[英]How to include, downloaded jar from plugin wget as dependency in Maven project
I have a Jar in a remote location. 我在远程位置有一个Jar。 I can download it to my src/lib using com.googlecode.maven-download-plugin. 我可以使用com.googlecode.maven-download-plugin将其下载到src / lib中。 I want to use this jar in my code as a dependency to resolve compile error. 我想在我的代码中使用此jar作为依赖项来解决编译错误。
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://remoteMachine/file/hello.zip</url>
<unpack>true</unpack><outputDirectory>${project.build.directory}/../src/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You can create a repo pointing to your jar 您可以创建一个指向您的罐子的仓库
<repository>
<id>cool project</id>
<name>My cool repo</name>
<url>file://${dirWithProject}/libs</url>
</repository>
Then just add the dependency 然后只需添加依赖项
<dependency>
<groupId>yourGroupUd</groupId>
<artifactId>your-artifact-id</artifactId>
<version>0.0.1</version>
</dependency>
Another way is using mvn install:install-file
另一种方法是使用mvn install:install-file
Or add the dependency like this 或像这样添加依赖项
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ldapjdk</groupId>
<artifactId>ldapjdk</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath>
</dependency>
</dependencies>
source http://www.tutorialspoint.com/maven/maven_external_dependencies.htm 来源http://www.tutorialspoint.com/maven/maven_external_dependencies.htm
最好的方法是使用maven install
指向存储在文件系统上的jar,并在pom中将其用作常规依赖项。
What you are currently attempting to do is against the Maven conventions. 您当前正在尝试违反Maven约定。 If you use custom plugins to randomly unpack ZIPs you will most likely break some of the Maven features eg parallel execution with -T
flag. 如果您使用自定义插件随机解压缩ZIP,则很有可能会破坏某些Maven功能,例如带有-T
标志的并行执行。 Worst, by going against conventions you make your build harder to understand and loose the biggest benefit of Maven, convention over configuration . 最糟糕的是,通过违反约定,您将使您的构建更难以理解,并且失去了Maven的最大好处, 约定优于配置 。
Convert your ZIP into a proper Maven dependency and use standard dependency resolution mechanism, <dependency>
section in pom.xml
. 将您的ZIP转换为适当的Maven依赖项,并使用标准的依赖项解析机制pom.xml
<dependency>
部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.