【问题标题】:Attaching only a contents of the folder to the jar仅将文件夹的内容附加到 jar
【发布时间】:2014-06-07 11:06:18
【问题描述】:

我正在使用maven-jar-plugin 来生成源jar。

我有以下文件夹结构:

folder/foo/baz/A.java
folder/bar/baz/B.java

我希望源 jar 包含以下内容:

baz/A.java
baz/B.java

我正在使用以下配置:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
        <executions>
            <execution>
                <phase>generate-resources</phase>
                <goals>
                    <goal>jar</goal>
                </goals>
                <configuration>
                    <classesDirectory>folder</classesDirectory>
                    <includes>
                        <include>foo/**</include>
                        <include>bar/**</include>
                    </includes>
                    <finalName>sources</finalName>
                </configuration>
            </execution>
        </executions>
</plugin>

但这会像这样创建 jar:

folder/foo/baz/A.java
folder/bar/baz/B.java

如何修改代码以在 jar 中获得所需的结构?

【问题讨论】:

    标签: maven version-control jar maven-3 maven-jar-plugin


    【解决方案1】:

    我无法用maven-jar-plugin 解决这个问题,我也必须使用maven-resources-plugin

    <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
            <execution>
                <phase>generate-resources</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/sources/</outputDirectory>
                    <resources>
                        <resource>
                            <directory>folder/foo/</directory>
                        </resource>
                        <resource>
                            <directory>folder/bar/</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
    
    <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <executions>
            <execution>
                <phase>generate-resources</phase>
                <goals>
                    <goal>jar</goal>
                </goals>
                <configuration>
                    <classesDirectory>${project.build.directory}/sources</classesDirectory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <finalName>sources</finalName>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      相关资源
      最近更新 更多