J2EE standalone aplication with JRE

Hi there,

Recently I have been asked by one of my clients to add more feature to an existing project [using auto response email] I did that with the help of J2EE [testing it with eclipse it runs smothly]. However, while trying to run it from the command line - it appears that i am not using the correct JRE.

i get this message:

C:\eclipse\workspace\USGroups JRE\Application>java -cp USGroups.jar USmain

java.lang.NoClassDefFoundError: javax/mail/Message

at USmain.runUSGroups(USmain.java:39)

at SecurityLog.actionPerformed(SecurityLog.java:205)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow

n Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener$ReleasedAction.actionPerfo

rmed(Unknown Source)

at javax.swing.SwingUtilities.notifyAction(Unknown Source)

at javax.swing.JComponent.processKeyBinding(Unknown Source)

at javax.swing.JComponent.processKeyBindings(Unknown Source)

at javax.swing.JComponent.processKeyEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)

at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)

at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Sour

ce)

at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Sour

ce)

at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Anyone?

[2628 byte] By [P_Primrose] at [2007-9-30 16:56:29]
# 1
You're missing the JavaMail jar files. http://java.sun.com/products/javamail/-Alexis
am74686 at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 2
I'm not sure, which one should i download and where do i place it.thanks
P_Primrose at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 3

From http://java.sun.com/products/javamail/downloads/index.html

download JavaMail 1.3.1 Release and also JAF 1.0.2 from

http://java.sun.com/products/javabeans/glasgow/jaf.html.

You should have:

- activation.jar

- mail.jar

- mailapi.jar

- pop3.jar

- smtp.jar

- imap.jar

hth,

-Alexis

am74686 at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 4
Thanks Alexiswhere should I place those files? in the folder of my application or to the folder where I extracted my j2re-1_4_0-win.thanksPpr
P_Primrose at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 5
You might also want to take a look at what the classpath is set to for your project in eclipse and try using thesame classpath when running it standalone.: jay
JayDS at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 6
I had to add extrenal Jars to the project and i didn't touch the CLASSPATH. from eclipse it works great. I tried to take those jars and place them at the application folder [even setting the CLASSPATH to application folder] ...doesn't work...same err msg :-(
P_Primrose at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 7

You need to provide more information like your CLASSPATH content.

Maybe you can try running with the -verbose:class option to see where the VM is failing to load a class.

Anyhow, this is a case for having an ANT-based project for your IDE !

Look at NetBeans 4.0 beta (http://www.netbeans.org/community/releases/40/beta.html)

No need to start the IDE to compile, run, test, ... No IDE dependencies.

-Alexis

am74686 at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 8
:-(I got all the files, try to set it on the CLASSPATH but didn't work out.maybe I suppose to write something in the command lind indication that I'm going to use those JARS.my line is simply:java -cp USGroups.jar USmainanything to add here?
P_Primrose at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 9
You can explicitly add those JAR files to the command line indeed.You can also make sure the CLASSPATH environment variable mentions them.-Alexis
am74686 at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 10
thanks - works perfectly. I added them to the lib\extby the way, if I wanted to add them to my command line, how would that look like? how do you use java -cp Class1.jar Class2.jar?
P_Primrose at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 11

It depends on your OS:

jar1.jar;jar2.jar;jar3.jar (Win)

or

jar1.jar:jar2.jar:jar3.jar (Unix)

Be carefull when placing things in your VM lib/ext forlder:

- you need to do this everytime you change the JRE

- anything there has priority over CLASSPATH, so odd

things can happen if you forget you did that.

-Alexis

am74686 at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 12

Oh, in this case maybe I'll simply add all the jar files to my folder and run it from the command line.

I'm trying to do this:

java -cp activation.jar, mail.jar imap.jar, mailapi.jar, pop3.jar, smtp.jar, USGroups.jar USmain

but I get this err msg:

Exception in thread "main" java.lang.NoClassDefFoundError: mail/jar

what am i doing wrong?

[I placed all the jars in the folder]

P_Primrose at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 13
don'y use commas (,).Use ";" between jar file names-Alexis
am74686 at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 14
Hi AlexisI tried both ;and:same err msg:java -cp activation.jar; mail.jar; imap.jar; mailapi.jar; pop3.jar; smtp.jar; USGroups.jar USmainException in thread "main" java.lang.NoClassDefFoundError: mail/jar:-(any idea ?
P_Primrose at 2007-7-6 13:10:07 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 15
Don't use spaces.(we're getting there!)-Alexis
am74686a at 2007-7-19 22:20:44 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 16
PERFECT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!thanks a lot:-)it works great both ways.Thanks Alexis
P_Primrosea at 2007-7-19 22:20:44 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 17
Glad I could help ;-)-Alexis
am74686a at 2007-7-19 22:20:44 > top of Java-index,Enterprise & Remote Computing,AVK Portability...
# 18

Hi,

I saw your discussion,pretty useful...hmmmm.. but in my case its failed.

I could execute my java class individually like this.

D:\JDK13~1.1_0\x>java -cp mail.jar;activation.jar;classes12.zip;. MailTest

I made a jar for my MailTest and tried to execute it, the error is...

( the jar I made from PKZIP Utility. I doubted the jar first, I tried for my other programs and I have been using this way making jars since a long time. all others are working well)

D:\JDK13~1.1_0\x>java -cp mail.jar;activation.jar;classes12.zip;. -jar ForU.jar

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Message

pls. help me to work on this....

Sanathleea at 2007-7-19 22:20:44 > top of Java-index,Enterprise & Remote Computing,AVK Portability...