【问题标题】:how can set both classpathPrefix and mainClass in pom?如何在 pom 中同时设置 classpathPrefix 和 mainClass?
【发布时间】:2015-10-28 01:21:11
【问题描述】:

我有这样的 pom.xml:

<plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                  <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>package.mainClass</mainClass>
                        <classpathPrefix>lib/</classpathPrefix>
                  </manifest>
                  </archive>
                </configuration>
              </plugin>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                <source>1.6</source>
                <target>1.6</target>
                </configuration>
              </plugin>
</plugins>

我编译并打包我的项目成功。但是当我java -jar myProject.jar 我得到Error: Could not find or load main class package.mainClass!!

我认为这是因为我在清单中同时写了 mainClassclasspathPrefix!在 pom.xml 中如何设置它们?

【问题讨论】:

  • classpathPrefix 适用于 dependencies 而不是项目二进制文件,并且可以与 mainClass 共存。你从哪里运行java - jar ... - 我假设target 文件夹?
  • 是的,正是目标文件夹!我必须从任何其他文件夹运行?
  • 你能在项目jar中打开MANIFEST.MF看看Main-Class是不是和你想运行的一样吗?
  • 是的,它有我的主课:Manifest-Version: 1.0 Built-By: soltanmohammadi Build-Jdk: 1.7.0_45 Class-Path: D:/9405/todayJob/lib/OperationMaker-1.0.jar D:/9405/todayJ ob/lib/slf4j-api-1.7.12.jar D:/9405/todayJob/lib/logback-classic-1.0. 13.jar D:/9405/todayJob/lib/logback-core-1.0.13.jar Created-By: Apache Maven 3.0.5 Main-Class: first.PathGetter Archiver-Version: Plexus Archiver first.PathGetter 是我的主课

标签: maven manifest manifest.mf


【解决方案1】:

根据您的 MANIFEST.MF,在 pom.xml 文件中使用“Main-Class: first.PathGetter”而不是“Main-Class: package.mainClass”

【讨论】:

    猜你喜欢
    • 2016-04-30
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 2012-12-11
    • 2013-03-27
    • 2012-02-23
    相关资源
    最近更新 更多