I have a jar file named umar.jar in /root/umar/bin directory. I have a shell script file run.sh in same directory. Following is the content of run.sh
#!/bin/bash
"$JAVA_HOME"/bin/java -jar /root/umar/bin/umar.jar
Now when I run the shell script, I get the following error
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
After some googling, I found (as a folk from stackoverflow mentioned) that such errors occur when the Jar was compiled with a later version of the JDK than your JRE.
Now strange thing is, if I run this command directly on shell
java -jar umar.jar
it works perfectly fine. If the jar was compiled with a later version of JDK than my JRE, it shouldn't have had run at all even from the shell.
What do you suggest?
compare "java -version " and ""$JAVA_HOME"/bin/java -version"
You probably have multiple JVMs installed
As already mentioned - you're trying to use byte code compiled by the later compiler with old jvm.
Please note that if your PATH contains multiple java executables of different versions you can switch between them easily using '-version' key.
Suppose you have java5 and java6 at your PATH and java5 is located before java6 there. You can see that java5 is used by default then (if you execute 'java -version' it prints corresponding information). However, you can start java6 easily using command like 'java -version:1.6 ...' (e.g. if you execute 'java -version:1.6 -version' you see that java6 is used).
Export the java and jre home which you need to use in your sh file.
Run the jar using the exported java home
e.g
export JAVA_HOME=/opt/java6
export JRE_HOME=/opt/java6/jre
/opt/java6/bin/java -Xms2048m -Xmx2048m -jar abc.jar $1
Related
I want to run my Java code in remote server with external jar file. I referred to this tutorial and run IntelliJ IDE to generate a jar file of my whole project. Now I can run the following code in local terminal successfully.
javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java
java -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try
The code will run successfully. However, when I try the same thing in server. The compile process can be finished without any errors or warnings.
javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java
I have checked that the class file new_server_try.class is generated in the directory.
However the second step will return error as Could not find or load main class new_server_try and I am not sure why this happens.
on the second command try giving the full package name .. like shown below
java -cp "/Users/natsuapo/out/artifacts/main_jar/main.jar:lib/*" my.package.MainClass
also with operating system the command differs, check below
Windows
java -cp "Test.jar;lib/*" my.package.MainClass
Unix
java -cp "Test.jar:lib/*" my.package.MainClass
I have installed multiple versions of JDK, including 1.6,1.7,1.8.
I want to know which version of java.exe gets executed when I run software that needs JRE. I did some testing, see below:
Tests:
cmd.exe command: echo %java_home%
prints: java version "1.8.0_31"
cmd.exe command: java -version
prints: java version "1.8.0_31"
Then I checked the register table in HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.8 and got the javaHome key value
result: C:\Program Files\Java\jdk1.8.0_31.
java code: System.out.println(System.getProperty("java.home"));
prints: C:\Program Files (x86)\Java\jdk1.7.0_15\jre
Finally, I opened the task manager, searched the java.exe process and located the java.exe directory at:
result: C:\Program Files (x86)\Java\jdk1.7.0_15\bin
Question:
I'm confused which jave.exe file the computer chooses. Can you help?
Passive approach
You may want what the where windows command line utility does; assuming you have only one java.exe in your %PATH%
Try:
where java.exe
If you have multiple version of java pin your %PATH% this will return multiple values. (unfortunately)
Active approach
Set your environment this way:
Have your PATH environment variable to point ONLY to c:\tools\java\default
Store all your jre in one folder like
C:\tools\Java\JRE_1.6
C:\tools\Java\JRE_1.7
C:\tools\Java\JRE_1.8
Then open a comman propt and inside C:\tools\Java\ execute
junction default JRE_1.6
This will create a junction (wich is more or less like a symbolic lync).
In this way you will always have your default java in c:\tools\java\default.
If you then need to change your default java to the 1.8 version you just neet to execute
junction -d default
junction default JRE_1.8
From information you provided your default java is set to java 8 and the program you run is like to be run in some ide that use java 7.
Java -version command gives the default set java in your system.
I have installed Java 1.7.0_45 on Mac OS X 10.6.8 using Pacifist [http://www.charlessoft.com/] however I am unable to run a jar file which I have downloaded. The jar file is a threaded application.
The error message I am getting is:
java -jar context.jar
2013-10-31 14:14:41.898 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement methodSignatureForSelector: -- trouble ahead
2013-10-31 14:14:41.900 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement doesNotRecognizeSelector: -- abort
Trace/BPT trap
Is there anyway I can run the jar. I have set the JAVA_HOME path properly and java -version is showing 1.7.0_45 as the version.
The same application works properly on Windows Java 1.7.0_45 and also on Linux Java 1.7.
The web search for the solution and the given keywords return very few results and none of them have any specific solution in it. I am new to mac so I am not fully able to understand the issue.
Alternatively, is there anyway I can run Java from folder in Mac like I can do in windows and Linux by just extracting the Java contents and changing the JAVA_HOME. If that is possible then I should be able to run my JAR.
I had kind of same problem while installing an application through jar file, my Java was not detected by the jar application installer,
Over here I see that one of the method is not accessible, could be a same problem. But I am not very sure of it.
make sure you have rt.jar in your JAVA_HOME/jre/lib/ folder
In case you don't have then you are required to have it through the process of creation of symbolic link.
In the command below replace your_java_version with proper version matching your requirement.
sudo mkdir -p /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib
Go into the directory:
cd /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib/
Create symbolic link :
sudo ln -s ../../../Classes/classes.jar rt.jar
Hope this solves your problem.
I get the exact same problem with MacOS 10.6.8 and JDK 7. In order to run the jar I had to use the System JRE which is 1.6.x (In my case I wanted to install Squirrel
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar >squirrel-sql-3.6-MACOSX-install.jar
I have CQ5 executable jar file.It is suppose to be executed on double clicking.But i get error saying "could not find Main class program will exit".The same jar file executed on all my team mates machine but i am unable to execute it.
I am working on windows 7 OS.
I have jre6 installed.
I have done all steps provided in following link .jar file keeps giving me " could not find the main class". Program will exit.
my ftype and assoc is set to propervalue.
there is no problem in manifest file(becoz it executed on others machine).
all my path variables are set properly.
type of file on my system is "JAR" but on everyone else machine its "Executable JAR"
Could not figure out what is problem with my system.
Help plz.
You can alternatively try executing this command from a command console,
first CD to the location where you have the jar file and execute
For Win7 32-bit:
java -Xmx1024M -jar .jar
For Win7 64-bit:
java -XX:MaxPermSize=256m -Xmx1024M -jar .jar
if you have supported version of Java installed correctly, then the command should be able to start the CQ5 server. In that case, for fixing the double click issue, you would need to fix the filetype association of .jar files to open with /bin/javaw.exe
For supported Java versions, refer
CQ5.5 http://dev.day.com/docs/en/cq/5-5/deploying/technical_requirements.html
CQ5.6 http://dev.day.com/docs/en/cq/5-6/deploying/technical_requirements.html
I am trying to compile some files using cygwin shell.
java file that I am trying to compile is C:\Users\Programs\x.java
For windows command prompt
C:\Users\Programs>javac x.java
No errors.
For Cygwin shell
$ javac /cygdrive/c/Users/Programs/x.java
Error:
javac: file not found: \cygdrive\c\Users\Programs\x.java
Why do I get an error in cygwin shell though it runs in windows command prompt
javac is Windows application. It has no clue about /cygdrive. Always keep it in mind and pass valid Windows paths.
So use javac 'c:/Users/Programs/x.java' or javac c\:/Users/Programs/x.java
Also, as in most Unix shells \ must be escaped if you need to use it.
I think that the problem is that "cygdrive" is a pseudo-device that is implemented in a Cygwin-specific library. If the executable you are running has not been linked against that library (and the Oracle Java executables have not!) it won't correctly resolve the "/cygdrive" path component.