1

I created my SWT project in Eclipse and the software helps me in dealing with all the library stuff. As far I a see, the project has a JRE(1.8) library and a reference library which contains all the libraries needed for my code.

My code works well in Eclipse, but when I export the project into a jar file and run it by "java -jar myCode" the error appeared -

"Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite......"

My understanding is that when I tried to run the program without Eclipse, I did not specify the reference libraries so it will not tell classes in the reference libraries. I'm using Mac and not sure how to specify the reference for my program.

Can anyone give a step by step example to show the processes? Thanks in advance.

Rohit Poudel
  • 1,793
  • 2
  • 20
  • 24
rainbow66
  • 11
  • 2
  • I guess if I can export the reference libraries in my project as a .jar file then I can run my program with extra configurations? But somehow I can only find ways to export the whole project as a .jar rather than the libraries only. – rainbow66 Aug 28 '17 at 11:28
  • while exporting jar did u select the option of Package required libraries into generated JAR in library handling part? May be u can give it a try, by selecting that radio button and then exporting and running it using the same command. – NickS Aug 28 '17 at 11:35
  • That jar file actually works except giving me a warning saying "***WARNING: Display must be created on main thread due to Cocoa restrictions.". To solve that problem by adding optional arguments -XstartOnFirstThread in the terminal. The post is here https://stackoverflow.com/questions/22273960/swt-exception-when-running-jar-exception-in-thread-main-org-eclipse-swt-swtex – rainbow66 Aug 29 '17 at 00:22

0 Answers0