运行 JAR 文件而不直接调用 `java` [英] Running a JAR file without directly calling `java`
问题描述
我正在部署一个用 Java 编写的命令行工具,它接受命令行参数.我把它打包成 JAR 文件,因为一个文件很方便.
I am deploying a command-line tool that is written in Java that accepts command-line arguments. I have it packaged as a JAR file because it is convenient to have a single file.
问题是要运行它你必须先调用java -jar (filename) (args)
,这很烦人.
The problem is that to run it you must first call java -jar (filename) (args)
and that is quite annoying.
我目前使用的方法是使用一个简单的 bash 脚本来启动它,但这并不理想.
The current way I have it is to have a simple bash script that launches it, but this is less than ideal.
无论如何(在 Linux、Ubuntu Server 中)是否可以制作一个自行调用 Java VM 的 JAR 文件?我找了一个shebang,但找不到(这当然有意义,因为它是编译代码).
Is there anyway (in Linux, Ubuntu Server) to make a JAR file that invokes the Java VM by itself? I've looked for a shebang, but couldn't find one (which of course makes sense since it is compiled code).
这就是我想要做的:myprogram.jar arg1 -arg2
而不是这个:java -jar myprogram.jar arg1 -arg2
This is what I want to do: myprogram.jar arg1 -arg2
instead of this: java -jar myprogram.jar arg1 -arg2
谢谢,
布莱恩
推荐答案
参见 Documentation/javaLinux 内核文档中的 .txt ,它告诉您如何使用 binfmt_misc
内核模块配置系统以自动运行 Jar 文件.但是,这是您在计算机上更改的配置选项,而不是您更改 jar 文件的内容,因此它不会从系统到系统遵循 jar 文件.
See Documentation/java.txt in the Linux Kernel documentation, which tells you how to configure a system using the binfmt_misc
kernel module to run Jar files automatically. However, this is a configuration option you change on a computer, not something you change about the jar file, so it doesn't follow the jar file from system to system.
这篇关于运行 JAR 文件而不直接调用 `java`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!