3

I've been struggling with this problem for a while now. I found this and this but those solutions won't work for me at all.

My jar works perfect with java -jar on command prompt but when it comes to double click, a JFrame window is opened but it fails on these:

Scanner fileLat = new Scanner( a.getClass().getResourceAsStream("/motor/resources/lat.txt") );
Scanner fileLong = new Scanner( a.getClass().getResourceAsStream("/motor/resources/long.txt") );

Which result on null pointer exceptions and resources not being found.

My directory structure (inside the jar) looks like this:

/ (root)
|- META-INF
|- motor
 |- main
  |- Main.class
 |- resources
  |- lat.txt
  |- long.txt

And my MANIFEST.MF reads as follows:

Manifest-Version: 1.0
Class-Path: .
Main-Class: motor.main.Main

Edit: I just attempted this (especifically, the jar:file:MyJar.jar!/etc...) and it didn't work either.

Community
  • 1
  • 1
Nirro
  • 746
  • 4
  • 18
  • what is your current directory? `Class-Path: .` looks suspicious. – Vlad May 10 '12 at 15:45
  • Double-clicking a file on Windows stablishes it to that file's directory, doesn't it? I think so. For the command prompt is a different one but it works. – Nirro May 10 '12 at 19:02
  • hmm, I am not sure. try to output the current directory to console or some file at the program start. – Vlad May 10 '12 at 19:19
  • Tried: `File test = new File(".");` `System.out.println(test.getAbsolutePath());` It returns the directory where the jar is placed. – Nirro May 10 '12 at 21:26
  • that's bad, it means that the problem is somewhere else :( – Vlad May 10 '12 at 22:29
  • For what I've seen, looks like it has to do with using or not -jar option. When I use command prompt I use it with -jar but on double-clicking it just launches normally. I don't quite understand the difference and of course I can't find a solution. : ( – Nirro May 10 '12 at 22:48

1 Answers1

0

Did you tried to remove Class-Path from the manifest ? Defining the classpath is uncommon in the examples I have here : many applications (incl. jEdit and jExt installer) will run without it.

You could also try to add an empty one.

Seki
  • 11,135
  • 7
  • 46
  • 70
  • Not defining the Class-Path game me an error, leaving it blank gave me a different one. "Invalid or corrupt jarfile" when blank. "Failed to load Main-Class manifest attribute from C:\Users\Nirei\Downloads\EarthClock.jar" when no Class-Path attrib. – Nirro May 10 '12 at 18:11