当前位置: 首页 > 知识库问答 >
问题:

mvn清理包:无主清单属性[重复]

米夕
2023-03-14

当项目从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$ 

显然,只需要为清单指定主类条目。

只需关注软件包阶段:

运行Maven工具Maven阶段

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

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

共有1个答案

龚跃
2023-03-14

我明白了,这是使用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 
<?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

 类似资料:
  • 当运行我的jar文件:java-jar target/places-1.0-snapshot.jar时,我得到了下一个错误: 我的pom.xml包含spring-boot-maven-plugin: 知道我还能试试什么吗?

  • 首先,我看了关于这个话题的类似问题。我还没有找到解决办法。 我想把我一直在做的一个小项目分发给朋友和家人。问题是我不能指望他们都能跑。类文件。因此,我正在努力创造一个新的世界。jar文件,我可以将其转换为。exe文件。然而,我遇到了一个问题。它抱怨缺少主清单属性。在谷歌搜索之后,我决定尝试一个小教程。我正在遵循教程(甚至下载了Hello.jar小文件),但仍然没有获得主清单属性。 当我运行Wind

  • 我正在用Gradle构建一个JAR文件。当我尝试运行它时,我得到了错误 RxJavaD中没有主清单属性emo.jar 我试图操纵清单属性,但我想我忘记向它添加依赖项或其他东西了。我到底做错了什么?

  • 问题内容: 我最近刚开始在Java中玩Maven。是时候测试我的项目了,它在NetBeans窗口中运行正常,运行在App.java(com.MyCompany.App)中找到的主类,但是当我尝试从命令行运行它时,出现了一个错误: fileName.jar中的“无主要清单属性” 我尝试添加一个manifest.mf文件来指定主要文件,我也进入了项目属性并将其添加为主文件… 这是怎么回事? 问题答案:

  • 当我在ubuntu(maven version 2)上运行mvn clean package时,我得到一个错误,说丢失了9个JAR,而且存储库中似乎也没有这些JAR。我如何解决这个问题? `1)com.sleepycat:sleepycat_je:jar:2.1.30 尝试从项目网站手动下载文件。 然后,使用命令mvn install:install-file-dgroupid=com.sleep

  • 问题内容: 运行基于Gradle构建的JAR文件时遇到的错误让我有点发疯。错误显示为“ RxJavaDemo.jar中没有主清单属性”,我尝试操纵Manifest属性,但我想我忘记在其中添加依赖项或其他内容。我到底在做什么错? 问题答案: 尝试更改清单属性,例如: 然后只需更改为(您的Main类具有main方法)。在这种情况下,您可以在清单中创建一个指向此类的属性,然后运行一个jar。