views:

110

answers:

6
+1  Q: 

Jar file of java

I have created a java application and packed it into a jar file on a Windows platform. Now I wants to deploy that jar file on Debian Linux.

  1. Will the same jar file work for Debian Linux?

  2. Is the command, used in windows for executing a jar file from the command prompt, same for Debain Linux?

i.e.

java -jvm "MyJar.jar"

Will the above command work for Debian Linux?

+2  A: 

yes, the main idea of java is that it (should) run on different operating systems, as long as a java runtime is installed.

though i have never heard of the -jvm flag.

if you want to start a jar file you should use the -jar flag.

java -jar "MyJar.jar"

you can also read up on the Write once run anywhere principle.

clamp
+3  A: 

Yes.

Jar files are portable across platforms, and the syntax of the jar command is the same on both Linux and Windows.


EDIT: You should use the latest version of Sun Java unless there is a very good reason not to. Installation instructions: http://wiki.debian.org/Java/Sun

Thorbjørn Ravn Andersen
+1  A: 

Almost. Use:

java -jar "MyJar.jar"

And of course you shouldn't have used anything such JNI or runtime stuff

Davide
+1  A: 

Yes, although you might want to do, in Linux:

java -jar YourJar.jar

Instead of:

java -jvm YourJar.jar
Pablo Santa Cruz
+5  A: 

Generally, it should. However this depends on a few conditions:

  • If you use native code (JNI) you must make sure that the native library is available for the target platform
  • You must make sure you have no paths hardcoded which are Windows specific (in fact you should even watch out for special characters like the Path seperator : vs. ;)
  • You cannot use Runtime specific code
frenetisch applaudierend
+1 I've seen a LOT of Java apps written and tested only on Windows fall down hard on a Mac or Linux machine. WORA is a goal to work toward, not a proof against carelessly written software.
Sixten Otto
+2  A: 

I do my development on a mac but run in linux and windows environments without any problem. Key is not to use JNI, As everyone else have mentioned I would use java -jar "MyJar.jar"