0

I created a Java project called TotalBeginner, and exported as a jar. I then reference it in a desktop app with a SWT GUI, called MyLibrary. I now want to be able to run MyLibrary outside of the Eclipse IDE (I am running Luna 4.4.0). In following the advice of other answers to questions on Stack Overflow, I export as Runnable JAR File. I pick "Package required libraries into generated JAR" - so if I understand correctly, referenced libraries like TotalBeginner.jar should be included in the MyLibrary.jar, correct? However, when I run it, it returns to the command prompt with absolutely nothing appearing to happen. Task Manager (Windows 7) shows no Javaw process. What am I missing? Thanks.

C:\Users\jimerman\>javaw -jar MyLibrary-app.jar C:\Users\jimerman\>_ 

No errors, no dialogs.

8
  • I should further add, the TotalBeginner is a class library, so no external or main functions. Commented Aug 11, 2014 at 19:24
  • Execute it with "java" insteead of javaw, this will print the stacktrace. Post the stacktrace. Commented Aug 11, 2014 at 19:29
  • OK, this could be it: Error: Could not find or load main class MyLibrary.MainWindow. My project is called MyLibrary, the package is called "(default package)" - and the main() class is MainWindow. So perhaps I have the class name wrong? Commented Aug 11, 2014 at 19:35
  • "and the main() class is MainWindow" --- WHAT? A METHOD is no CLASS. Commented Aug 11, 2014 at 19:50
  • Sorry for the confusion, the MainWindow is a SWT window class, that has the main() method. I created a named package, and a manifest file (found instructions wiki.eclipse.org/…), now when I execute I get the following: Commented Aug 11, 2014 at 20:00

1 Answer 1

1

I suspect in your JAR you only have classes of your own project (which is fine in fact) and you haven't put all dependent JARs in classpath (As it is complaining for unable to find org/eclipse/swt/events/DisposeListener)

It may be tedious to find out all dependent JARs and put it in classpath of java command manually.

Consider making use of build tools like Maven and Gradle, which will save you trouble in collecting dependencies, and there are plugins for them to help you to construct artifacts that makes execution easier.

For example by using Maven, what you need is to prepare a POM, put SWT (and other dependencies) as dependencies of your project.

Then by making use of shade, appassembler or assembly plugins, you can easily have a uber-jar that contains all dependencies, or have a zip files that all dependencies are put in a specific directory and you can easily execute using generated command.

Sign up to request clarification or add additional context in comments.

2 Comments

Maven with maven-shade-plugin is my go-to for packaging simple tools with their libraries.
Thanks, that's what I was looking for. Too bad Eclipse doesn't have it built in. I will try them. I built a manifest file, rebuilt the jar, and now I get the error Could not load SWT library, not in java.library.path. I have been programming in .NET for all these years, which builds the dependencies for you, so I am not familiar yet with Java.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.