【问题标题】:IntelliJ: Maven: Build Artifact to Jar but cant execute jarIntelliJ:Maven:将工件构建到 Jar 但无法执行 jar
【发布时间】:2016-09-01 23:19:50
【问题描述】:

我已经建立了一个mavens标准目录结构的项目:

应用程序: --> src -->main -->java -->com -->company -->appname -->//这里是classes

我在java目录下也有一个META-INF目录,里面有一个MANIFEST.MF:

 Manifest-Version: 1.0
 Main-Class: com.company.appname.MyMain

我的 maven pom.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0     http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dsds.cryptoapp</groupId>
<artifactId>Crytpo</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>com.jgoodies</groupId>
        <artifactId>jgoodies-forms</artifactId>
        <version>1.9.0</version>
    </dependency>
</dependencies>

如您所见,我将 JGoodiesLibrary 作为项目的依赖项导入。

到目前为止一切正常。

现在我通过 Maven 在 IntelliJ 中通过 clean --> compile --> package --> install 构建一个工件。

jar 已创建,但我的库不见了。 此外,当我通过 windows cmd 使用“java -jar myapp.jar”启动 jar 时,它说我的 mainmanifestattribute 丢失了,即使它在那里!

【问题讨论】:

    标签: java maven intellij-idea build artifact


    【解决方案1】:

    Jar 插件可以为你生成清单,我建议这样使用它:https://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make_The_Jar_Executable

    我猜你也必须将类路径添加到清单文件中:https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

    【讨论】:

    • 谢谢,可能是这个原因,我去试试
    【解决方案2】:

    您是否验证了未包含的库已添加到项目中的包中?你可以去Project Structure (Alt Ctrl Shift S),Artifacts in Output Layout,在最终包中添加你需要的库。

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 2021-05-15
      • 2017-07-25
      • 1970-01-01
      • 1970-01-01
      • 2013-04-06
      相关资源
      最近更新 更多