0

I'm having issues running a jar file I compiled from an eclipse project. I'm fairly new to Java so I'm likely missing something simple.

When I run the jar file from the command line:

javaw -jar test1.jar

the program runs fine. But when I double click the jar it doesn't run. I believe the issue has to do with 32 bit versus 64 bit java (double clicking the jar file opens the "javaw.exe *32" process whereas running from the command line opens "javaw.exe"). I'm using the swing GUI libraries, if that makes a difference.

Is that the issue?

Is there a way to make eclipse export a .jar file that will be compatible with "javaw.exe *32"?

Thanks.

EDIT: I figured out the error was related to using generics with JList, which is only supported in Java 7. Double clicking the .jar was running a 32-bit version of Java 6, which is what was throwing the error. Thanks for the help guys

Skaevola
  • 103
  • 5
  • 3
    *off topic* why do people always want to run jar by double click!? Why not use something that natively runs by double on a specific platform and then use it to launch the jar, for windows a simple .bat file with the command above would do the job, an alternative is to create a .exe wrapper, a lot of tools out there can help, jsmooth is one... – A4L Aug 13 '14 at 19:33
  • I dont know much about desktop application deployment but what I do know is that most people have their "Open With" messed up for jar files (myself included on many occasions). If you want the jar file to open up right on your machine then change the program it opens with. If you want to give it to a friend then use a tool or batch file suggested by @A4L that will smooth over that process so you dont have that headache. – ug_ Aug 13 '14 at 19:38
  • 1
    @A4L, that's like taking the platform independence way from Java. Why go through the trouble of creating 3 launchers (Win, Mac, Linux), when you can have 1 launcher that will work on all 3? Especially if it's just a test run of the program. Furthermore, launching it from a .bat/exe file won't fix his issue of the JAR not being executable. My assumption for the problem is that you did not select a run-able JAR file from the eclipse menu. – zfollette Aug 13 '14 at 19:39
  • @A4L Thanks for the comment. I actually originally used a batch script to do that, but it doesn't always work on other people's computers. I'd much rather solve the underlying issue, which I believe is related to 32 bit Java compatibility. – Skaevola Aug 13 '14 at 19:42
  • @Error I did select run-able JAR file when I exported it – Skaevola Aug 13 '14 at 19:44
  • I have 2 things I want you to try. 1) Check the manifest and see if it contains the proper main class 2) Check and see that you are not getting a major.minor error running the JAR with a batch file – zfollette Aug 13 '14 at 19:45
  • @Error I don't think that's his problem since it runs in the command line. – damian Aug 13 '14 at 19:47
  • @Error I think it is easier to make a launcher for each platform, than try to make a jar run on each with double click. The fact that this setup is itself necessary for each platform would defeat java's platform independence, luckily this is not how java's independence is meant. The launcher for java is `java.exe` and/or `javaw.exe` i.e. the `JVM` and it is present on each platform. All you need to hand out is the jars and there should be a `jre` to run them. – A4L Aug 13 '14 at 19:48
  • @Skaevola, just to clarify, by 'Running from the command-line' did you mean running the project in eclipse, or running with a batch file? A4L, why would you need to make a JAR for each platform? Java bytecode isn't platform specific so the same JAR file would run on any system with JRE installed. – zfollette Aug 13 '14 at 19:49
  • @Error besides of that if you look at most distributions of java based programs and tolls you'll see that all vendors provide such launchers for each platform or they are packaged in such a way that after installing you just double click on some link and it starts. – A4L Aug 13 '14 at 19:50
  • @Error It runs succesfully from the batch file. – Skaevola Aug 13 '14 at 19:52
  • @Skaevola, just more clarification, are you running the JAR from the batch file, or the main class? – zfollette Aug 13 '14 at 19:53
  • @Error Here's the actual line in the batch file: javaw -jar test1.jar – Skaevola Aug 13 '14 at 19:54
  • @Skaevola well you'll have to go to each platform and fix it or provide a howto so that people can fix it by themselves, for windows, go to registry, delete/edit the key YXZ/don't know what, for linux ... for mac os and so on.... – A4L Aug 13 '14 at 19:55
  • @A4L, are you actually going to address the issue or just keep going on about how it's not good to run from a JAR file? As for the problem, do you get any output if you use `java` instead of `javaw` in the command line? I ask this because `javaw` doesn't wait and listen for output, wereas `java` does. – zfollette Aug 13 '14 at 19:58
  • @Error That also works. Like I said, it seems like a 32 bit versus 64 bit issue. When I run these batch files a java.exe process is created, but when I run by double clicking a java.exe *32 process is created and it doesn't work. Is there a way to export a 32 bit compatible .jar? Alternately maybe it's a library issue? I'm using the Java Swing gui library, so maybe that's working with the JDK but not with the JRE? Still trying to understand this all. – Skaevola Aug 13 '14 at 19:59
  • Java byte code is platform independent, meaning that the same bytecode will run with 32 bit and 64 bit. But if you want to try it, you could set eclipses default compiler to a 32 bit version of java and recompile/export. – zfollette Aug 13 '14 at 20:04
  • @Error sorry if I annoyed you, but I think I was addressing the issue all the time, because IMHO suggesting a better way for doing thing is a way of addressing the issue, but I might be wrong. – A4L Aug 13 '14 at 20:14
  • To address the issue as @Error suggests, the problem is that you have two things, 1st you have a path to java binaries in your `PATH` environment variable which points to the 64 bit version, probably you have both, but the 64 bit version is first and it wins the race and your program run fine from cmd. 2nd you have some registry key which controls the action on double click on jar files, and it points to the the 32bit version. – A4L Aug 13 '14 at 20:16
  • I think you were more or less just addressing a work around for the issue. While yes, it is better to do like you said, it would be very impractical for testing. – zfollette Aug 13 '14 at 20:16
  • So what you need to do is to go to the windows registry and find that key and edit it so that it points to the 64 bit version of `javaw.exe`, you can find more help in this ´[so question](http://stackoverflow.com/q/7325676/1113392) as it is addressing the same problem you are facing. – A4L Aug 13 '14 at 20:16
  • @A4L thanks for the link, but is there a way to change the compilation settings so the jar will run correctly on the 32 bit version? – Skaevola Aug 13 '14 at 20:19
  • @Skaevola and for that too there already is an [answer](http://stackoverflow.com/q/783662/1113392) ;-) – A4L Aug 13 '14 at 20:21
  • 2
    In addition to @A4L's suggestion, do you have multiple java versions installed? It could be a problem with double-clicking pointing to an older version of java. In that case, the solution is similar to A4L's. – zfollette Aug 13 '14 at 20:22
  • @Error I think that must be the problem - I will try compiling for an older version of Java. Thanks for the help! – Skaevola Aug 13 '14 at 20:30
  • If it is the problem, will it be alright if I post it as an answer and you accept it? I could use the extra reputation – zfollette Aug 13 '14 at 20:35
  • @Skaevola to think of it, you actually didn't even say what error you get!!! What sure is, is that you have two java installations, most likely of different versions, so if you compile with java7 and try to run with java5 it will fail, because the class files versions are different. Pleas check the version you compile (in eclipse compiler compliance) with and the versions you run with. – A4L Aug 13 '14 at 20:38
  • Double clicking would not result in an error, just an un successful execution. Since he can run successfully with the command-line, there is no easy way to find out the exact error that I know of – zfollette Aug 13 '14 at 20:43
  • 1
    @Skaevola sure there is a way, run both from command line with the full path to the java exe, once with the 32bit and another with the 64 bit version and you will definitely see the error! also show the version of each with the `-version` switch. – A4L Aug 13 '14 at 21:46
  • I figured out the error was related to using generics with JList, which is only supported in Java 7. Double clicking the .jar was running a 32-bit version of Java 6, which is what was throwing the error. Thanks for the help guys – Skaevola Aug 15 '14 at 19:03

0 Answers0