从 Jar 或 Batch 文件执行 Java 运行应用程序 [英] Executing a Java running application from a Jar or Batch file

查看:31
本文介绍了从 Jar 或 Batch 文件执行 Java 运行应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Java 应用程序和一个构建文件,在它的任务中,有一个任务是从应用程序创建 jar 文件,另一个任务是运行应用程序

I have a Java application and a build file which, among its tasks, has one task to create a jar file from the application and one to run the application

<!-- ===== Create An Executable Jar target ======-->
<target name="jar-task" depends="compile-task">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="jar/Guix.jar" basedir="${gui_bin.dir}">
        <fileset dir="${basedir}">
            <include name="img/**/" />
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="sys.deep.cepu.Start"/>
            </manifest>
            <filelist dir="${basedir}" files="user.properties"/>
    </jar>
</target>

<!-- 
    ============ Run target =================== 
    -->
<target name="run-task" depends="jar-task">
      <java classpath="${basedir};jar/Guix.jar;CK-DASP-2.0.0.jar;library/*;user.properties;img/* " classname="sys.deep.cepu.Start" fork="true">
    </java>
</target>

构建文件完美运行,jar 被创建,应用程序运行.我想允许用户通过单击单个文件(jar 或批处理文件)来启动应用程序.我试图点击生成的可执行 jar 文件,但没有任何反应.正常吗?有人可以帮助我如何从这个 jar 或批处理文件执行程序吗?谢谢!

The build file runs perfectly, the jar is created and the application runs. I would like to allow the user to start the application by clicking on a single file (jar or batch file). I tried to click on the generated executable jar file but nothing happens. Is it normal? Can someone give me an help on how to execute the program from this jar or from a batch file? Thanks!

推荐答案

在构建 jar 文件时,您已经指定了 Main-Class.但是你没有在manifest文件中指定需要的库,只是在运行应用程序的时候在ant文件中指定.

When building you jar file you already specify the Main-Class. But you did not specify the required libraries in the manifest file, only in the ant file when running the application.

将另一个清单属性写入 ant 文件.name 应该是 Class-Path,值是一个 空格 分隔的库列表.查看这里(维基百科)的示例.

Write another manifest attribute into the ant-file. The name should be Class-Path, the value a space separated list of libraries. Look here (Wikipedia) for an example.

之后你的应用程序应该在进入时启动

After that your application should start when entering

java -jar Guix.jar

然后按照在这个问题中描述的步骤 双击即可启动.

Then follow the step described in this question to make it startable with a double click.

这篇关于从 Jar 或 Batch 文件执行 Java 运行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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