如何为具有多个包和库的项目生成可执行的.jar 文件?

发布于 2025-01-02 00:07:02 字数 116 浏览 5 评论 0原文

我参与创建了一个项目,该项目包含大约 60 个包和 150 多个类以及一些外部库。我如何将这些东西打包到一个可执行的 jar 文件中,以便我可以将其作为应用程序运行。谁能提供详细步骤。

提前感谢回复者。

I am involved in creating a project which has around 60 packages and more than 150 classes and also some external libraries. How can i package these things in to a single executable jar file, so that i can run it as an application. can anyone please provide the detailed steps.

Thanks to the replier in advance.

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

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

发布评论

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

评论(4

影子是时光的心 2025-01-09 00:07:02

在 Eclipse 中选择“导出为可运行 JAR”。

如果您希望将所有内容都保存在一个文件中,请选择“将库提取到 JAR 中”。

In Eclipse choose 'Export as Runnable JAR'.

If you want it all in one file, choose 'extract libraries into JAR'.

别低头,皇冠会掉 2025-01-09 00:07:02

我强烈建议你将其mavenize。从长远来看,使用 Apache Maven 会对您的项目描述有很大帮助。

I would strongly recommend you to mavenize it. Using Apache Maven will help you a lot in the long run with the project describe.

遇到 2025-01-09 00:07:02

如果您使用的是 Netbeans,请右键单击您的项目,然后单击“清理并构建”。这将在项目的根目录中创建一个名为 dist 的文件夹。该文件夹包含 jar 文件。

If you are using Netbeans, right-click on your project, click on Clean and Build. This will create a folder named dist in your project's root directory. That folder contains the jar file.

踏雪无痕 2025-01-09 00:07:02

您可以使用 maven 构建项目并使用 maven- 生成包含所有依赖项的 jar阴影插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <finalName>my-executable</finalName>
        <shadedArtifactAttached>true</shadedArtifactAttached>
        <shadedClassifierName>shaded</shadedClassifierName>
        <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <!-- Main class -->
                <mainClass>com.worklight.my.cli.MainClassName
                </mainClass>
            </transformer>
        </transformers>
    </configuration>
</plugin>

You can use maven to build your project and generate a jar with all of the dependencies with maven-shade-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <finalName>my-executable</finalName>
        <shadedArtifactAttached>true</shadedArtifactAttached>
        <shadedClassifierName>shaded</shadedClassifierName>
        <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <!-- Main class -->
                <mainClass>com.worklight.my.cli.MainClassName
                </mainClass>
            </transformer>
        </transformers>
    </configuration>
</plugin>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文