如何将 java 文件转换为应用程序?

发布于 2024-07-12 05:52:31 字数 1542 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

墟烟 2024-07-19 05:52:31

基本思想(为您提供一些要搜索的内容)是:将

  • 编译后的 .class 文件捆绑到“jar”中。
  • 将清单添加到您的 jar 中,指定要运行的主类。

当您运行“干净构建”时,您可能会发现您的 IDE 已经创建了它。 Netbeans 将其放入“dist”文件夹中。

现代 JRE 允许您通过双击 jar 等方式来运行该 jar。

您还可以更进一步,使用 JSmooth 等工具将 jar 包装在本机可执行文件中。

The basic idea (to give you some things to search for) is:

  • Bundle your compiled .class files into a 'jar'.
  • Add a manifest to your jar specifying a main class to run.

You might find your IDE already creates this when you run a 'clean build'. Netbeans puts this into a 'dist' folder.

Modern JREs will allow you to run the jar by double clicking it etc.

You can also go a bit further by wrapping the jar in a native executable using a tool such as JSmooth.

梦初启 2024-07-19 05:52:31

查看可执行 jar。 这是精确的,没有任何细节, 创建可执行 jar 文件

Look at executable jar. Here is the precise one, without any details, Creating executable jar files.

晒暮凉 2024-07-19 05:52:31

你使用什么IDE?

根据 IDE,某些支持 导出功能将为您创建 .jar 可执行文件。 例如,在 Eclipse 中,您就有该选项。 另外,还有其他适用于 Eclipse 的插件,例如 Fat-Jar,其中将包含您需要的任何其他库包括不属于 Sun 标准库的一部分。

What IDE are you using?

Depending on the IDE, some support Export features that will create the .jar executable for you. For example, in Eclipse, you've got that option. Plus there are additional plug-ins for Eclipse, such as Fat-Jar, that will include any additional libs you include that aren't part of Sun's standard libs.

做个ˇ局外人 2024-07-19 05:52:31

Java 文件必须通过 Java 虚拟机运行,因此您可以从命令行运行类文件。

如果您有一个名为 filename.java 的文件,请将其编译为 filename.class,然后您可以通过键入 java filename 从命令行运行它>

Java files have to run through the Java Virtual Machine, so you can run your class files from the command line.

If you have a file called filename.java you compile it to filename.class and then you can run it from a command line by typing java filename

岁吢 2024-07-19 05:52:31

如果您想在 Windows 上分发应用程序,请查看 JSmooth

If you want to distribute your application on Windows, look into JSmooth.

久伴你 2024-07-19 05:52:31

JNLP/网络启动

JNLP/Web Start

给我一枪 2024-07-19 05:52:31

“基本思想(给你一些
要搜索的内容)是:

将编译后的 .class 文件捆绑到
一个“罐子”。 将清单添加到您的 jar 中
指定要运行的主类。 你
可能会发现您的 IDE 已经创建了
当您运行“干净构建”时会出现此情况。
Netbeans 将其放入“dist”中
文件夹。”(由 Cogsy)

此外,为了实现此目的,您可以选择:

根据 IDE,一些支持
导出功能将创建
.jar 可执行文件。 例如,
在 Eclipse 中,您有这个选项。
另外还有额外的插件
Eclipse,例如 Fat-Jar,它将
包括您的任何其他库
包括不属于 Sun 的
标准库。 (作者:kchau)

或者,如果您要做严肃的事情,请选择像 Ant 或 Maven 这样的构建脚本。
以下是 Ant build.xml 脚本的示例:

<project name="jar with libs" default="compile and build" basedir=".">
    <!-- this is used at compile time -->
    <path id="example-classpath">
        <pathelement location="${root-dir}" />
        <fileset dir="D:/LIC/xalan-j_2_7_1" includes="*.jar" />
    </path>

    <target name="compile and build">
        <!-- deletes previously created jar -->
        <delete file="test.jar" />

        <!-- compile your code and drop .class into "bin" directory -->
        <javac srcdir="${basedir}" destdir="bin" debug="true" deprecation="on">
            <!-- this is telling the compiler where are the dependencies -->
            <classpath refid="example-classpath" />
        </javac>

        <!-- copy the JARs that you need to "bin" directory  -->
        <copy todir="bin">
            <fileset dir="D:/LIC/xalan-j_2_7_1" includes="*.jar" />
        </copy>

        <!-- creates your jar with the contents inside "bin" (now with your .class and .jar dependencies) -->
        <jar destfile="test.jar" basedir="bin" duplicate="preserve">
            <manifest>
                <!-- Who is building this jar? -->
                <attribute name="Built-By" value="${user.name}" />
                <!-- Information about the program itself -->
                <attribute name="Implementation-Vendor" value="ACME inc." />
                <attribute name="Implementation-Title" value="GreatProduct" />
                <attribute name="Implementation-Version" value="1.0.0beta2" />
                <!-- this tells which class should run when executing your jar -->
                <attribute name="Main-class" value="ApplyXPath" />
            </manifest>
        </jar>
    </target>
</project>

"The basic idea (to give you some
things to search for) is:

Bundle your compiled .class files into
a 'jar'. Add a manifest to your jar
specifying a main class to run. You
might find your IDE already creates
this when you run a 'clean build'.
Netbeans puts this into a 'dist'
folder." (by Cogsy)

Plus to achieve this you can either choose:

Depending on the IDE, some support
Export features that will create the
.jar executable for you. For example,
in Eclipse, you've got that option.
Plus there are additional plug-ins for
Eclipse, such as Fat-Jar, that will
include any additional libs you
include that aren't part of Sun's
standard libs. (by kchau)

Or if you going to to serious stuff, opt for a build script like Ant or Maven.
Here's an example of an Ant build.xml script:

<project name="jar with libs" default="compile and build" basedir=".">
    <!-- this is used at compile time -->
    <path id="example-classpath">
        <pathelement location="${root-dir}" />
        <fileset dir="D:/LIC/xalan-j_2_7_1" includes="*.jar" />
    </path>

    <target name="compile and build">
        <!-- deletes previously created jar -->
        <delete file="test.jar" />

        <!-- compile your code and drop .class into "bin" directory -->
        <javac srcdir="${basedir}" destdir="bin" debug="true" deprecation="on">
            <!-- this is telling the compiler where are the dependencies -->
            <classpath refid="example-classpath" />
        </javac>

        <!-- copy the JARs that you need to "bin" directory  -->
        <copy todir="bin">
            <fileset dir="D:/LIC/xalan-j_2_7_1" includes="*.jar" />
        </copy>

        <!-- creates your jar with the contents inside "bin" (now with your .class and .jar dependencies) -->
        <jar destfile="test.jar" basedir="bin" duplicate="preserve">
            <manifest>
                <!-- Who is building this jar? -->
                <attribute name="Built-By" value="${user.name}" />
                <!-- Information about the program itself -->
                <attribute name="Implementation-Vendor" value="ACME inc." />
                <attribute name="Implementation-Title" value="GreatProduct" />
                <attribute name="Implementation-Version" value="1.0.0beta2" />
                <!-- this tells which class should run when executing your jar -->
                <attribute name="Main-class" value="ApplyXPath" />
            </manifest>
        </jar>
    </target>
</project>
说不完的你爱 2024-07-19 05:52:31

只需退出 IDE 并熟悉命令行工具即可。 java 教程 有关于该主题的线索 此处(选择 Windows 或 Solaris/Linux 部分)。

Just get out of the IDE and familiarise yourself with the command line tools. The java tutorial has a trail on the subject here (pick the Windows or Solaris/Linux section).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文