4

I need to create an executable jar file with my App class along with its dependencies and this is working ok, but it's also creating a second jar file with just the App class.

It outputs 2 jars with filenames: lchain-0.0.4-SNAPSHOT-jar-with-dependencies.jar lchain-0.0.4-SNAPSHOT.jar (contains just the App class)

I could just ignore the second file but I'd prefer to understand why it is happening and to create the first file only.

I'm using Eclipse 2018-12 with the latest .m2e plugin. I create the jar file(s) by running-as 'Maven install'. The App class contains the main method.

My POM is as follows:

<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.mato</groupId>
  <artifactId>lchain</artifactId>
  <version>0.0.3-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>lchain</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.web3j</groupId>
        <artifactId>core</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <version>1.7.5</version>
   </dependency>
  </dependencies>

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                            <manifest>
                                <mainClass>
                                    com.mato.lchain.App
                                </mainClass>
                            </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
tommccann
  • 133
  • 1
  • 10
  • 1
    The jar containing only the app files is created by the maven-jar-plugin. You can disable the execution of the default goal of that plugin, please see: https://stackoverflow.com/a/12814320 – danielorn Jan 06 '19 at 09:37
  • Thanks ever so much @danielorn. That did the trick. – tommccann Jan 06 '19 at 10:29

0 Answers0