Launch4j - Exception in thread “main” java.lang.No

2019-07-30 03:26发布

问题:

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

回答1:

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.



回答2:

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