JavaMail ClassNotFound - java

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."

Related

javamail class not found while trying to run on RHEL

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?

NoClassDefFoundError hibernate criterion exporting jar

I'm trying to export a java stand-alone class that uses hibernate. It's a really simple read/insert procedure. I'm stuck with this error
C:\Users\Admin\Desktop>java -jar ImportDatiMeteo2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/criteri
on/Criterion
at openplan.openergy.standalone.ImportDati.main(ImportDati.java:24)
Caused by: java.lang.ClassNotFoundException: org.hibernate.criterion.Criterion
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)
... 1 more
I was thinking it could be a manifest file problem so i checked. It seem ok to me.
Manifest-Version: 1.0
Class-Path: lib/antlr-2.7.6rc1.jar lib/asm-attrs.jar lib/asm.jar
lib/c3p0-0.8.5.2.jar lib/cglib-2.1.3.jar lib/cleanimports.jar
lib/commons-collections-2.1.1.jar lib/commons-logging-1.0.4.jar lib/concurrent-1.3.2.jar
lib/connector.jar lib/dom4j-1.6.1.jar lib/ehcache-1.1.jar lib/hibernate3.jar
lib/jaas.jar lib/jacc-1_0-fr.jar lib/jaxen-1.1-beta-7.jar
lib/jdbc2_0-stdext.jar lib/jgroups-2.2.7.jar lib/jta.jar lib/log4j-1.2.11.jar
lib/log4j-1.2.9.jar lib/oscache-2.1.jar lib/proxool-0.8.3.jar
lib/swarmcache-1.0rc2.jar lib/xerces-2.6.2.jar lib/xml-apis.jar
Created-By: 1.6.0_21 (Sun Microsystems Inc.)
Main-Class: openplan.openergy.standalone.ImportDati
In my Eclipse all the project work properly, does anyone know where the problem is?
You need to add those libraries in classpath as you are running it from command line :
C:\> java -classpath <referenced-jars> -jar ImportDatiMeteo2.jar
in myEclipse all the project work properly, does anyone know where the problem is ?
--> Because Eclipse will take care of your classpath and adding libraries in your classpath.
Please check Library handling option in your Eclipse export dialog. On my side it works fine with hibernate with Extract required libraries into generated JAR selected.

7Zip-JBinding UnsatisfiedLinkError

I've looked through a number of the UnsatisfiedLinkError threads on here and nothing seems to quite fit my problem.
I am trying to get this api working: 7ZipBind
However I am having an issue, and cant get the thing to work. I am running some of its example code from the commandline like so:
C:>java -classpath
"/sevenzipTest.jar;/sevenzipjbinding-AllWindows.jar;\sevenzipjbinding.jar"
com.poc.sevenzip.SevenZipSimple c:\archive\test.zip
However when I try to run it I get the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\Users\XXXX\AppData\Local\Temp\SevenZipJBinding-9640553\lib7-Zip-JBinding.dll: Can't
find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJARIntern(SevenZip.java:428)
at net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJAR(SevenZip.java:235)
at net.sf.sevenzipjbinding.SevenZip.ensureLibraryIsInitialized(SevenZip.java:578)
at net.sf.sevenzipjbinding.SevenZip.openInArchive(SevenZip.java:567)
at com.poc.sevenzip.SevenZipSimple.runZip(SevenZipSimple.java:25)
at com.poc.sevenzip.SevenZipSimple.main(SevenZipSimple.java:64
What I am confused about, is why it says it cant locate the libraries (dll files), when the libraries are stored within the <file_path>/sevenzipjbinding-AllWindows.jar file... I am obviously not doing something correct here, and was hoping some1 can give me some pointers.
Cheers
The bug fix was released. Please, use version 1.06rc or above.
Download URL:
All versions
4.65-1.06rc-extr-only
The following instructions are for Windows x86 and 7 Zip JBinding version 4.65-1.05 RC. Download the following DLLs.
libstdc++-6.dll
libgcc_s_dw2-1.dll
gpsvc.dll
sysntfy.dll
Add the DLLs into the Windows-x86 directory in sevenzipjbinding-AllPlatforms.jar. Then append the following lines to sevenzipjbinding-lib.properties in the Windows-x86 directory in the jar.
sevenzipjbinding.libname.3=gpsvc.dll
sevenzipjbinding.libname.4=libgcc_s_dw2-1.dll
sevenzipjbinding.libname.5=libstdc++-6.dll
sevenzipjbinding.libname.6=sysntfy.dll
Instead of modifying the jar file, one could put the DLLs in the PATH (not classpath).
In order to figure this out, I extracted lib7-Zip-JBinding.dll from sevenzipjbinding-AllPlatforms.jar. I then opened the file in Dependency Walker.

Local Tomcat Environment Not Starting

I'm attempting to get a local Tomcat environment running and am consistently encountering the following error:
Can't load log handler "2localhost.org.apache.juli.FileHandler"
java.lang.ClassNotFoundException: 2localhost.org.apache.juli.FileHandler
java.lang.ClassNotFoundException: 2localhost.org.apache.juli.FileHandler
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)
I've confirmed the existence of 'tomcat-juli.jar' in %TOMCAT_HOME%/bin.
Pulling hair out on this one. It's almost gone.. Any help you can offer is greatly appreciated. Thanks! :)
Did you modify your catalina.policy config?
grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
permission java.security.AllPermission;
permission java.lang.RuntimePermission "setContextClassLoader";
};
What good does a JAR do in /bin? Put it in server/lib if you're using Tomcat 5 or lib if you're using Tomcat 6. Those directories are in the CLASSPATH; bin is not.
UPDATE: You're using Tomcat 6, which uses a system class loader that's different from previous versions. This suggests that the juli JAR belongs in /bin, so my previous suggestion might correct the problem but it's not the recommended Tomcat 6 idiom.
Do you have CATALINA_HOME set?

Tinyos Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file

When I use make command, like make mica2, in TinyOS. The following problem will occured:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
make: *** [exe0] Error 1
I reinstalled JAVA and add env variables, but it didn't work. I use TinyOS 2.1 and JAVA 1.5 u18. Can any one help me?
Problem solved by install JDK 1.6. Although when I run tos-check-env command, it shows me a warning that tell me its not JDK 1.4 or 1.5. Maybe it is a bug in TinyOS.
an UnsupportedClassVersionError means you are trying to run byte code on an older version of the JVM than it was compiled in. You can use a class file viewer to check which version of the JDK the source code was compiled it and make sure it is compatible with JAVA 1.5 u18.
The error you're getting means that the version of Java that's running is trying to load a class that was compiled with an incompatible version of Java.
With the information you've provided it's not possible to diagnose the problem any more specifically than this - look at any Java libraries you're using and what their required Java versions are. If you can't find anything wrong here, you might just need to clean out some cached *.class files that were built with a version of Java before the reinstall.
Finally, if you have multiple JVMs installed be sure that make is using the one you expect. It's definitely possible for you to have installation Java 1.5u18 but for the application to still be finding and using a 1.4 JVM from somewhere.
I got the same error today, and I simply solved it by installing java version 1.6 and jre6, and by making Java 1.6 version as the default version.
I also had java 1.5 installed earlier, as tos-check-env wanted me to have either java 1.4 or java 1.5 versions installed.
I also included both the java 1.5 and 1.6 versions to my classpath and ran make micaz again in the /opt/tinyos-2.1.0/apps/Blink directory and it worked.
Normally there would be a message such as
(Unsupported major.minor version 49.0)
in the first line of the exception message. However, you got
Bad version number in .class file
So maybe your class file is corrupted?
Use sudo update-alternatives --config java and set the version you may want to use.

Categories