Amit
Amit

Reputation: 34763

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?

Upvotes: 3

Views: 6700

Answers (7)

Mr. Benjamin
Mr. Benjamin

Reputation: 41

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

Yes. Hence the nature of Java (portable code)

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

java -jar "MyJar.jar"

Upvotes: 4

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

Upvotes: 6

add-semi-colons
add-semi-colons

Reputation: 18810

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"

Upvotes: 2

Alfonso
Alfonso

Reputation: 8482

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

Upvotes: 7

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181340

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

java -jar YourJar.jar

Instead of:

java -jvm YourJar.jar

Upvotes: 1

Davide
Davide

Reputation: 17818

Almost. Use:

java -jar "MyJar.jar"

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

Upvotes: 1

clamp
clamp

Reputation: 34026

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.

Upvotes: 2

Related Questions