java - maven:没有主要清单属性
问题描述
我正在开发我的 web java 项目。当我尝试运行由 maven 构建的 java jar 文件时,出现错误:
no main manifest attribute, in "project name".
我认为原因是 maven 找不到我的主要课程。我创建了具有此层次结构的测试项目:
/test
/src
/main
Main.java
pom.xml
pom.xml 文件包含以下内容:
<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>FirstProject</groupId>
<artifactId>FirstProject</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugin</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<outputDirectory>${basedir}</outputDirectory>
<finalName>server</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
在测试项目中也会出现此错误。我试图用谷歌搜索它,每个人都建议添加 pom.xml,但我已经这样做了......(在我的情况下,这不是一个解决方案)。我怎么解决这个问题?
解决方案
阴影插件更容易使用:
<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>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>main.Main</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
推荐阅读
- javascript - 正则表达式 - 在给定数量的 3 个字母序列之后,如何匹配特定的 3 个字母序列?
- gradle - gradle buildscript“name”变量解析不起作用
- node.js - 在aws pinpoint(NodeJS)中,当用户触发客户事件时如何触发电子邮件
- ruby-on-rails - Rails 应用程序的每个请求的入口点是什么?
- python-3.x - 发送带有cookie的post请求时遇到问题----urllib.error.HTTPError: HTTP Error 503: Service Unavailable
- c++ - 编译cpp代码时出错:collect2:错误:ld返回1退出状态
- r - R如何将结果以一种方式绘制
- julia - 鉴于 Zygote 不支持突变,Recur 如何摆脱它?
- testing - 赛普拉斯导入规范文件
- linux - Linux命令行中的cat > filename和cat >> filename有什么区别