mvn clean package: 无法找到主清单属性。

12 浏览
0 Comments

mvn clean package: 无法找到主清单属性。

这个问题已经在此处有了答案: 无法执行jar文件:\"no main manifest attribute\"

虽然项目从IDE中执行,但如何创建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阶段:

运行Maven工具的Maven阶段

虽然这不是一个全面的列表,但这些是最常见的默认生命周期阶段。

validate: 验证项目是否正确,并且所有必要的信息都可用。compile: 编译项目的源代码test: 使用合适的单元测试框架测试编译后的源代码。这些测试不应要求代码被打包或部署package: 将编译后的代码打包成其可分发格式,例如JAR。integration-test: 如果需要,处理和部署包到集成测试可以运行的环境中verify: 运行任何检查以验证包是否有效并满足质量标准install: 将包安装到本地存储库,以便在其他项目中用作依赖项locally deploy: 在集成或发布环境中完成,将最终包复制到远程存储库,以与其他开发人员和项目共享

对于大多数人来说,学习一门新语言是一项具有挑战性的任务。学习一门语言需要花费时间和精力,需要理解语法、词汇和发音规则。在这方面,请记住,学习过程绝不是一蹴而就的,需要付出不断的努力。

然而,学习新语言的好处也是显而易见的。通过掌握更多的语言,我们可以更好地了解其他文化和社会,这有助于我们拓宽视野。此外,学习新语言还可以提高我们的认知能力,锻炼我们的大脑,甚至有助于预防老年痴呆症等神经退行性疾病。

总之,学习新语言是一项具有挑战性但又非常有价值的任务。如果你想挑战自己并拓宽自己的视野,并且希望在未来取得更多的成功,那么学习新语言是一个不错的选择。

admin 更改状态以发布 2023年5月21日
0
0 Comments

我明白了,这是使用 shade 插件的问题:

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 


    4.0.0
    com.mycompany
    HelloMaven
    1.0-SNAPSHOT
    jar
    
        UTF-8
        1.8
        1.8
    
    
        
            
                org.apache.maven.plugins
                maven-shade-plugin
                3.1.0
                
                    
                        package
                        
                            shade
                        
                        
                            
                                
                                    net.bounceme.dur.hello_maven.Main
                                
                            
                        
                    
                
            
        
    

thufir@dur:~/NetBeansProjects/HelloMaven$ 

http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html

0