简体   繁体   English

在没有JRE的计算机上运行JAR。 使其便携

[英]Running JAR in a computer that has no JRE. Making it portable

I have a JAR file that I wish to run on CentOS (university computer labs). 我有一个希望在CentOS(大学计算机实验室)上运行的JAR文件。 But the problem is it has no JRE installed. 但是问题是它没有安装JRE。 The sys admin won't install the latest version of Java. 系统管理员不会安装Java的最新版本。 Is there a way to run a JAR on a computer that has no JRE installed? 有没有办法在没有安装JRE的计算机上运行JAR? And installing JRE isn't an option since the sysadmin denied that request. 由于系统管理员拒绝了该请求,因此无法选择安装JRE。

Assumption: JAR files are generated with no trouble. 假设:JAR文件的生成没有问题。 Running is the issue. 运行是问题。

The sys admin won't install the latest version of Java. 系统管理员不会安装Java的最新版本。 Is there a way to run a JAR on a computer that has no JRE installed? 有没有办法在没有安装JRE的计算机上运行JAR?

Basically, no. 基本上没有

Possible alternatives: 可能的选择:

  • Install Java yourself in your home directory. 自己在主目录中安装Java。 (If you have enough disk space, and this doesn't violate the rules for your Lab.) (如果您有足够的磁盘空间,并且这不违反实验室的规则。)
  • If the lab permits the running of virtual machines, launch one and install and run Java with the VM. 如果实验室允许运行虚拟机,请启动一个虚拟机,然后通过VM安装并运行Java。
  • Run this application somewhere else; 在其他地方运行该应用程序; eg on your laptop, on an Amazon AWS server (costs money), etc. 例如在您的笔记本电脑上,在Amazon AWS服务器上(需要付费)等。

If you had source code for the JAR, and if it only used pre-Java 5 APIs and language features, then the GNU GCJ compiler might be an option. 如果您具有JAR的源代码,并且仅使用Java 5之前的API和语言功能,则可以选择使用GNU GCJ编译器。 But I would not recommend this. 但是我不建议这样做。

(And you would need to convince the sys admin to install GCJ! And the resulting executable may not be portable, depending on what libraries it is linked against, processor types and versions, etc.) (而且,您需要说服系统管理员安装GCJ!根据所链接的库,处理器类型和版本等,生成的可执行文件可能无法移植。)


Given that you do have source code and a development platform (Intellij), try changing your IDE's compiler settings to compile for the (older) version of Java installed on the Lab machines. 假设您确实具有源代码和开发平台(Intellij),请尝试更改IDE的编译器设置,以针对Lab机器上安装的Java(旧)版本进行编译。 The Intellij documention is here: Intellij文档在这里:

Read the linked pages as well. 还要阅读链接的页面。

But this won't work if you use newer APIs and language features. 但是,如果您使用较新的API和语言功能,则将无法使用。

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

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