7 Replies - 662 Views - Last Post: 07 October 2012 - 07:38 PM Rate Topic: -----

#1 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

.jar cannot find main class?

Posted 06 October 2012 - 12:25 PM

I created this .jar file that works on many Windows machines, but does not work on many others. I see 2 problems:

1, the .jar file appears as a zip icon, right click->Open does not show "Java Platform SE Binary" as an option (so double click does not execute the .jar). I have to manually select bin/javaw.exe. How do I not do it manually?

2, after I associate javaw.exe, it says "cannot find main class"? Command prompt java -jar executes just fine, on the other hand.

Any help?
thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: .jar cannot find main class?

#2 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: .jar cannot find main class?

Posted 06 October 2012 - 02:37 PM

and it gets worse when i uninstall jre6, reinstall jre7.
now i cannot even associate javaw.exe with the .jar file?

in command prompt:
>>assoc .jar
.jar=jarfile
>>ftype jarfile
jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*


I read somewhere that installation of JRE is supposed to associate the file type (.jar) with javaw.exe automatically. So what's wrong here?

I also noticed that no path has been added into the environment variable "path", how come typing "java" in command prompt works?

This post has been edited by g37752: 06 October 2012 - 03:10 PM

Was This Post Helpful? 0
  • +
  • -

#3 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: .jar cannot find main class?

Posted 07 October 2012 - 01:55 AM

I suspect the problem is with the Chinese OS file paths. On the other hand, I read that classpath is ignored when executing a jar file because everything is in the jar? if so, how can special characters in paths cause problems?

My java program though is very simple. It is only 1 file, with no packages. it's a 1-line manifest file.

I tried to build the .jar on the machine where my .jar does not work. I install the same version of JDK 1.6, compile, and jar. Again, it runs in the command prompt, and fails on double click - "cannot find main class"? environment variable CLASSPATH=.;
to build the jar, in the folder, i use javac to generate .class. then
jar cfm a.jar manifest.txt *.class


in control panel -> Default Programs, I have .classpath on my working computer which is not found on the non-working computer. Mine does not have .class either? I don't even see that I can add an entry in Default Programs?
Was This Post Helpful? 0
  • +
  • -

#4 Kakerergodt  Icon User is offline

  • D.I.C Head

Reputation: 87
  • View blog
  • Posts: 201
  • Joined: 01-May 12

Re: .jar cannot find main class?

Posted 07 October 2012 - 03:32 AM

I've had friends with, what might be, the same problem before, for them the reason for the problem was that they had both JRE and JDK installed and when they launched from commandprompt the newest one(java.exe) was used, but when launching the jar from explorer the oldest version of java was used. So make sure both JRE and JDK are up to date.
Was This Post Helpful? 1
  • +
  • -

#5 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: .jar cannot find main class?

Posted 07 October 2012 - 11:36 AM

View PostKakerergodt, on 07 October 2012 - 03:32 AM, said:

I've had friends with, what might be, the same problem before, for them the reason for the problem was that they had both JRE and JDK installed and when they launched from commandprompt the newest one(java.exe) was used, but when launching the jar from explorer the oldest version of java was used. So make sure both JRE and JDK are up to date.


thanks for the reply. actually, i did not have jdk installed on my first test. there was only 1 jre installed (6 or 7). i also tested jdk6 with jre6.
Was This Post Helpful? 0
  • +
  • -

#6 Kakerergodt  Icon User is offline

  • D.I.C Head

Reputation: 87
  • View blog
  • Posts: 201
  • Joined: 01-May 12

Re: .jar cannot find main class?

Posted 07 October 2012 - 01:44 PM

Have you checked the registry and what's there regarding jar-files?
This is how it looks on my computer:

[HKEY_CLASSES_ROOT]
   [.jar] -> jarfile
   [jarfile] -> Executable Jar File
      [shell]
         [open]
            [command] -> "C:\...javaw.exe" -jar "%1" %*

This post has been edited by Kakerergodt: 07 October 2012 - 01:46 PM

Was This Post Helpful? 1
  • +
  • -

#7 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: .jar cannot find main class?

Posted 07 October 2012 - 02:30 PM

View PostKakerergodt, on 07 October 2012 - 01:44 PM, said:

Have you checked the registry and what's there regarding jar-files?
This is how it looks on my computer:

[HKEY_CLASSES_ROOT]
   [.jar] -> jarfile
   [jarfile] -> Executable Jar File
      [shell]
         [open]
            [command] -> "C:\...javaw.exe" -jar "%1" %*


yes, in the registry, there are 2 entries:
HKEY_CLASSES_ROOT:jarfile:shell:open:command with %*
HKEY_CURRENT_USER:software:classes:Applications:javaw.exe:shell:open:command withOUT %*

I added %* but it does not help. I wonder if i need to reboot (remote access - i cannot access the computer after boot)

it works in command prompt:
>>ftype jarfile
jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*

i even typed in the exact phrase to skip over environment variable:
"C:\Program Files\Java\jre7\bin\javaw.exe" -jar a.jar


meaning double click is not executing exact command as this one..
Was This Post Helpful? 0
  • +
  • -

#8 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: .jar cannot find main class?

Posted 07 October 2012 - 07:38 PM

looks like changing HKEY_CURRENT_USER:software:classes:Applications:javaw.exe:shell:open:command is incorrect. this one should not have %* in the end.

I wonder in "C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
how does windows assign the clicked object (a.jar) as %*? in this case, it seems Windows has trouble doing that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1