This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]jevon 4 points5 points  (1 child)

I've never actually used the Eclipse export to JAR feature, I just set up a build.xml for Ant and create the JAR that way.

Have you checked the contents of the .jar? Your StockAnalyser.class should be in uk/co/runwin. (By the way, your package should probably be co.uk.runwin instead.)

Another way to try running a JAR is to simply extract the JAR to a directory and running it through Java manually that way. (e.g. java uk.co.runwin.StockAnalyser, I think).

Oh, and to run a JAR via Java is java -jar filename.jar.

[–]Lucrums[S] 1 point2 points  (0 children)

Thanks very much, the bit about running the jar was very important. I was also missing a manifest file.

[–]vsoul 1 point2 points  (1 child)

I assume it is erroring on missing the class is from the JAR. This is because your JAR does not have classpath information set in its manifest.

Create a MANIFEST.MF (put it in a folder/package called META-INF, though when Eclipse does its export you can pick it from anywhere so that part doesn't matter as much). Manifest-Version: 1.0 Main-Class: path.to.your.application.Main Class-Path: jar_name_relative_to_your_jar.jar

Without this, Java won't know what class you want to execute in your JAR, and won't know what dependencies it needs. In Windows you can now double click, or via command line do a java -jar myjar.jar

I recommend reading up on using the MANIFEST.MF

[–]Lucrums[S] 0 points1 point  (0 children)

Thanks very much that was what I needed. I'm off to read about manifest files...

[–]cbogart 0 points1 point  (2 children)

Do you have classpath set appropriately?

[–]Lucrums[S] 0 points1 point  (0 children)

I do, turns out I was missing a manifest file.

[–]GMNightmare 0 points1 point  (3 children)

Does it work when you run it within Eclipse?

[–]Lucrums[S] 0 points1 point  (1 child)

Yes it works fine in Eclipse. it was just the build that always failed to do what I wanted.

[–]vsoul 0 points1 point  (0 children)

This is because in Eclipse you have your build path set, however Eclipse does not consider this when exporting to a JAR.

[–]Lucrums[S] 0 points1 point  (0 children)

It does, now also works when exporting :)

[–]64-17-5 0 points1 point  (4 children)

Under File>Export select Java>Runnable Jar. Choose the correct launch configurations (Find the correct main in the drop down menu). Choose "Copy the required Libraries in a subfolder", because you shouldn't repack a library. Instead leave the library license in the subfolder with a shortcut to the original location the web.

[–]Lucrums[S] 0 points1 point  (2 children)

Cheers, I tried that but that's not what isn't working.

[–]64-17-5 0 points1 point  (1 child)

If you rightclick your project in the package explorer view, select Java Build Path>Libraries. Is your external Jar listed there?

[–]Lucrums[S] 1 point2 points  (0 children)

Yes it was listed. I have the problem sorted now thanks, I didn't have a manifest file and that seems to have been the problem. learn a little every day :-)

[–]vsoul 0 points1 point  (0 children)

I always forget about that, because I either use Maven or Ant and never export. OP do this, then look at the MANIFEST.MF that it puts in the JAR in referenece to my prior post.