Maven仅复制特定依赖项

问题描述 投票:0回答:1

我正在根据基于组件的软件工程,使用Maven开发OSGI电子邮件客户端。我必须确保在OSGI容器内解析了我所有组件之间的依赖关系,因此我无法在生成的JAR内复制依赖关系,否则使用OSGI将毫无意义。但是我确实必须在JAR内部复制一个依赖项,即javax.mail,因为我找不到任何与OSGI兼容的捆绑包,可以通过电子邮件发送。

为此,我已经看到此页面:https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html

所以我编辑了pom.xml

<project>
    ...
    <build>
        <plugins>
            <plugin> <!-- to edit the MANIFEST.MF, required for OSGI -->
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>4.2.1</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Class-Path>lib/</Class-Path>
                        ... OSGI instructions ...
                    </instructions>
                </configuration>
            </plugin>
            <plugin> <!-- to copy the dependencies -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.sun.mail</groupId>
                                    <artifactId>javax.mail</artifactId>
                                    <version>1.6.2</version>
                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    ...
</project>

但是<artifactItems>标签似乎无效。当我mvn install时,它将所有依赖项复制到dependency/文件夹而不是lib/文件夹中。如何只将javax.mail JAR复制到名为lib/的文件夹中?

谢谢您的帮助。

java maven components osgi dependency-management
1个回答
0
投票

您混合了目标copy-dependenciescopy。将copy-dependencies替换为copy

http://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html

© www.soinside.com 2019 - 2024. All rights reserved.