简体   繁体   English

使用Maven目录结构生成包含Maven项目源代码的jar?

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

I have a web application that I build with Maven into a war. 我有一个Web应用程序,我用Maven构建了一个战争。 But I want to generate a JAR with the maven project with the correct maven directory structure. 但是我希望使用具有正确maven目录结构的maven项目生成JAR。 I tried this but it throws away the Maven directory structure (src/main/java, etc.). 我尝试了这个,但它抛弃了Maven目录结构(src / main / java等)。 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. 我的目标是将这个jar分发给其他人,这样他们就可以解压缩并运行mvn eclipse:eclipse并开始处理他们的新Web项目。

Why not using the existing descriptor of maven-assembly-plugin .. 为什么不使用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

Use the maven-assembly-plugin. 使用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: 这是你的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. 我没有测试过它,但它大致就是你应该设置它的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM