Question

I have a project(A) in maven that has packaging of war. One other project(B) depends on A and it needs project A jar file but in phase of compile, the war of project A will produce and no jar is available for project B. How can I create a jar of project A in phase of compile so that project B can use it?

Was it helpful?

Solution 2

I found the solution : :)

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
            <execution>
                <id>make-a-jar</id>
                <phase>compile</phase>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <executions>
            <execution>
                <phase>install</phase>
                <goals>
                    <goal>install-file</goal>
                </goals>
                <configuration>
                    <packaging>jar</packaging>
                    <artifactId>${project.artifactId}</artifactId>
                    <groupId>${project.groupId}</groupId>
                    <version>${project.version}</version>
                    <file>
                        ${project.build.directory}/${project.artifactId}-${project.version}.jar
                    </file>
                </configuration>
            </execution>
        </executions>
    </plugin>

OTHER TIPS

I would suggest to go a different way and use the maven-war-plugin which can produce a separate artifact for the classes which can be used like the following:

<dependency>
  <groupId>myGroup</groupId>
  <artifactId>myArtifact</artifactId>
  <version>myVersion</myVersion>
  <classifier>classes</classifier>
</dependency>

This can be achieved by using the following configuration in your war module:

 <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <attachClasses>true</attachClasses>
      </configuration>
    </plugin>
    ...
  </plugins>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top