File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Strange Problem in Running Jar! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Strange Problem in Running Jar!" Watch "Strange Problem in Running Jar!" New topic
Author

Strange Problem in Running Jar!

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

You can either use the "-source 1.4 -target 1.4" compiler flags, or upgrade the JVM on your Unix box.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Sep 29, 2008
Posts: 12617

They *did* tell you the syntax of the command. You've compiled under 1.6, but are running under 1.5.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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

Joined: Mar 04, 2009
Posts: 477
Thanks everyone. I changed the compiler to 1.5 in Eclipse and created the jar again! Now its working!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange Problem in Running Jar!
 
Similar Threads
Weblogic platform8.1 SP4 installation error
Ant - How to create a runnable jar of jars and classes
Can't upload submission jar / CertManager website down
Installing Fitnesse on Unix
error while starting oc4j