Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build maven jar from classes no java source

I want to build a maven jar artifact from classes. I don't have source files. These classes are originally in another artifact installed locally. I use maven-dependency-plugin to unpack the classes and put them in the target folder for this project/module.

It creates the jar.. but doesn't include the classes I just unpacked. Here's my pom:

<build>
... 

<!-- unpack myjar1.jar and myjar2.jar -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.company</groupId>
                                    <artifactId>myjar1</artifactId>
                                    <version>1.0</version>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>target/final</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.company</groupId>
                                    <artifactId>myjar2</artifactId>
                                    <version>1.0</version>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>target/final</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classesDirectory>/path/to/target/final/folder</classesDirectory>
                            <includes>
                                <include>**</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

</plugins>

</build>

How can I include these classes into my final.jar?

like image 747
Aravind Datta Avatar asked Mar 22 '23 03:03

Aravind Datta


1 Answers

I think the best solution is the maven-shade-plugin: create a pom.xml, add those 2 libraries as dependencies and configure the maven-shade-plugin. Run mvn package and you have your merged project.

like image 157
Robert Scholte Avatar answered Apr 25 '23 00:04

Robert Scholte