how to import jar files in linux machine
I am trying to run a Java program on Linux machine, that includes:
impor开发者_C百科t javax.mail.*;
I have included mail.jar
into myjdk/lib
. Even on compiling it shows errors like
javax.mail does not exist
What to do?
On bash run this command
export CLASSPATH=$CLASSPATH:/path/to/my.jar
and then compile
Check your CLASSPATH. Make sure it points to all JAR files in the directory. This should be specified by either a direct path to the your JAR, or a wildcard.
Take a look at this page on setting the class path: http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
Based on your comments, I'm going to assume that you have a script to construct the classpath from the files in the "lib" directory.
In that case, the most likely problem is that Windows uses a semi-colon (";") as a classpath separator, while Linux uses a colon (":").
Offhand, I don't know of a solution that works in both environments. The usual approach is to create a "runme.sh" for Linux, and a "runme.bat" for Windows.
Copy all your jar files and .java files in same folder. To compile,
javac -cp .:mail.jar SendEmail.java
To execute,
java -cp .:mail.jar SendEmail
精彩评论