I was asked to configure and use javamail on a RHEL 7 server.
I untar'ed a javamail directory they had here which contains the following files:
activation.jar
cacerts
config.properties
InstallCert.class
InstallCert$SavingTrustManager.class
mail.jar
SimpleSSLMail.class
Also, I have created a /etc/profile.d/java.sh where I have the following:
JAVA_HOME=/usr/java/jre1.6.0_45
export PATH=$JAVA_HOME/bin:/usr/bin:/bin:/usr/sbin:$PATH
export CLASSPATH=$CLASSPATH:/usr/share/javamail/activation.jar:/usr/share/mail.jar:.
cacerts is a keystore which holds gmail's cert to sendmail. When I try to send mail using the following:
java -Djavax.net.ssl.trustStore="cacerts" -Djavax.net.ssl.trustStorePassword="somepassword" SimpleSSLMail "SomeHeader" "Testing..." "some#mail.com"
It fails with message:
Exception in thread "main" java.lang.NoClassDefFoundError:
SimpleSSLMail Caused by: java.lang.ClassNotFoundException:
SimpleSSLMail
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: SimpleSSLMail. Program will exit
I have reviewed many posts saying the problem is java not finding mail and activation jars, but I can't handle correctly the CLASSPATH to work with those files. I also tried using -cp flag like this: java -cp mail.jar -cp activation.jar -Djavax.net.ssl.trustStore="cacerts" .....
It was useless, I get the same error.
What am I missing or how do I get it to work?
I have java jre only; do I need to compile it using javac?
My goal is to make it work in order to create an alias where the user can type only sendmail "Message" "mail.com" or similar
UPDATE
I was having a typo in classpath where instead of using /usr/share/javamail/mail.jar I was using /usr/share/mail.jar.
Now, when creating the alias it works fine in javamail directory but if I try to run it outside the directoy, java complains that it doesn't find config.properties. I believe it is searching for it as ./config_properties.
I don't have the source code, so, is there a way to override the config.properties location with the command line?
Related
I asked a question earlier here: NoClassDefFoundError with bluecove's javax.microedition
but got no responses.
I am trying to run some java code (Server.java) that requires bluetooth, so I installed the bluecove-2.1.0.jar file in C:\Program Files\Java.
I compile my code with javac -cp "C:\Program Files\Java\bluecove-2.1.0.jar";. Server.java and run it with java Server -cp "C:\Program Files\Java\bluecove-2.1.0.jar"
It compiles successfully, but when I run it, I get the error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javax/microedition/io/Connection
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.microedition.io.Connection
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Any ideas where i've gone wrong?
EDIT: Following Minus' answer, to fix the error that followed, I also needed to use a different .jar file which I downloaded from http://snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.63/
The problem is that the .dll is not loaded correctly.
The library should contain a .dll that will be saved on disk and loaded, maybe the program cannot save the .dll to disk or cannot read it.
Extract the .dll and follow bluecove installation instructions on Native Library location.
For example:
Create a directory c:\blue, and a directory blue\lib.
Put the files like this:
C:\blue\Sever.java
C:\blue\Sever.class
C:\blue\[bluecove_native_library].dll
C:\blue\lib\bluecove-2.1.0.jar
Open a cmd (Command Prompt) on c:\blue
Try to run the app like this:
java -cp .;lib\bluecove-2.1.0.jar -Dbluecove.native.resource=false Server
This way you will have both Server.class and bluecove-2.1.0.jar in classpath and the DLL in path (since on Windows the current dir is in path).
Add a current folder to a classpath (.;) and make sure that your code is in a package-name folder.
So if your server has a package name :
mypackage
make sure that your class code is in a /mypackage directory
than go to a parent folder to /mypackage and call:
java -cp ".;C:\Program Files\Java\bluecove-2.1.0.jar" mypackage.Server
I am trying to get Jalview [1] running on my windows 7 system. The standard installation works without error but when starting (the .exe file) it I get "Windows error 2 occured while loading the Java VM". As this error is quite general I tried then
C:\Program Files (x86)\Jalview>java -jar jalview.jar
which leads to:
Java version: 1.8.0_121
x86 Windows 7 6.1
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layo
ut
at jalview.bin.Jalview.doMain(Jalview.java:210)
at jalview.bin.Jalview.main(Jalview.java:180)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
any ideas what is going wrong?
Thx
Morpheus
[1] http://www.jalview.org/Download
This error "java.lang.NoClassDefFoundError" occurs when there is a class missing in your respective packages.
I suggest please check if the class "Layout" is present at path : org/apache/log4j
If not then its correct that you have some missing files/libraries of log4j in the classpath.
Please vote and mark the solution if useful.
Thanks!
First check that in C:\Program Files (x86)\Jalview\lib the library min-jabaws-client-*.jar exists.
To run it from command line
cd C:\Program Files (x86)\Jalview
java -cp jalview.jar;lib/* jalview.bin.Jalview
I've written a program to read in data from a text file and do some simple calculations, then print out those calculations. That part works great.
Afterward, I added in some code to do a t-test, using the TTest class (org.apache.commons.math3.stat.inference.TTest). So, I downloaded commons-math3-3.6.jar from the Apache Commons download page and put the JAR file in the same folder as the rest of my Java code for this program.
I use the following command in Windows to compile, which works fine:
javac -cp ./commons-math3-3.6.jar ./FootballTeam.java ./Main.java
But I can't figure out how to correctly run the program. I've tried this:
java Main
which executes everything up to the t-test perfectly, and then gives the expected error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/stat/inference/TTest
at Main.main(Main.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.stat.inference.TTest
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I've also tried this:
java -cp commons-math3-3.6.jar Main
which gives me this:
Error: Could not find or load main class Main
I cannot for the life of me figure out how to properly set the classpath here. Can someone provide me some assistance? Thank you!
The Main class cannot be found because the current directory (.) is not on your classpath.
To add it, on Windows:
java -cp ".;commons-math3-3.6.jar" Main
On *n?x:
java -cp ".:commons-math3-3.6.jar" Main
I'm a newbie to Java (just two days) and am trying to get an HTTP server running using Spark. I created a new Maven project in IntelliJ and have a Hello World response coming back from Spark when running it in IntelliJ. As a learning exercise, I would like to get the app running from the command line using Java.exe. When I run java Main, I get the following error:
Exception in thread "main" java.lang.BootstrapMethodError:
java.lang.NoClassDef oundError: spark/Request
at Main.main(Main.java:5) Caused by: java.lang.NoClassDefFoundError: spark/Request
... 1 more Caused by: java.lang.ClassNotFoundException: spark.Request
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
Looks like it can't find the Spark .jar files. There's a command line option -cp to specify paths to dependencies. After looking up where Maven keeps these files, I tried running:
java -cp .;C:\Users\jbuschmann.m2\repository Main
Still same error. How do I specify the path to the Maven dependencies?
Instead of giving the repository in the -classpath, try adding the location of your spark.jar.
java -cp \path\to\spark.jar Main
I've run in to a strange error with the javamail 1.4.2 api and jdk/jre 1.6.0u16. I've placed the unzipped javamail-1.4.2 folder (along with the MySQL Connector-J 5.1.7 also needed) in both the jdk and jre folders as in the %classpath% below.
.;"C:\Program
Files\Java\jdk1.6.0-16\jre\lib\ext\mysql-connector-java-5.1.7-bin";"C:\Program Files\Java\jdk1.6.0-16\jre\lib\ext\javamail-1.4.2\mail.jar";"C:\Program
Files\Java\jdk1.6.0_16\bin";"C:\Program
Files\GameLabInventory\GameLabInventory-7.0.jar";"C:\Program
Files\Java\jre6\lib\ext\mysql-connector-java-5.1.7-bin";"C:\Program Files\Java\jre6\lib\ext\javamail-1.4.2\mail.jar";
But when I run my compiled jar with the command
C:\Program Files\Java\jre6\bin>java -cp %classpath% -jar "C:\Program Files\GameLabInventory\GameLabInventory_7.0.jar"
I get the following error message:
Exception in thread "main"
java.lang.NoClassDefFoundError:
javax/mail/MessagingException
at gamelab.inventory.GameLabInventory.main(GameLabInventory.java:62)
Caused by:
java.lang.ClassNotFoundException:
javax.mail.MessagingException
at java.net.URLClassLoader$1.run(Unknown
Source)
at java.security.AccessController.doPrivileged(Native
Method)
at java.net.URLClassLoader.findClass(Unknown
Source)
at java.lang.ClassLoader.loadClass(Unknown
Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown
Source)
at java.lang.ClassLoader.loadClass(Unknown
Source)
at java.lang.ClassLoader.loadClassInternal(Unknown
Source)
... 1 more
I can't find anything wrong with my setup here, hopefully you guys can help me out. Thanks!
Here is the manifest file:
Manifest-Version: 1.0
Main-Class: gamelab.inventory.GameLabInventory
Here is the jar -tvf (link)
According to the documentation for the java tool:
When you use [the -jar] option, the
JAR file is the source of all user
classes, and other user class path
settings are ignored.
You can specify a Class-Path attribute in yourJAR file that "specifies the relative URLs of the extensions or libraries that [your] application or extension needs."
When using -jar, java overrides the classpath setting (-cp). In this configuration, however, classpath jars can be specified in the manifest file of your jar.
I've experienced a similar issue (not identical to yours, since mine is spring-related) and found this link was helpful:
http://forum.springsource.org/showthread.php?t=65840&page=3
It seems that implementation changes in the JDK might be causing this behaviour. Quoting from the link:
"I managed to reproduce the problem on my Mac development box using Java 6 (1.6.0_07). I then tried it on my Mac using Java 5, and could not reproduce the problem. Crucially, in the Java 5 case, the JVM would be using the javax.activation API and implementation from the 1.1.1 javax activation bundle, whereas on Java 6, it would be using them from the JRE (anything that's part of the JRE takes precedence over what's in dm Server's lib directory). I then tried the app on an Ubuntu box, this time using Java 6 1.6.0_10. I could not reproduce the problem."
and/but:-
"I've just had this same problem "No object DCH for MIME type" but on Ubuntu java version "1.6.0_13". So I don't know how you guys solved it by upgrading to 1.6.0_11.
What I did is copy the mailcab.default to my own bundle and it worked. Seems to be a classloading problem which I don't fully understand yet."