-1

I'm trying to use maven-jar-plugin to produce both a war file and a jar file doing ./mvnw clean install.

My pom.xml contains:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-services-provided</id>
                    <phase>test</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <configuration>
                        <packaging>jar</packaging>
                        <groupId>${project.groupId}</groupId>
                        <version>${project.version}</version>
                        <file>${project.build.directory}\${project.artifactId}-${project.version}.jar</file>
                    </configuration>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I also tried with <phase>compile</phase>.

The jar-file is being created but is very small and does not even contain the application main class.

How can I achieve the same result as <packaging>jar</packaging> ? The war-file looks good it is bigger.

I did read Maven JAR Plugin 3.0.2 Error ...

Adder
  • 5,708
  • 1
  • 28
  • 56
  • 1
    Simply the wrong way. If you like to create a jar file use packaging jar and if your like to create a war file use packaging war instead. If you have a war project which should produce a war file and a jar file which contains the java code compiled use the configuration of maven-war-plugin .... – khmarbaise Feb 08 '19 at 15:39

1 Answers1

-1

If you like to create a separate jar file of the code in your war module the configuration should look like this:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
          <archiveClasses>true</archiveClasses>
          <attachClasses>true</attachClasses>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235