Alright i made a executable jar that holds a test game ran through a application. It runs fine for me but for my friend it does not. It says its unable to find the main class. So does he have to install java jdk or something? Is there a way around this?
4 Answers
Well, for one, he could be using the wrong command line arguments to the JVM to run the Java jar. Secondly, you could have not defined the main class correctly when you built the jar file (see: Unable to load main-class for jar file).
The way that you work around this? In the link I provided above, you'll see that there are a few command line parameters that can be supplied to the JVM that makes a big difference in how the JVM runs. Take those command line parameters and build a batch (or shell) file that end users can run to initialize the program correctly.
As your computer is setup differently, so may be the shell extension that handles files of type ".jar"

- 1
- 1

- 1,009
- 1
- 9
- 27
Try installing the newest version of java (JRE) on their machine (make sure it is of equal or higher version than the one your application was compiled against) and ensure that if you are using different architectures (x86 / x64) that you have the right versions of any libraries. I had this error only yesterday because I deployed a JDK 7u7 application to a machine with JRE 6u7.

- 648
- 2
- 6
- 19
-
That could be it let me try that. – user1600202 Sep 19 '12 at 23:41
-
Yep that was the issue he was still running java 1.6 Thanks! – user1600202 Sep 19 '12 at 23:53
Yes, there is a way around it. Run this script:
@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: this .bat script creates a file association for executable .jar files
ECHO Creating .jar file association...
ECHO JAVA_HOME is %JAVA_HOME%
IF NOT DEFINED JAVA_HOME GOTO :FAIL
REG ADD "HKCR\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKCR\jarfile\shell" /ve /f
REG ADD "HKCR\jarfile\shell\open" /ve /f
ECHO REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%**" /f
REG ADD "HKLM\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
ECHO Finished creating .jar file association for executable .jar files.
PAUSE
GOTO EOF
:FAIL
ECHO Script failed. JAVA_HOME not defined.
PAUSE

- 28,471
- 61
- 196
- 289
- install the new JRE .
- while running the jar make sure you giv the class path in he command. Eg. java -cp asd -jar file.jar

- 128
- 8