如何在intelliJ或eclipse中创建包含所有类和字节代码的JAR文件? [英] How to create a JAR file with all classes and byte code in intelliJ or eclipse?

查看:211
本文介绍了如何在intelliJ或eclipse中创建包含所有类和字节代码的JAR文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是java的新手,目前正在做一个java项目。这是关于如何提交项目的说明。有谁能告诉我如何在intelliJ或eclipse中做到这一点?

I am new to java and currently doing a java project. This is the instruction on how to submit the project. Could anyone tell me how to do this in either intelliJ or eclipse?

请提交Java Archive(包含您编写的所有Java类的jar文件)。你的jar文件应该是
包含:
a)包含所有类的源代码
b)包含所有类的可执行文件(字节代码)

Please submit a Java Archive (jar file containing all java classes you have written). Your jar file should contain: a) Contain source code for all classes b) Contain executable (byte code) for all classes

推荐答案

如果你使用eclipse,你可以按照你的要求采用以下方式之一。

If you you are using eclipse you can follow one of the below ways as per your requirements.

要导出项目您正在以罐子形式工作:

1)右键单击您正在运行的项目>从上下文菜单中选择导出

1) Right Click on the project you are working > Select Export from context menu.

2)选择Java> JAR文件

2) Select Java > JAR File

3)选择要导出为JAR的项目。输入生成jar文件的名称,然后单击完成。

3) Select the project to export as JAR. Enter the name for the generating jar file and then click on finish.

如果您正在使用Maven,请对pom.xml执行以下配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4.1</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>com.xxxxx.xxxxx</mainClass>
            </manifest>
        </archive>
        <outputDirectory>C:\tmp</outputDirectory>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.0.1</version>    
    <configuration>
        <outputDirectory>C:\tmp</outputDirectory>
    </configuration>    
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

这篇关于如何在intelliJ或eclipse中创建包含所有类和字节代码的JAR文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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