Build Maven jars from classes without Java sources

I want to build a maven jar artifact from the class I have no source files These classes were originally installed locally in another artifact I use Maven dependency plugin to extract classes and place them in the target folder of the project / module

It creates a jar But it doesn't include the class I just unzipped This is 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 to include these classes in final Jar?

Solution

I think the best solution is Maven shade plugin: create a POM XML, add the two libraries as dependencies and configure Maven - shade - plugin Run the MVN package and you have the merged project

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>