简体   繁体   English

如何从java代码创建* standalone * linux可执行文件

[英]How to create a *standalone* linux executable from java code

I know that java intent is for gui and multi platform, but the problem I'm facing it how to release a java application into a linux servers, which I don't have control on, ie I dont know what java vm is installed if at all. 我知道java意图是针对gui和多平台的,但是我面临的问题是如何将java应用程序发布到linux服务器上,我无法控制,即我不知道java vm是安装的一点都不

So, how do i compile this into a true standalone linux exe, do not assume any pre installed package on the target linux. 那么,我如何将其编译成一个真正的独立linux exe,不要假设目标linux上有任何预安装的包。

public class MyTest {
    public static void main(String[] args) {

        System.out.println("You passed in: " + args[0]);

    }
}

You need to specify as a requirement an installed JRE. 您需要指定已安装的JRE作为要求。
Otherwise you would need to deliver a JRE yourself as part of the deliverable application 否则,您需要自己交付JRE作为可交付应用程序的一部分

The GNU COmpiler for Java does exactly this. 用于JavaGNU COmpiler就是这样做的。 Keep in mind that it will work properly only for small programs, either way you'll need a JVM. 请记住,只有小程序才能正常工作,无论哪种方式都需要JVM。

There's also Avian , which has another approach and allows to deploy a lightweight JVM with jour application, but it still hasn't all the features of a full JRE. 还有Avian ,它有另一种方法,允许使用jour应用程序部署轻量级JVM,但它仍然没有完整JRE的所有功能。

Creating one binary from java may not be that good. 从java创建一个二进制文件可能不是那么好。 You may consider tools like http://launch4j.sourceforge.net/ for creating a full installation along with appropriate jre. 你可以考虑像http://launch4j.sourceforge.net/这样的工具来创建一个完整的安装以及适当的jre。

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

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