0

I have a src folder out of which i need to create multiple jars. Like each package as a separate jar. Also i need to put specific xml files from src folder into specific jars. I created a pom which creates multiple jars successfully using multiple executions in plugin. But the problem is the movement of xml files to jars is not happening. Have provided the pom file below.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.1</version>
    <executions>
        <execution>
            <id>tra_common_id</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
                <finalName>tra_common</finalName>
                <encoding>ISO-8859-1</encoding>
                <classifier>tra_common</classifier>
                <includes>
                    <include>com/**/common/**</include>
                    <include>com/**/apm/*Access*</include>                              
                </includes>
                <excludes>
                    <exclude>com/**/management/**</exclude>    
                </excludes>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </archive>                          
            </configuration>
        </execution>
        <execution>
            <id>tra_client_id</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
                <finalName>tra_client</finalName>
                <encoding>ISO-8859-1</encoding>
                <classifier>tra_client</classifier>
                <includes>
                    <include>com/**/client/**</include>                   
                </includes>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>
harimper
  • 1
  • 2
  • If you have to create multiple jar's you should create a multi module build which separates the appropriate classes to the location they belong to and then you have the separated jar files. If you need to add xml files you should locate them into `src/main/resources` – khmarbaise Mar 30 '19 at 10:03
  • You say that using multiple executions is a wrong approach?. Because i cant separate the src folder. i want to have one src folder only but generate different jars out of it. – harimper Mar 30 '19 at 10:20
  • First why can't you separate the src folder cause you want to generate different jars which is an indicator that your module/project has not the correct setup. Furthermore the convention is to have a single jar per pom file ...You can of course hack to get what you want...but that's usually not a good idea..The classifiers already show that the right approach is a multi module setup which has modules like `common`, `client` and so on. This would make it easier for the users of your modules and it follows the convention over configuration paradigm. – khmarbaise Mar 30 '19 at 13:27
  • Thanks for your feedback. That sure helps my understanding. – harimper Apr 02 '19 at 13:45

0 Answers0