如何创建一个cmd文件来运行jar? [英] How to create a cmd file to run jars?

查看:499
本文介绍了如何创建一个cmd文件来运行jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过一切,尝试,使我的jar文件可执行文件通过双击。但我得出结论,要么我需要一些主要的帮助,因为我的java安装有一个问题,或者我需要创建一个.cmd文件,以自动运行它们正确。文件中的代码如下:

I have literally tried everything to try and make my jar files executable by double clicking. But i have come to the conclusion that either I need some major help because my java installation has a problem, or I need to create a .cmd file to automatically run them properly. The code in the file would be like this:

java -jar myfile.jar

我将替换 myfile.jar ,以便窗口放入文件扩展名我想打开?感谢。

What would i replace myfile.jar with so that windows puts in the file extension of what i'm trying to open? Thanks.

推荐答案

如果您想要一个 .cmd 运行你的jar,那么这样的文件可能看起来像这样

If you want to have a .cmd file to run your jar, then such a file could look like this

@ECHO OFF
SET JRE_HOME=<path to your jre>
%JRE_HOME%\bin\java.exe -jar myfile.jar

注这里的选项 -jar 隐含地意味着 myfile.jar 包含所有的依赖,你不能扩展类路径包括其他依赖关系。另外使用这个选项需要你的mainifest有一个属性 Main-Class ,它告诉哪个类运行/是你的程序的入口点。

Note that here the option -jar that implicitly means that myfile.jar contains all your dependencies and you cannot extend the classpath to include other dependencies. Also using the this option require your mainifest to have the attibute Main-Class which tells which class to run / is the entry point for your program.

更好的是在类路径中包含 myfile.jar 将你的主类传递给 java.exe

Better yet include myfile.jar in the classpath an pass your main class to java.exe

@ECHO OFF
SET JRE_HOME=<path to your jre>
SET MY_CLASSPATH=<jars/libs your app depends on separated by semicolon>;myfile.jar
%JRE_HOME%\bin\java.exe -cp %MY_CLASSPATH% <your main class>

最后,如果你想创建一个 .exe 你的java程序,然后你可能想使用包装器 jsmooth ,它将您的jar及其所有依赖项捆绑为一个 .exe 文件

Finally if you want to make an .exe of your java programm then you might want to use a wrapper like jsmooth which bundles your jar and all it's dependencies into a single .exe file

这篇关于如何创建一个cmd文件来运行jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆