0

在我的项目中,我使用的是 maven,因为我在我的项目 pom.xml 中添加了第三方库依赖项

<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>support-v4</artifactId>
    <version>r6</version>
</dependency>

现在所以这个 jar 在编译时出现在我的本地仓库中,我可以在 maven 依赖项中看到。现在我想制作一个超级 jar,其中包括三个 jar 文件,两个在我的 eclipse 工作空间中,一个在本地 repo 中。所以我可以使用下面的代码包含两个文件

<property name="First.jar" value="${basedir}/../Some/bin/SomeFirst-${project.version}.jar" />
<available file="${First.jar}" type="file" property="First-found" />
<fail unless="First-found" message="ERROR: failed to find First.jar, looked here: ${First.jar}" />

<!-- verify second.jar is available -->
<property name="second.jar" value="${basedir}/bin/some-project-name-${project.version}.jar" />
<available file="${second.jar}" type="file" property="second-found" />
<fail unless="second-found" message="ERROR: failed to find second.jar, looked here: ${second.jar}" />



<!-- glue all jars together into a super jar -->
<zip destfile="${super.jar}">
    <zipfileset src="${Second.jar}" />
    <zipfileset src="${First.jar}" excludes="META-INF/*,connectors/*" />
    <zipfileset src="Need third file relative path here " excludes="META-INF/*" />
</zip>

我可以使用完整路径,例如:

<zipfileset src="C:/Users/xxx/.m2/repository/com/google/android/support-v4/r7/support-v4-r7.jar"  /> 

但我确信这不适用于其他系统。 那么我如何将 support-v4-r7.jar 从本地 repo 相对引用到 Pom.xml。

4

3 回答 3

1

在 Maven 中创建“uber JAR”的简单方法是使用Maven “shade”插件。这将生成一个包含所有依赖 JAR 的“内容”的 JAR。有多种选项可用于重新组织内容和排除事物。插件文档应该足以让您入门。

可以通过 Mavan Ant 插件来做到这一点(正如你似乎正在做的那样),但这不是一个好的解决方案。首先,如果/当您更改依赖项时,您的构建可能会中断。

于 2013-06-24T12:21:18.100 回答
0

You can define a local repository for your Maven by setting

 <localRepository>D:/Maven/LocalRepo</localRepository>   

in

  config/settings.xml 

when you build your maven project once successfully. All dependencies will download to your local repository.

In your case if you are using your own jar you can add that jar as follows to pom.xml

<dependency>
    <groupId>your.group.id</groupId>
    <artifactId>your.art.id</artifactId>
    <version>SNAPSHOT</version>
    <scope>provided</scope>
</dependency>
于 2013-06-24T11:54:55.933 回答
0

这个改变对我有用

<zipfileset src="${settings.localRepository}/com/google/android/support-v4/r7/support-v4-r7.jar" />
于 2013-06-26T12:30:13.687 回答