Question:
Java Programming HELP?? Help make this to a jar file? 3rd post..?
anonymous
2011-10-03 18:50:27 UTC
Okay, so I have a program where you take a quiz, it saves the results as a txt document, then it emails the text document off. For some reason i cant produce a jar file... Please help? i really want to be able to do this properly.

some of the code got cut off and it put "..." at the end by default, but i'm sure if you're good at this you will be able to fix it and help me. I'm a beginner.

this is the 3rd post and no answers so far on the other post...

Code

// Quiz And Sends Email With A Results Attachment

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

import java.util.Properties;


public class QuizEmail {

private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final int SMTP_HOST_PORT = 465;
private static final String SMTP_AUTH_USER = "myEmail@gmail.com";
private static final String SMTP_AUTH_PWD = "myPassword";
private static final String fileAttachment = "C:/Users/myUsername/Desktop/results.txt…
static Scanner console = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException, Exception {
QuizEmail quiz = new QuizEmail();
quiz.test();
}
public void test() throws FileNotFoundException, Exception {
String x;
PrintWriter outFile = new PrintWriter("C:/Users/myUsername/Desktop…
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String z = "Please answer the following questions to complete the survey.";
JOptionPane.showMessageDialog(null, z, "Quiz", JOptionPane.PLAIN_MESSAGE);
JFrame frame = new JFrame();
Object result0 = JOptionPane.showInputDialog(frame, "Question");



outFile.print("Question");
outFile.print(result0);


outFile.close();


Properties props = new Properties();

props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", SMTP_HOST_NAME);
props.put("mail.smtps.auth", "true");


Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);
message.setSubject("Testing SMTP-SSL");
MimeBodyPart messageBodyPart =
new MimeBodyPart();

//fill message
messageBodyPart.setText("Hi");

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);

// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(
new DataHandler(source));
messageBodyPart.setFileName(fileAttachme…
multipart.addBodyPart(messageBodyPart);

// Put parts in message
message.setContent(multipart);


message.addRecipient(Message.RecipientTy…
new InternetAddress("anotherEmail@hotmail.co…

transport.connect
(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);

transport.sendMessage(message, message.getRecipients(Message.RecipientT…
transport.close();
}
}
Three answers:
husoski
2011-10-03 19:33:25 UTC
There are too many truncated lines for me to fix. FYI, these happen on Java when a string of over 40 nonblanks is encountered. Prevent most of these by adding spaces to break up long "tokens". Some askers use pastebin.com or similar sites to not only get all characters, but preserve indentation.



The first thing you should do, if you haven't already, is to review the information about JARs and manifests in the Java Tutorial. The specific page that might help you is:



http://download.oracle.com/javase/tutorial/deployment/jar/appman.html



If you have JDK 1.6 or later (1.7 is the newest) then note the bit at the bottom of the page. You can use "jar -cfe " to create an executable jar without manually creating a manifest file. If there's just one class file:



jar -cfe RunQuiz.jar QuizEmail QuizEmail.class



Then run with "java -jar RunQuiz.jar". If you have your application filetype settings done properly, you can just type "RunQuiz.jar" at the command prompt.



You are at the command prompt, right? Jar is a command-line utility.
Unca Alby
2011-10-03 19:21:14 UTC
Are you able to compile it into a class file? Once you've done that, enter the command:



jar cvf {nameOfJarFile}.jar {nameOfClassFile}.class



If you are unable to compile it into a class file, then you need to fix the Java code until such time as the compiler likes it well enough to give you a class file. Thereafter, creating a jar file is simple. One line command.



Showing us the Java source code isn't going to help anybody tell you how to create a jar file. Compile it into a class file. The program that creates the jar file doesn't care what you put into the jar file. Indeed, I've known people to put both the class file and the original Java source into the jar file.



You can put anything you like into a jar file since, at its root, it's just a Zip file with a particular directory structure that allows it to optionally keep a manifest file.



I expect the reason nobody answered your question before was because it didn't make sense. It was like asking, "Why doesn't the factory GPS system work in my Pinto?" Well, they stopped making Pintos long before GPS was invented. So the question doesn't make sense. Maybe the asker intended to ask, "Why doesn't the Camry GPS system work when I install it in my Pinto?" That's kind of a peculiar thing to do, but at least the question makes more sense.
?
2016-11-11 12:00:27 UTC
you're arranged to do using IDE's alongside with eclipse, JDeveloper, Netbeans, etc in spite of if, if JDK is put in right here 2 steps will enable you to run a Java standalone application a million. goto command on the spot using cmd command on the RUN in initiate 2. javac abc.java 3. To run java abc


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...