Generating a jar with the source code of the Maven project with the Maven directory structure?

旧街凉风 提交于 2019-12-23 19:42:06

问题


I have a web application that I build with Maven into a war. But I want to generate a JAR with the maven project with the correct maven directory structure. I tried this but it throws away the Maven directory structure (src/main/java, etc.). My goal is to distribute this jar to other people so they can unpack and run mvn eclipse:eclipse and start working on their new web project.


回答1:


Why not using the existing descriptor of maven-assembly-plugin..

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
  <descriptorRefs>
    <descriptorRef>src</descriptorRef>
  </descriptorRefs>
</configuratio



回答2:


Use the maven-assembly-plugin. It's pretty straight-forward to do what you want.

Here's your definition for the plugin:

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.2.1</version>
                    <executions>
                        <execution>
                            <id>make-distribution</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
                                </descriptors>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Here's your src/main/assembly/assembly.xml:

<assembly>

        <id>my-project</id>

        <formats>
                <format>zip</format>
        </formats>

        <includeBaseDirectory>true</includeBaseDirectory>

        <fileSets>
                <fileSet>
                        <directory>${basedir}</directory>
                        <includes>
                                <include>**/**</include>
                        </includes>
                        <excludes>
                                <exclude>**/**</exclude>
                        </excludes>
                </fileSet>
        </fileSets>

</assembly>

I haven't tested it, but it's roughly the way you should set it up.



来源:https://stackoverflow.com/questions/10263859/generating-a-jar-with-the-source-code-of-the-maven-project-with-the-maven-direct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!