【问题标题】:Create non-executable JAR from selected classes in IntelliJ从 IntelliJ 中的选定类创建不可执行的 JAR
【发布时间】:2014-03-24 00:04:10
【问题描述】:

在 Eclipse 中,有一个选项 Export -> JAR File。然后我们选择想要导出到输出jar的类。

我们如何在 IntelliJ 中做到这一点?

【问题讨论】:

  • 我遇到了同样的问题。我制作了一个没有主类的 solr 模块。我找不到在 inteliji 中导出它的方法。显示的所有方法都适用于可执行的 jar 文件。

标签: jar intellij-idea


【解决方案1】:

我不知道你是否需要这个答案,但我今天遇到了同样的问题,我想出了如何解决它。 请按照以下步骤操作:

  1. 文件 -> 项目结构(Ctrl + Alt + Shift + S);
  2. 转到“工件”菜单 -> 单击“+”按钮 -> JAR -> 从具有依赖项的模块...
  3. 选择要生成Jar文件的模块;
  4. 不要选择任何主类;
  5. 在 JAR files from libraries 菜单中,选择“extract to the target JAR”选项 -> 点击 Ok;
  6. 命名你的jar文件->选择输出目录->点击“应用”和“确定”;
  7. 完成这些步骤后,转到:构建 -> 构建工件...
  8. 将出现一个飞行菜单,其中包含您之前创建的工件;
  9. 点击构建就完成了。

希望这对您和遇到此问题的每个人都有帮助。 我浪费了一整天的时间尝试使用 FatJar 在 Eclipse 上生成 jar 文件,但我无法生成它。

【讨论】:

    【解决方案2】:

    您可以使用 Ant 来做到这一点。

    1. 创建您的 Ant 项目。
    2. 将 ant 文件拖放到 Ant Build 视图中。
    3. 执行任务以生成 .jar 文件。

    <?xml version="1.0" encoding="utf-8"?>
    <project name="CustomJar" default="dist" basedir=".">
        <description>
            Package clases selected package to jar.
        </description>
        <!-- set global properties for this build. **** The paths are relative to the ant file location *** -->
        <property name="src" location="../src/main/java/com/dto/myclasespackage"/>
        <property name="build" location="../build"/>
        <property name="dist" location="../dist/custom_jar"/>
        <property name="version" value="1.0"/>
    
        <target name="init">
            <!-- Create the time stamp -->
            <tstamp/>
            <!-- Create the build directory defined above -->
            <mkdir dir="${build}"/>
        </target>
    
        <target name="compile" depends="init" description="compile the source">
            <!-- Compile java code from ${src} into ${build} -->
            <javac srcdir="${src}" destdir="${build}"/>
        </target>
    
        <target name="dist" depends="compile" description="generate the distribution">
            <buildnumber/>
            <!-- Create the distribution directory -->
            <mkdir dir="${dist}/lib"/>
    
            <!-- Put everything in ${build} into the MyApplication-${version}.${build.number}.jar -->
            <jar destfile="${dist}/lib/desglose-reports-beans-${version}.${build.number}.jar" basedir="${build}"/>
        </target>
    
        <target name="clean" description="clean up">
            <!-- Delete the ${build} and ${dist} directories -->
            <delete dir="${build}"/>
            <delete dir="${dist}"/>
        </target>
    </project>
    

    【讨论】:

      猜你喜欢
      • 2014-07-26
      • 2013-06-06
      • 2017-11-14
      • 1970-01-01
      • 2016-02-09
      • 2023-02-08
      • 2016-09-29
      • 2014-10-05
      • 2019-09-28
      相关资源
      最近更新 更多