Maven:以下pom.xml文件为空的jar提供了什么? [英] Maven: What does the following pom.xml file gives empty jar?

查看:129
本文介绍了Maven:以下pom.xml文件为空的jar提供了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下pom.xml文件:

I wrote the following pom.xml file:

<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>
    <parent>
        <groupId>com.earnix.eo</groupId>
        <artifactId>EOParent</artifactId>
        <version>8.8.4.0-SNAPSHOT</version>
        <relativePath>../EOParent/pom.xml</relativePath>
    </parent>
    <artifactId>PricingBatch</artifactId>
    <name>PricingBatch</name>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>com.earnix.eo</groupId>
        <artifactId>Tools</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.earnix.eo</groupId>
        <artifactId>EarnixShared</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.earnix.eo</groupId>
        <artifactId>EOGUI</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.earnix.eo</groupId>
        <artifactId>EOSessions</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.earnix.eo</groupId>
        <artifactId>EOUtils</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sample</groupId>
        <artifactId>sample1</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>C:\ibm\WebSphere\AppServer\lib\bootstrap.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.sample</groupId>
        <artifactId>sample2</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>C:\ibm\WebSphere\AppServer\runtimes\com.ibm.ws.webservices.thinclient_8.5.0.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.sample</groupId>
        <artifactId>sample3</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>C:\ibm\WebSphere\AppServer\java\jre\lib\xml.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.sample</groupId>
        <artifactId>sample4</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>C:\ibm\WebSphere\AppServer\java\jre\lib\ibmorb.jar</systemPath>
    </dependency>
</dependencies>

<build>
    <finalName>PricingBatch</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.earnix.tools.batchpricing.Main</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>EOSessions.jar EOUtils.jar EOSessions.jar EOGUI.jar EarnixShared.jar bootstrap.jar ibmorb.jar xml.jar com.ibm.ws.webservices.thinclient_8.5.0.jar</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

我的目的是建立一个jar文件,该文件的主要类为com.earnix.tools.batchpricing.Main.如您所见,我有很多依赖项.四个依赖项是不属于Maven工件的jar文件:C:\ ibm \ WebSphere \ AppServer \ runtimes \ com.ibm.ws.webservices.thinclient_8.5.0.jar,C:\ ibm \ WebSphere \ AppServer \ lib \ bootstrap .jar,
C:\ ibm \ WebSphere \ AppServer \ java \ jre \ lib \ xml.jar, C:\ ibm \ WebSphere \ AppServer \ java \ jre \ lib \ ibmorb.jar

My purpose is the build a jar file which main class will be com.earnix.tools.batchpricing.Main. As you can see I have a number of dependencies. Four dependencies are jar files that are not part of maven artifactory: C:\ibm\WebSphere\AppServer\runtimes\com.ibm.ws.webservices.thinclient_8.5.0.jar,C:\ibm\WebSphere\AppServer\lib\bootstrap.jar,
C:\ibm\WebSphere\AppServer\java\jre\lib\xml.jar, C:\ibm\WebSphere\AppServer\java\jre\lib\ibmorb.jar

当我运行"mvn install"时,在目标文件夹中得到一个空的jar文件.我使用jd-gui,看到的是:

When I run "mvn install" I get an empty jar file in target folder. I use jd-gui, and I see this:

我看不到com.earnix.tools.batchpricing.Main类.

I don't see the class com.earnix.tools.batchpricing.Main.

如何使Maven创建所需的jar文件?

What can I do to make Maven create the jar file I want?

推荐答案

我在您的pom.xml中看到了这种依赖关系

I see this dependency in your pom.xml

<dependency>
    <groupId>com.earnix.eo</groupId>
    <artifactId>Tools</artifactId>
    <version>${project.version}</version>
    <scope>compile</scope>
</dependency>

因此,如果您希望在该模块中使用主类com.earnix.tools.batchpricing.Main,则最好从该模块中构建可执行jar.

So if your desired main class com.earnix.tools.batchpricing.Main in that module you'd better build executable jar from that module.

或者您可以要求Maven将所有依赖项解压缩到生成的jar中

Or you could ask Maven to unpack all dependencies into your resulting jar

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>fully.qualified.MainClass</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <appendAssemblyId>false</appendAssemblyId>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id> <!-- this is used for inheritance merges -->
      <phase>package</phase> <!-- bind to the packaging phase -->
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>

您可以查看此问题以获取更多详细信息:

You could check this question for more details: How can I create an executable JAR with dependencies using Maven?

这篇关于Maven:以下pom.xml文件为空的jar提供了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆