0

How can I make a JAR file if project packaging type is "POM". The reason is that I have couple of sub-modules which added in this project. I'm using shaded plug-ins to make a JAR file but looks its not getting created in .m2 directory, but it creates in target folder which doesn't have any Classes, resources etc

Pom.xml

<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>HealthProject</groupId>
  <artifactId>HealthProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <excludes>
                  <exclude>classworlds:classworlds</exclude>
                  <exclude>junit:junit</exclude>
                  <exclude>jmock:*</exclude>
                  <exclude>*:xml-apis</exclude>
                  <exclude>org.apache.maven:lib:tests</exclude>
                  <exclude>log4j:log4j:jar:</exclude>
                </excludes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
    <modules>
        <module>database</module>
         <module>services</module>
    </modules>
</project> 
user1030128
  • 411
  • 9
  • 23
  • Why do you want the shaded jar file in your maven repository? – SubOptimal May 04 '16 at 10:30
  • I want to include HealthProject JAR as dependency in other roject. Actually i have two separate projects so just trying to add HealthProject project as JAR in Parent project . But the problem is HealthProject is POM project since it has some modules. – user1030128 May 04 '16 at 10:37

1 Answers1

1

I would see following solutions.

Either you add to the other project the modules it depend on.

<dependency>
    <groupId>HealthProject</groupId>
    <artifactId>database</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>HealthProject</groupId>
    <artifactId>services</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

or you create in HealthProject a new module which will create a Jar of HealthProject.

<parent>
    <groupId>HealthProject</groupId>
    <artifactId>HealthProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>healthproject-all</artifactId>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>HealthProject</groupId>
        <artifactId>database</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>HealthProject</groupId>
        <artifactId>services</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

and then in the other project you add this as dependency.

<dependencies>
    <dependency>
        <groupId>HealthProject</groupId>
        <artifactId>healthproject-all</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>pom</type>
    </dependency>
</dependencies>
SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • Looks like second approach will sort out my problem. Just wondering, do i need make any UBAR jar while making these modules (health-all)? I create one of the jar by following your suggestion but those jar looks empty. – user1030128 May 04 '16 at 12:24
  • @user1030128 Depending on your other settings it would make sense to move the `maven-shade-plugin` related part into the `healthproject-all`. Otherwise you would need more or less to duplicate the same configuration. – SubOptimal May 04 '16 at 12:49
  • Do you have any idea/code snippet how can i apply shade plugin in healthproject-all? i tried earlier but it wasn't a good jar – user1030128 May 04 '16 at 12:51
  • @user1030128 The configuration in your current `pom.xml` from `HealthProject` should work. – SubOptimal May 04 '16 at 13:22