Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange Problem in Running Jar!

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I had developed a Project in Eclipse in Windows. I have created the jar file and i have uploaded it in a Unix machine using Filezilla. Now when i run the jar on the Unix machine, I get an error message as:



Could you please tell me the how to get rid of this problem! I have JAVA 1.6 installed on my windows machine and the java installed in the Unix box is 1.4.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either use the "-source 1.4 -target 1.4" compiler flags, or upgrade the JVM on your Unix box.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15274
38
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message means that you have compiled your classes with JDK version 6, but that you are trying to run the classes on an older JRE (Java 5 or older).

Java is downwards compatible - classes compiled with an older version run unmodified on a newer version, but not upwards compatible - classes compiled with a newer version do not run on an older version.

Make sure you compile your source code with the right JDK version. JDK 1.4 is still available for download on Sun's website.

You could use the -source and -target switches as Rob suggests, but if you use classes from the Java 6 standard API which don't exist in the older JRE, it will still not work correctly.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please tell me the syntax of the command. Because the source compiler is in a Windows machine and the target compiler is in a Unix box!

JDK 1.5 is installed in a folder called /software/j2sdk1.5.0_10 in the UNIX box.

I tried running the command using command:

java -jar FTPDownloadClient_fat.jar
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They *did* tell you the syntax of the command. You've compiled under 1.6, but are running under 1.5.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The source and target must be set when compiling, not when running the JVM. So it's "javac -source 1.4 -target 1.4 <anything else you want>". If you're using an IDE like Eclipse you can specify the target platform in the project properties.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone. I changed the compiler to 1.5 in Eclipse and created the jar again! Now its working!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic