mvn clean package:没有主要清单属性[重复]
Posted
技术标签:
【中文标题】mvn clean package:没有主要清单属性[重复]【英文标题】:mvn clean package: no main manifest attribute [duplicate] 【发布时间】:2018-04-02 15:20:36 【问题描述】:虽然来自 IDE 的项目 executes,但如何创建 JAR
以便真正运行 hello world 类型的控制台应用程序?
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloMaven ---
[INFO] Deleting /home/thufir/NetBeansProjects/HelloMaven/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ HelloMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/thufir/NetBeansProjects/HelloMaven/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/thufir/NetBeansProjects/HelloMaven/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ HelloMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloMaven ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ HelloMaven ---
[INFO] Building jar: /home/thufir/NetBeansProjects/HelloMaven/target/HelloMaven-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.400 s
[INFO] Finished at: 2017-10-21T10:50:42-07:00
[INFO] Final Memory: 14M/47M
[INFO] ------------------------------------------------------------------------
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ tree
.
├── nbactions.xml
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── net
│ │ │ └── bounceme
│ │ │ └── dur
│ │ │ └── hello_maven
│ │ │ └── Main.java
│ │ └── resources
│ └── test
│ └── java
└── target
├── classes
│ └── net
│ └── bounceme
│ └── dur
│ └── hello_maven
│ └── Main.class
├── generated-sources
│ └── annotations
├── HelloMaven-1.0-SNAPSHOT.jar
├── maven-archiver
│ └── pom.properties
└── maven-status
└── maven-compiler-plugin
├── compile
│ └── default-compile
│ ├── createdFiles.lst
│ └── inputFiles.lst
└── testCompile
└── default-testCompile
└── inputFiles.lst
25 directories, 9 files
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ java -jar target/HelloMaven-1.0-SNAPSHOT.jar
no main manifest attribute, in target/HelloMaven-1.0-SNAPSHOT.jar
thufir@dur:~/NetBeansProjects/HelloMaven$
显然只需要为清单指定Main-Class
条目。
只关注package
phase:
运行 Maven 工具 Maven 阶段
虽然不是一个完整的列表,但这些是最常见的 执行的默认生命周期阶段。
validate:验证项目是否正确且所有必要 资料可用 compile:编译源代码 项目测试:使用合适的单元测试编译后的源代码 测试框架。这些测试不应该要求打包代码 或部署的包:获取编译后的代码并将其打包到它的 可分发的格式,例如 JAR。集成测试:过程和 如有必要,将包部署到集成环境中 可以运行测试 verify:运行任何检查以验证包是否有效 并符合质量标准安装:将包安装到本地 存储库,用作本地部署的其他项目中的依赖项: 在集成或发布环境中完成,复制最终 打包到远程存储库以与其他开发人员共享 项目
【问题讨论】:
Can't execute jar- file: "no main manifest attribute" 的可能重复项。或特定于 maven ***.com/questions/15990258/maven-cant-execute-jar 【参考方案1】:我明白了,这是使用阴影插件的问题:
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloMaven ---
[INFO] Deleting /home/thufir/NetBeansProjects/HelloMaven/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ HelloMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/thufir/NetBeansProjects/HelloMaven/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/thufir/NetBeansProjects/HelloMaven/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ HelloMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloMaven ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ HelloMaven ---
[INFO] Building jar: /home/thufir/NetBeansProjects/HelloMaven/target/HelloMaven-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:3.1.0:shade (default) @ HelloMaven ---
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /home/thufir/NetBeansProjects/HelloMaven/target/HelloMaven-1.0-SNAPSHOT.jar with /home/thufir/NetBeansProjects/HelloMaven/target/HelloMaven-1.0-SNAPSHOT-shaded.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.805 s
[INFO] Finished at: 2017-10-21T11:02:31-07:00
[INFO] Final Memory: 17M/56M
[INFO] ------------------------------------------------------------------------
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ java -jar target/HelloMaven-1.0-SNAPSHOT.jar
Oct 21, 2017 11:02:38 AM net.bounceme.dur.hello_maven.Main getGreeting
INFO: Hello world.
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ cat 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>com.mycompany</groupId>
<artifactId>HelloMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>net.bounceme.dur.hello_maven.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
thufir@dur:~/NetBeansProjects/HelloMaven$
http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html
【讨论】:
以上是关于mvn clean package:没有主要清单属性[重复]的主要内容,如果未能解决你的问题,请参考以下文章
mvn clean package install deploy
idea 使用 mvn clean package 报错 Could not create local repository at
Maven - 为啥在“mvn clean”之后我需要在“mvn package”之前执行“Maven Update Project”?
此环境中不提供编译器。执行 mvn clean package 时