java 使用 Maven 只是为了获取一些库 jars
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4568633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use Maven just to fetch some library jars
提问by Mot
We are using ANT for our build process and don't have plans to change this in the near future.
我们正在将 ANT 用于我们的构建过程,并且没有计划在不久的将来改变它。
Is it possible to use Maven to just fetchcommon Open Source jar files (e.g. Log4J, SWT, JFace) and put them in the right location of our project, so we don't have to store them in our version control — preferable without creating the typical Maven-cache in the home directory?
是否可以使用 Maven 来获取常见的开源 jar 文件(例如 Log4J、SWT、JFace)并将它们放在我们项目的正确位置,这样我们就不必将它们存储在我们的版本控制中——最好不创建主目录中的典型 Maven 缓存?
回答by David W.
NO NO NOEveryone!
NO NO NO大家!
If you're using Ant, the best way to use Maven repositories to download jar dependencies is to use Ivywith Ant. That's exactly what Ivy is for.
如果您使用的是 Ant,则使用 Maven 存储库下载 jar 依赖项的最佳方法是将Ivy与 Ant一起使用。这正是 Ivy 的用途。
Installing Ivy and getting to work with current Ant projects is simple to do. It works with Nexus and Artifactory if you use those as your local Maven repositories.
安装 Ivy 并开始使用当前的 Ant 项目很简单。如果您将它们用作本地 Maven 存储库,它可以与 Nexus 和 Artifactory 一起使用。
Take a look at Ivy. It is probably exactly what you want.
看看常春藤。这可能正是您想要的。
回答by Sean Patrick Floyd
In variation of org.life.java's answer, I would not do mvn install
.
在org.life.java's answer 的变体中,我不会这样做mvn install
。
Instead, in the pom.xml I would add the following bit:
相反,在 pom.xml 中,我会添加以下内容:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Now you just need to do mvn generate-sources
, which is a lot faster than the full mvn install
, and all dependencies will be copied to the specified directory.
现在你只需要做mvn generate-sources
,比full快很多mvn install
,所有的依赖都会复制到指定目录下。
Oh btw, isn't that what Apache Ivyis about? Extending Ant to understand Maven's dependency management?
哦顺便说一句,这不是Apache Ivy的内容吗?扩展 Ant 以了解 Maven 的依赖管理?
回答by Alexander Pogrebnyak
It's possible, you should use maven-ant-tasks.
有可能,您应该使用maven-ant-tasks。
In particular its dependencies
ant task. With this setup no Maven install is required.
特别是它的dependencies
蚂蚁任务。有了这个设置,不需要 Maven 安装。
<?xml version="1.0" encoding="UTF-8"?>
<project
name="download-dependency"
basedir="."
default="download-dependency"
xmlns:artifact="antlib:org.apache.maven.artifact.ant"
>
<target name="download-dependency">
... define properties ...
<taskdef
resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
/>
<artifact:dependencies>
<localRepository path="${local-repo.dir}"/>
<remoteRepository id="central" url="${repository-uri}"/>
<dependency
groupId="${groupId}"
artifactId="${artifactId}"
version="${version}"
type="${type}"
classifier="${classifier}"
scope="runtime"
/>
</artifact:dependencies>
</target>
</project>
The only binary you should check into your project is maven-ant-tasks.jar
.
您应该检入项目的唯一二进制文件是maven-ant-tasks.jar
.
Actually in our project I used Sonatype Nexus( documentation) Maven repository manager to centralize access to different repositories and even maintain some binaries unique to our environment. With Nexus' help I just fetch maven-ant-tasks.jar
with ant's <get>
task from a known URL. You don't have to use Nexus, but it greatly speeds up builds, because it caches binaries close to your developer's machines.
实际上,在我们的项目中,我使用了Sonatype Nexus(文档)Maven 存储库管理器来集中访问不同的存储库,甚至维护一些我们环境独有的二进制文件。在 Nexus 的帮助下,我只需从已知 URL 中获取maven-ant-tasks.jar
蚂蚁的<get>
任务。您不必使用 Nexus,但它极大地加快了构建速度,因为它将二进制文件缓存在靠近开发人员机器的地方。
回答by user77115
Ivy does just this,
when it bootstraps itself:
http://ant.apache.org/ivy/history/latest-milestone/samples/build.xml
当 Ivy 自我引导时,它就是这样做的:http:
//ant.apache.org/ivy/history/latest-milestone/samples/build.xml
<property name="ivy.install.version" value="2.0.0-beta1"/>
<property name="ivy.jar.dir" value="lib"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<target name="resolve" unless="skip.download">
<mkdir dir="${ivy.jar.dir}"/>
<echo message="installing ivy..."/>
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
</target>