简体   繁体   English

Jar文件的java

[英]Jar file of java

I have created a java application and packed it into a jar file on a Windows platform. 我创建了一个java应用程序并将其打包到Windows平台上的jar文件中。 Now I wants to deploy that jar file on Debian Linux. 现在我想在Debian Linux上部署该jar文件。

  1. Will the same jar file work for Debian Linux? 相同的jar文件是否适用于Debian Linux?

  2. Is the command, used in windows for executing a jar file from the command prompt, same for Debain Linux? 在Windows中用于从命令提示符执行jar文件的命令是否与Debain Linux相同?

ie

java -jvm "MyJar.jar"

Will the above command work for Debian Linux? 以上命令是否适用于Debian Linux?

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 如果使用本机代码(JNI),则必须确保本机库可用于目标平台
  • 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. ;) 您必须确保没有特定于Windows的硬编码路径(实际上您甚至应该注意特殊字符,例如Path seperator:vs.;)
  • You cannot use Runtime specific code 您不能使用特定于运行时的代码

Yes. 是。

Jar files are portable across platforms, and the syntax of the jar command is the same on both Linux and Windows. Jar文件可跨平台移植,并且jar命令的语法在Linux和Windows上都是相同的。


EDIT: You should use the latest version of Sun Java unless there is a very good reason not to. 编辑:您应该使用最新版本的Sun Java的,除非有很好的理由不这样做。 Installation instructions: http://wiki.debian.org/Java/Sun 安装说明: http//wiki.debian.org/Java/Sun

1. Will the same jar file work for Debian Linux? 1.相同的jar文件是否适用于Debian Linux?

Yes. 是。 Hence the nature of Java (portable code) 因此Java(便携式代码)的本质

2. Is the command, used in windows for executing a jar file from the command prompt, same for Debain Linux? 2.在Windows中用于从命令提示符执行jar文件的命令是否与Debain Linux相同?

java -jar "MyJar.jar" java -jar“MyJar.jar”

yes, the main idea of java is that it (should) run on different operating systems, as long as a java runtime is installed. 是的,java的主要思想是它(应该)在不同的操作系统上运行,只要安装了java运行时即可。

though i have never heard of the -jvm flag. 虽然我从未听说过-jvm标志。

if you want to start a jar file you should use the -jar flag. 如果要启动jar文件,则应使用-jar标志。

java -jar "MyJar.jar"

you can also read up on the Write once run anywhere principle. 您还可以阅读Write once run anywhere原则。

I do my development on a mac but run in linux and windows environments without any problem. 我在mac上进行开发,但在linux和windows环境中运行没有任何问题。 Key is not to use JNI, As everyone else have mentioned I would use java -jar "MyJar.jar" 关键是不要使用JNI,正如其他人都提到的那样我会使用java -jar "MyJar.jar"

Almost. 几乎。 Use: 采用:

java -jar "MyJar.jar" java -jar“MyJar.jar”

And of course you shouldn't have used anything such JNI or runtime stuff 当然,你不应该使用任何类似JNI或运行时的东西

Yes, although you might want to do, in Linux: 是的,虽然您可能想要这样做,但在Linux中:

java -jar YourJar.jar

Instead of: 代替:

java -jvm YourJar.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM