0

I have java project I convert it to .jar file using netbeans Clean & Build, I used cmd to run the .jar file it successfully run without errors, then I want to convert it to .exe file using launch4j but the problem is I have this error:

Executing: C:\Users\LaLa\Desktop\el.exe
Exception in thread "main" java.lang.NoClassDefFoundError: com/toedter/calendar/JDateChooser
    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: com.toedter.calendar.JDateChooser
    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

What could be the possible error I made? or I shouldn't made to avoid it?

(I'm totally new to java programming, I'd ask you please to write solution in details)

LaLa
  • 101
  • 11
  • why would you want to convert it to an exe? it looks like you don't have all your dependencies in your exe. when do you get this error, when building or when running the exe? – Stultuske Aug 03 '18 at 12:50
  • 3
    Looks like you've almost certainly not included your libraries in your jar file (assuming `com.toedter.calendar.JDateChooser` is a library that you're using.) Have a look at building a fat jar if you want all the libraries included, and use launch4j to wrap that. – Michael Berry Aug 03 '18 at 12:51
  • @Stultuske I got the error when running the exe, in launch4j app – LaLa Aug 03 '18 at 12:58
  • @MichaelBerry i'm using netbeans so when I convert it to jar file it'll automatically create lib folder that has all jar files I used in my project – LaLa Aug 03 '18 at 13:00
  • @LaLa does it create that folder inside the .jar file? that's the question – Stultuske Aug 03 '18 at 13:01
  • @LaLa consider using [maven-assembly-plugin](http://maven.apache.org/plugins/maven-assembly-plugin/), it will build a single jar-with-dependencies which you can convert to `.exe` – Vladimir Vagaytsev Aug 03 '18 at 13:01
  • @Stultuske no it doesn't – LaLa Aug 03 '18 at 13:08
  • @Stultuske Thanks! I added my .exe file where my .jar file & libraries located. it worked now! – LaLa Aug 03 '18 at 13:16
  • you shouldn't have to. this way, you (or anyone you give your code to) will never be able to run the exe, unless they have the exact same setup – Stultuske Aug 03 '18 at 13:19
  • What do you mean (they have the exact same setup)? @Stultuske – LaLa Aug 04 '18 at 08:43
  • Unless you know upforehand that your application will never (ever) be used on any other computer, you can't know that for sure. – Stultuske Aug 07 '18 at 05:57
  • @Stultuske I sent my app folder to a friend & make a shortcut to add the app in desktop it worked very well, for meantime this's what I was looking for. – LaLa Aug 07 '18 at 14:56
  • @Lala if you work like that, it is not possible to know whether both machines have the same setup. it looks to me, what you're looking for is an installer tool. This has nothing really to do with Java – Stultuske Aug 08 '18 at 06:10

1 Answers1

0

I saved my .exe file in dist folder that contains my .jar file & lib folder. It worked as I wanted. Thanks to All!

LaLa
  • 101
  • 11