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

Deadly 提交于 2021-01-28 19:59:19

问题


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:

enter image description here

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



来源:https://stackoverflow.com/questions/23516137/launch4j-exception-in-thread-main-java-lang-noclassdeffounderror-javax-mail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!