Results 1 to 8 of 8
Thread: Need advice wrt Java email & jar
- 01-14-2012, 11:58 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 14
- Rep Power
- 0
Need advice wrt Java email & jar
I'll break the golden rule by starting with an apology for posting in the wrong section, but I can't see which group is correct for java mail problems. For anyone who understands Java mail, I think my question will be simple. My program works perfectly when initiated from a DOS box(or Command line) with the instruction "Java myProg" and it issues an email when certain events occur. Everything works when compiled into a .jar with the exception of emails are never sent. It doesn't look as if my firewall is stopping the email going through (might be wrong), so is there anything extra I should do to allow java-email to be sent from a .jar?
- 01-15-2012, 01:08 PM #2
Re: Need advice wrt Java email & jar
There should be no difference between executing a program in a jar and from class files in folder(s).
A difference could be that some files are missing from the jar file or are not on the classpath for the Java program.
Make sure there are no errors. Open a command prompt, change to the folder with the jar file and use the command:
java -jar <THEJARFILE>.jar to execute.
- 01-15-2012, 05:35 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 14
- Rep Power
- 0
Re: Need advice wrt Java email & jar
I tried this and obtained the same results except the jar file issued an error message. I don't understand why it should run OK as a command line but not as a jar.
All the java and class files (that I have written) are in the same folder and the program is run from that folder. The CLASSPATH includes C:\Progra~1\Java\javamail-1.4.4\mail.jar.
The module Postit.java calls "Mailer" as a low priority thread to send a simple email.
The error is:
Exception in thread "Thread-6" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at Postit.run(Postit.java:18)
at java.lang.Thread.run(unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(Unkown Source)
at java.security.AccessController.doPrivilaged(Native Method)
at java.net.URLClassLoader.findClass(UnknownSource)
etc.
- 01-15-2012, 05:40 PM #4
Re: Need advice wrt Java email & jar
Where is the class mentioned in the error message? It's probably in a jar file that you need on the classpath.java.lang.ClassNotFoundException: javax.mail.MessagingException
How did you execute the program when it worked? What was the classpath set to?
- 01-15-2012, 06:46 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 14
- Rep Power
- 0
Re: Need advice wrt Java email & jar
I thought the exception would be in the C:\Progra~1\Java\javamail-1.4.4\mail.jar. I import javax.mail.* in the program and it doesn't object during compile. I've tried adding a few things to the classpath but no change in the result. I have to go out now, so no testing until later.
CLASSPATH system=
.;c:\jdk;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;c:\Progra~1\Jav a\javamail-1.4.4\mail.jar;c:\jdk\cctv
CLASSPATH user=
.;C:\PROGRA~1\JMF21~1.1E\lib\sound.jar;C:\PROGRA~1 \JMF21~1.1E\lib\jmf.jar;C:\PROGRA~1\JMF21~1.1E\lib ;c:\jdk\cctv;C\PROGRA~1\Java\javamail-1.4.4\mail.jar;c:\PROGRA~1\javamail-1.4.4\lib\mailapi.jar
(I just added the mailapi.jar but it has no effect)
Presumably, the command line version never needs this Exception message as it sends the emails without problem. Everything should be identical as I call them both from the dos box as follows:
C:\jdk\cctv>java m
and
C:\jdk\cctv>java -jar m.java
FYI the batchfile to create the .jar contains:
cd \jdk\cctv
jar cvfm m.jar manifest.txt *.class
and the manifest contains:
Main-Class: m
No doubt the missing error message is a fault I need to find, but if .jar worked like the command line it would not usually be needed.
- 01-15-2012, 06:54 PM #6
Re: Need advice wrt Java email & jar
The java command with the -jar option ignores the classpath value.
There is an entry you can put in the manifest file: Class-path:
that could refer to other jar files that are needed
Or you can create a shortcut or batch file that uses the java -cp comand line with the jar files and the class name on the command line.
- 01-17-2012, 09:01 PM #7
Member
- Join Date
- Jun 2011
- Posts
- 14
- Rep Power
- 0
Re: Need advice wrt Java email & jar
I didn't know that the -jar ignores the classpath value, but just including it in the manifest didn't help. However, your suggestion has led to me "one-jar.sourceforge.net", which has shown that there is a lot I didn't know about JARs and Classpaths (and still don't). I need to study it for longer, but I think your are right about the way JAR handles Classpath being the cause of this problem.
- 01-18-2012, 11:51 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Advice on which java books to buy
By patriotsfan in forum New To JavaReplies: 5Last Post: 06-11-2011, 09:48 PM -
Just some advice on my first program in java.
By allen1952 in forum New To JavaReplies: 4Last Post: 12-22-2010, 02:32 PM -
send email using apache commons email
By jnamendi in forum JavaServer Faces (JSF)Replies: 0Last Post: 10-14-2008, 05:55 PM -
Java Email Server 1.6
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-21-2007, 08:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks