CrazySynthax
CrazySynthax

Reputation: 14988

Maven: What does the following pom.xml file gives empty jar?

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>

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

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

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

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

Upvotes: 0

Views: 768

Answers (2)

Yuvaraj Ram
Yuvaraj Ram

Reputation: 67

Step1: First of all <project> end tag is missed from pom.xml. 

Step2: Maven compiler plugin is missed from pom.xml
After </dependency> close tag add the below compiler plug in. Change the Java Version according to your situation.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Upvotes: 0

Ivan
Ivan

Reputation: 8758

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>

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

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?

Upvotes: 1

Related Questions