0

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

Let's say this is my 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>

    <properties>
        <websphere.folder>C:\ibm\WebSphere\AppServer</websphere.folder>
    </properties>

    <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>${websphere.folder}\lib\bootstrap.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.sample</groupId>
            <artifactId>sample2</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${websphere.folder}\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>${websphere.folder}\java\jre\lib\xml.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.sample</groupId>
            <artifactId>sample4</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${websphere.folder}\java\jre\lib\ibmorb.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
        <finalName>PricingBatch</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.earnix.tools.batchpricing.Main</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>
        </plugins>
    </build>

</project>

As you can see it has 9 dependencies. Since I used maven-assembly-plugin I expect that all dependencies will be packed inside the output jar (named PricingBatch.jar). However, when I run the output jar, it cannot run if I don't mention 3 of the 9 dependencies in the classpath.

I must run is as:

java -Xmx300M -classpath "C:\IBM\WebSphere\AppServer\runtimes\com.ibm.ws.webservices.thinclient_8.5.0.jar;"C:\Repositories\EO_Websphere\PricingBatch\target\PricingBatch.jar";C:\Repositories\EO_Websphere\EOGUI\target\EOGUI.jar" com.earnix.tools.batchpricing.Main %*

My question is why when I mention only the PricingBatch.jar in the classpath,

java -classpath PricingBatch.jar com.earnix.tools.batchpricing.Main -Xmx300M %*

I get an error?

CrazySynthax
  • 13,662
  • 34
  • 99
  • 183
  • 1
    you are not using maven-assembly-plugin but maven-jar-plugin. That's a different thing. Use maven-assembly-plugin with descriptionRef = jar-with-dependencies – Veselin Davidov Apr 24 '18 at 09:26
  • `I get an error` which error? Please post the full stacktrace if any, they're often full of relevant information – Aaron Apr 24 '18 at 09:26
  • Your assumption that maven adds all your dependencies into your jar is not correct. Instead all you tell maven is that for the different goals the dependencies must be loaded (e.g. compile / test). Yet, the resulting jar will not comprise your dependencies repackaged as long as you do not explicitly tell maven to do exactly that by building a full jar (see https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven ) – lwi Apr 24 '18 at 09:30
  • @Veselin Davidov, I mistakenly copied the wrong pom file. I just edited the post . – CrazySynthax Apr 24 '18 at 10:25

0 Answers0