Launch4j - Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException - java

I used launch4j (http://launch4j.sourceforge.net/) software to create an executable of my application created in java netbeans.
I did everything as I saw in a tutorial, just that when I run the exectutavel it creates in my application, it gives this error:
The message shown below is:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(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)
... 6 more
Does anyone can help me solve this problem please.
I've been searching but I can not solve. I apologize for this question but am new to java.
Thank you all.
Greetings

In your launch4j configuration file add the jars like this
<classPath mainClass="your.main.class">
<cp>path/to/javamail.jar</cp>
<cp>path/to/folder/*.jar</cp> // you can also add all the jars in a folder like this
</classPath>
It will automatically bundle them.
Hope this helps
EDIT
Just went through netbeans integration with launch4j and it seems there is no way to write your on config xml file instead it prompts you in launch4J GUI for dependencies. I searched and found this Stackoverflow Post. This is what you want. Good Luck.

Add Java mail jar to classpath.
Download it from here
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eeplat-419426.html#javamail-1.4.7-oth-JPR

Related

Dynamic reports classnotfoundexception

I have a java program that uses dynamic reports fine in netbeans, and even works in exe and jar when I first run it. However, if I share the jar/exe (I've even sent it and re-downloaded it on my own computer), I get an error java.lang.classnotfoundexception: net.sf.jasperreports.engine.jrdatasource. However, I have double checked my jars and I do have this class. What could be the source of this problem then?
Thanks
Edit: full error:
Exception in thread "main" java.lang.NoClassDefFoundError:
net/sf/jasperreports/engine/JRDataSource
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:
net.sf.jasperreports.engine.JRDataSource
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
if you get Caused by: java.lang.ClassNotFoundException: inside a jar file then, you need to provide the classpath arguments;
example:
java -cp my.jar -jar ExternalJarFileName.jar
you can also provide all jars use below command, only need to create a directory and put all external jars in to it and use path of directory in to below command:
java -cp my.jar;C:\externalJar\* mainpackage.MainClass

Missing slf4j in tess4j

I want to test tess4j to do OCR. I used the following tutorial for a first example: http://tess4j.sourceforge.net/codesample.html
I included the required libraries, but I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at net.sourceforge.tess4j.Tesseract.<clinit>(Unknown Source)
at tess4jexample.TesseractExample.main(TesseractExample.java:10)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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
Does anyone knows a solution for this?
Tess4J has several dependencies. You'll need to include them in the classpath.
There has where still some dependencies missing, which have not been mentioned on the mavenrepository:
logback-core-1.1.6.jar
slf4j-api-1.7.21.jar
I think now it is working :-) Thank you nguyenq for this hint, to check the dependencies.

Errors in Eclipse after Java update

I recently updated java, I went to eclipse opened up my code and saw that there were a lot of errors that weren't there before I saved last time I dont know what it's asking for and I know its not a problem with my code. Everytime i run it says the following:
Exception in thread "main" java.lang.NoClassDefFoundError: [LString;
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: String
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
as well as saying an JNI error has occured as well as Java Exception.
I haven't tried adding classes as I don't know what will happen if I do.
Did you remove the old version when you upgraded Java? Go to Preferences->Java->Installed JREs and check that the new version is selected.
If the new version isn't listed, use the Search button.

Upload an Object Using the AWS SDK for Java

I am using the following code from AWS documentation:
http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpJava.html
And i have used the following jars :
And i am getting the following error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at com.amazonaws.AmazonWebServiceClient.(AmazonWebServiceClient.java:58)
at UploadObject.main(UploadObject.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(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)
... 2 more
Any help would be appreciated for the same. I have tried adding the common logging jars but no luck.
Hi there are quite a few third-party library's required for AWS to work. The ones below are the extras packaged with the SDK download. I seem to remember there being one missing though so let me know if this doesn't work and i'll check my dependencys.
All of these can be found in '\aws-java-sdk-1.9.1\third-party'
aspectj-1.6
commons-codec-1.6
commons-logging-1.1.3
freemarker-2.3.1.8
httpcomponents-client-4.3
jackson-annotations-2.3.0
jackson-core-2.3.2
jackson-databind-2.3.2
javax-mail-1.4.6
joda-time-2.2
spring-3.0

Exporting Runnable JAR in eclipse with User Libraries included

I am trying to create a runnable JAR file from a project of which I'm importing org.apache.commons.io. I tried exporting and checked the box to include all dependant libraries but I keep getting this output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io
/filefilter/TrueFileFilter
at tvSort.Main.main(Main.java:36)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.filefilter.Tr
ueFileFilter
at java.net.URLClassLoader$1.run(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)
... 1 more
Any help would be appreciated, thank you.
Did you try setting up classpath in the Manifest?
e.g. Class-Path: commons-io-xyzversion.jar
If you can please try to add this manifest entry manually by saving this in a text file and adding it via the jar tool.
Hopefully eclipse has already done this,so did you run the jar with dependencies(jars) in the same folder/path?

Categories

Resources