maven - 生产jar作为依赖项添加到其他项目时如何指定自己的依赖项?

标签 maven netbeans maven-2 maven-3

如果问题标题不能说清楚,请带我在这里更详细地解释一下。假设我的一个 Maven 应用程序的生产 jar 需要用于我的另一个 Maven Web 应用程序。将该 jar 添加到我的第二个应用程序 Maven 依赖项不会添加其传递依赖项。另外,jar 本身就是一个应用程序。

一种方法是查看第一个应用程序的 POM,并将其添加到另一个应用程序的 POM 中。但是,中央 Maven jar 在添加到某个项目时如何添加自己的传递依赖项。

换句话说,如果我将 commons-io.jar Maven 依赖项添加到我的项目中,它会自动添加其传递依赖项。但是,当我添加 myjar.jar 作为 Maven 依赖项(范围->系统)时,它不会自动添加其传递依赖项。

我认为我应该将我的第一个应用程序开发为可以在这种情况下使用的其他原型(prototype)。请告诉我如何进一步进行。

很抱歉提出这个新手问题。实际上,我是 Maven 的新手,我已经开始使用 Netbeans-embedded-maven 来创建应用程序。我真的很喜欢 Maven 简化工作的方式。

已编辑

看来我应该更详细地解释一下。这就是它。

假设我编写了一个使用 A.jar、B.jar、C.jar 的程序/应用程序,并且我的生产输出是 X.jar(根据 Maven 默认构建,它显然不包含其他 jar)。上述 A、B、C jar 存在于 Maven 中央存储库中,并作为依赖项添加到我的项目中。项目构建jar是X.jar

现在我编写了另一个应用程序,其中添加了 X.jar 作为系统依赖项,现在我想要的是 A.jar、B.jar、C.jar 自动添加到项目中,因为它们是 X 的传递依赖项。 jar

希望这次我已经解释清楚了。如果您之前不明白,请原谅我的写作风格。

一种解决方案是使用类似的方法构建包含所有依赖项的 X.jar

 <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.nitinsurana.mlmmaven.Start</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-my-jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

但我正在寻找能够自动添加系统依赖项的传递依赖项的东西。

最佳答案

system scope不应该用于将与另一个应用程序打包的实际 jar 依赖项。引用官方文档:

Dependencies with the scope system are always available and are not looked up in repository. They are usually used to tell Maven about dependencies which are provided by the JDK or the VM. Thus, system dependencies are especially useful for resolving dependencies on artifacts which are now provided by the JDK, but where available as separate downloads earlier. Typical example are the JDBC standard extensions or the Java Authentication and Authorization Service (JAAS).

您应该使用默认的编译范围。

关于maven - 生产jar作为依赖项添加到其他项目时如何指定自己的依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14110898/

相关文章:

java - Tomcat 运行但在尝试访问我的 html 时给出 404,但在安装后显示 tomcat 的默认页面

java - 马文 2 : How to package current project version in a WAR file?

maven-2 - child 在平面结构的多模块 maven 构建中找不到父 pom

maven-2 - 无法通过 Nexus 代理到 Maven 仓库

gwt - 如何通过maven属性将属性设置到gwt.xml文件中?

java - 如何从maven插件使用的类路径中排除项目依赖

java - org.mortbay.http 包不存在。如何在 pom.xml 中为此添加依赖项

java - spring boot从2.1.4更新到2.1.5后java主类出现问题

java - Netbeans 应用程序中的 hibernate

java - 导入 org.postgresql.jdbc3.Jdbc3PoolingDataSource