简体   繁体   English

如何包含从插件wget下载的jar作为Maven项目中的依赖项

[英]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.

相关问题 如何将外部jar依赖项包含到Maven项目中? - How to include external jar dependency to maven project? 如何使用Maven包插件在OSGi包中包含一罐依赖项? - How to include a jar of dependency in an OSGi bundle using maven bundle plugin? 版本更新后未在Maven存储库中下载项目依赖项jar - Project dependency jar not downloaded in maven repository after version updation 如何使用maven程序集插件从依赖jar中排除一个包? - How to use maven assembly plugin to exclude a package from dependency jar? 如何在Maven中包含远程jar依赖项 - How to include remote jar dependency in Maven maven-eclipse-plugin:如何强制使用jar依赖项而不是项目依赖项 - maven-eclipse-plugin: how to force to use a jar dependency rather than project dependency 使用maven依赖插件包含另一个jar的全部内容 - Include the whole content of another jar with maven dependency plugin 如何从依赖项目 maven 中包含 .class 文件? - How to include .class files from dependency project maven? 如何将FMPP作为Maven依赖项而不是作为插件包含 - How to include FMPP as a maven dependency not as a plugin 如何将本地jar添加为maven项目的依赖项? - how to add a local jar as a dependency to a maven project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM