JavaMail Problem

A

AC

I'm a beginner to programming in Java (I'm switching over from VB because
I'm in a company that is beginning the transition from MS environments and I
need to start porting software to a platform that can run on Linux and
Windows machines). I'm telling you this so you'll be kind :)

Anyways, I'm using the NetBeans 4.0 IDE and have a small application that
downloads some data from one of our internal web sites, massages the data
and sends it out via email. I've managed to get to the email point, and
downloaded the JAF and JavaMail APIs, sticking mail.jar and activation.jar
into the jre/lib/ext directory (I'm actually doing the the development on a
Windows box). I can run my application without a hitch in NetBeans, but
when I try to run the jar file straight from the command prompt I get the
following error:

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

I don't have any of the jar files set in the NetBeans project itself, so I'm
assuming I don't need to muck around with class paths because it is in the
jre/lib/ext. Is there something I'm missing?
 
A

AC

You are missing the manifest in the jar file. See the section "Packaging
Your Application in a JAR File" in
http://java.sun.com/j2se/1.4.2/runtime.html .

Well, I'm using NetBeans to build the jar file, and from what I can tell
this is the manifest file:

Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

I'm just going to a shell and running the NetBeans-built jar file manually.
LIke I said though, I'm a beginner, so I'm sure I'm missing something
terribly obvious (though from a google search it looks like JavaMail can be
a pain in the a**).
 
D

dar7yl

AC said:
...though from a google search it looks like JavaMail can be
a pain in the a*

JavaMail is intimidating at first, but once you set it up, you'll find it's
actually quite easy to use (for basic operations).

BTW, you can use your ISP's mail server, so you don't have to grow your own.

regards,
Dar7yl
 
A

AC

JavaMail is intimidating at first, but once you set it up, you'll find it's
actually quite easy to use (for basic operations).

BTW, you can use your ISP's mail server, so you don't have to grow your own.

Well, I've got it sending mail through our mail server just fine within the
NetBeans environment. I just can't get it to do it from "java -jar", even
though both the activation.jar and mail.jar files are in the jre/lib/ext
directory. Do I actually have to add this directory to the class path?
 
D

dar7yl

AC said:
Well, I've got it sending mail through our mail server just fine within
the
NetBeans environment. I just can't get it to do it from "java -jar", even
though both the activation.jar and mail.jar files are in the jre/lib/ext
directory. Do I actually have to add this directory to the class path?

You shouldn't have to, but then again, you never can tell what's happening
in your environment. What sort of errors are you getting? Show stack
traces.

That's why I dislike the beans environment. It isolates you too much from
the actual real-world situations you are likely to encounter, such as
configuration issues, communication problems, security, and downright user
hostility.

When you are running at the applications level (that is, starting a .jar
from the command line), you have to make sure your environment is as
self-contained as possible. Also you may have to adjust your security
settings. Make sure you have an appropriate .policy file (either local or
in $JAVA_BASE/lib/security/java.policy). Don't forget to put the start
class into the manifest.

Running as an applet means that you have to provide all those excess
libraries to the client's computer (as .jars in html applet archive
parameter or by direct install), as well as provide some sort of mail server
or relay because the client can only open sockets back to your internet
address, without having to be c.ertificated.

Finally, running as a server means that you have a whole lot of
configuration issues to deal with. Much steep learning curve. Many
packages to install. Many manuals to read. Good cure for insomnia.

regards,
Dar7yl
 
D

Dimitri Maziuk

AC sez:
Well, I'm using NetBeans to build the jar file, and from what I can tell
this is the manifest file:

Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

I'm just going to a shell and running the NetBeans-built jar file manually.
LIke I said though, I'm a beginner, so I'm sure I'm missing something
terribly obvious (though from a google search it looks like JavaMail can be
a pain in the a**).

java -verbose:class is your friend. It'll show you exactly what classes
it's loading and where from.

Dima
 
A

AC

AC sez:

java -verbose:class is your friend. It'll show you exactly what classes
it's loading and where from.

I think I found my problem. Apparently there is another copy of the JRE on
the machine I'm working on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top