gpt4 book ai didi

java - target/xx.jar 中的 Maven : no main manifest attribute,,无法执行 jar 文件

转载 作者:行者123 更新时间:2023-11-30 05:43:37 25 4
gpt4 key购买 nike

这是 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>dl4j</groupId>
<artifactId>dl4j</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>example.JavaTestExample</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<!-- You need the below dependency to use CodecRecordReader-->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-data-codec</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<!-- <dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>${moduleName}-platform</artifactId>
<version>${moduleVersion}-1.4.4</version>
</dependency>-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<!-- You need the below dependency to use LocalTransformExecutor-->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-local</artifactId>
<version>1.0.0-beta3</version>
</dependency>
</dependencies>
<!-- Uncomment to use snapshot version -->
<!--<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy> &lt;!&ndash; Optional, update daily &ndash;&gt;
</snapshots>
</repository>
</repositories>-->
</project>

我想运行 maven-assemble-plugin 并创建一个 jar 文件,并添加所有依赖项。当我运行 java -jar jarfile.jar 时,出现以下错误:

target/jarfile.jar 中没有主要 list 属性

我浏览了几篇 Stack Overflow 帖子,并尝试了所有排列和组合。我尝试添加 assembleshade 插件。您可以在上面的 pom.xml 中看到我的设置。即使我添加了正确的 Maven 设置,我也不太确定这是如何发生的。

我验证 Java 运行正常:

enter image description here

我验证了我是否正确指定了主类。

对我来说一切看起来都很好,除了结果之外,我现在很困惑。

可能出了什么问题?我希望他们中的一些人仍然将问题标记为“重复”,但我一直在阅读其他帖子并尝试相应地更改设置。它们都不起作用。

最佳答案

高质量的问题!

我认为这将有助于实现您的目标。

我用它来构建一个可点击的 JavaFX Jar,其中包含所有依赖项。这是使用 maven-jar-pluginmaven-shade-plugin 而不是 maven-assemble-pluginHere is a good resource on the differences.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
<plugin>
<!-- I think you don't need this one -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
${mainClass}
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

关于java - target/xx.jar 中的 Maven : no main manifest attribute,,无法执行 jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55227729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com