我目前正在使用jar-with-dependencies程序集来创建这样一个jar.但是,我的罐子的名字有点长.
由于这个jar正被AS400上的RPG程序使用,我想缩短它以使这些开发人员的生活更轻松.但是,除了手工之外,我还没有找到一种方法来重命名罐子project-name-version-classifier-jar-with-dependencies.jar.我喜欢类似的东西project-name-version-classifier-full.jar
反正有没有基本上复制jar-with-dependencies程序集描述符并将其调用为满?
另外,我想继续让jar没有存储在存储库中的类路径.
我需要两个文物.我的分类器的jar包含构建所在的区域.具有所有依赖关系的jar也包括该区域.
project-name-version-region-full.jar并project-name-version-region.jar应存储在存储库中.在第一个例子中,分类器是区域满的,在第二个区域.后者正在发挥作用.
我有一个代码库,我想分发为jar.它还依赖于外部jar,我想在最后的jar中捆绑它.
我听说这可以用maven-assembly-plug-in,但我不明白怎么做.有人能指点我一些例子.
现在,我正在使用胖罐捆绑最后的罐子.我想用maven实现同样的目的.
我正在使用maven-assembly插件来创建我的应用程序的jar,包括其依赖项如下:
<assembly>
<id>macosx</id>
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
<includes>
<include>*:jar</include>
</includes>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
(我省略了一些与问题无关的其他内容)
到目前为止,这工作得很好,因为它创建了一个lib包含所有依赖项的目录.但是,我最近添加了一个新的依赖项,其范围是system,并且它不会将其复制到lib输出目录.我必须遗漏一些基本的东西,所以我打电话求助.
我刚刚添加的依赖项是:
<dependency>
<groupId>sourceforge.jchart2d</groupId>
<artifactId>jchart2d</artifactId>
<version>3.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/external/jchart2d-3.1.0.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我能够包含此依赖项的唯一方法是将以下内容添加到assembly元素:
<files>
<file>
<source>external/jchart2d-3.1.0.jar</source>
<outputDirectory>lib</outputDirectory>
</file>
</files>
Run Code Online (Sandbox Code Playgroud)
但是,这会强制我在重命名此jar时更改pom和程序集文件(如果有的话).而且,这似乎是错的.
我有试过<scope>runtime</scope>在dependencySets和<include>sourceforge.jchart2d:jchart2d</include>没有运气.
那么如何system在maven 2中将scoped jar 包含到汇编文件中?
非常感谢
我想生成一个zip文件,用maven更新应用程序.zip将托管在服务器上,我使用程序集插件生成zip.但是,我希望maven能够自动生成一个文本文件,该文件存储zip之外的当前版本号.这可能吗?
编辑:我成功地使用maven Assembly Plugin和两个描述符创建了两个自定义程序集.一个目录单一目标,它只是根据过滤创建一个带有更新版本.txt的文件夹.然后另一个具有单个目标的实际打包zip文件.这似乎非常不优雅,我想它不会正确地更新整个更新文件夹的maven repo.如果有更好的方法,请告诉我.
我希望Maven将项目与其运行时依赖项打包在一起.我希望它使用以下清单创建一个JAR文件:
.....
Main-Class : com.acme.MainClass
Class-Path : lib/dependency1.jar lib/dependency2.jar
.....
Run Code Online (Sandbox Code Playgroud)
并创建以下目录结构:
target
|-- ....
|-- my-project.jar
|-- lib
|-- dependency1.jar
|-- dependency2.jar
Run Code Online (Sandbox Code Playgroud)
意思是,我希望主JAR排除任何依赖项,并且我希望所有传递依赖项都被复制到"lib"子目录中.有任何想法吗?
从一些程序集插件版本maven build开始发出以下警告:
[警告]程序集描述符包含一个filesystem-root相对引用,它不是跨平台兼容的/
是否有任何推荐的即用型解决方案?直接谷歌搜索为我提供了大量的垃圾,没有真正的帮助.重新检查Maven程序集插件帮助没有为我提供答案,也许其他人有更好的搜索技能,可以提供帮助.
UPDATE
是的,这可能是因为类似于Linux,outputDirectory但我应该如何重写它以便携带?查看程序集插件文档,但未找到任何可移植性指南.
<fileSets>
<fileSet>
<directory>${basedir}/src/main/resources</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
Run Code Online (Sandbox Code Playgroud) 我正在尝试让Project B下拉(并解压缩)由Project A构建并部署到远程存储库的ZIP .
使用maven-assembly-plugin包装类型创建并附加ZIP pom:
<artifactId>project-a</artifactId>
<name>ZIP</name>
<description>Used by Project B</description>
<packaging>pom</packaging>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distribution-package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/scripts.xml</descriptor>
</descriptors>
<tarLongFileMode>gnu</tarLongFileMode>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
试图从项目B的pom中拉下来maven-dependency-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-scripts</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/staging</outputDirectory>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<overWrite>true</overWrite>
<type>zip</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
失败了: [ERROR] Failed to execute goal on project ...: …
zip pom.xml maven maven-assembly-plugin maven-dependency-plugin
我得到了错误Unable to locate NamespaceHandler when using context:annotation-config运行(java -jar)一个由maven-assembly-plugin组装并包含我的项目及其所有依赖项的jar.
正如其他人在forum.springsource.org 线程(消息#7/8)上正确发现的那样,问题出现是因为文件META-INF/spring.handlers和META-INF/spring.schemas存在于不同的jar中,当maven-assembly-plugin在单个文件中重新打包jar时会被覆盖.
查看两个spring - *.jar文件的内容,您可以看到文件位于相对于类路径的相同位置
$ jar tf spring-oxm-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/oxm/GenericMarshaller.class
...
$ jar tf spring-context-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/context/ApplicationContext.class
Run Code Online (Sandbox Code Playgroud)
是不是可以将META-INF文件夹放在特定的包中?如果是这样,我建议的想法(希望它是适用的)是将META-INF/spring.shemas和META-INF/spring.handlers文件放在他们引用的包下面.
$ jar tf spring-oxm-3.0.3.RELEASE.jar
org/springframework/oxm/META-INF/spring.schemas
org/springframework/oxm/META-INF/spring.handlers
org/springframework/oxm/GenericMarshaller.class
...
$ jar tf spring-context-3.0.3.RELEASE.jar
org/springframework/context/META-INF/spring.handlers
org/springframework/context/META-INF/spring.schemas
org/springframework/context/ApplicationContext.class
Run Code Online (Sandbox Code Playgroud)
这样,在单个jar中合并时它们不会发生冲突.你怎么看待这件事?
在必须是常见的事件中,我需要在程序集中包含一个空目录.就我而言,它是logs /.
我在程序集描述符中尝试了不同的变体,如:
<fileSet>
<directory>${basedir}/target</directory>
<includes>
<include>doesntexist</include>
</includes>
<outputDirectory>/logs</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
Run Code Online (Sandbox Code Playgroud)
并且目录刚刚被修剪.
我试图排除,但仍然包括很多东西:
<fileSet>
<directory>${basedir}/target</directory>
<excludes>
<exclude>*</exclude>
</excludes>
<outputDirectory>/logs</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
Run Code Online (Sandbox Code Playgroud) 我开发了一个Java实用程序库(类似于Apache Commons),我在各种项目中使用它.除了胖客户端,我还将它用于移动客户端(具有J9 Foundation配置文件的PDA).随着时间的推移,作为单个项目启动的库分布在多个包中.因此,我最终得到了许多功能,这在所有项目中并不是真正需要的.
由于这个库也用在一些移动/ PDA项目中,我需要一种方法来收集使用过的类并生成实际的专用jar.
目前在使用此库的项目中,我有Ant jar任务,从(从实用程序项目)生成专用jar文件(例如:my-util-1.0-pda.jar,my-util-1.0-rcp.jar)使用include/exclude jar任务功能.由于生成的jar文件的大小限制,对于移动项目,这通常是需要的.
现在迁移到Maven我只是想知道是否有任何最佳实践可以达到类似的目的.我考虑以下场景:
[1] - 除了主jar工件(my-lib-1.0.jar)之外,还在my-lib项目中使用Maven Jar插件使用分类器(例如:my-lib-1.0-pda.jar)生成单独/专用工件或Maven Assembly Plugin过滤/包含.我对这种方法不太满意,因为它污染了库,消费者需要(过滤器).
[2] - 为所有专门的客户端/项目创建额外的Maven项目,这将"包装""my-lib"并生成过滤的jar工件(例如:my-lib-wrapper-pda-1.0 ......等) .因此,这些包装器项目将包括过滤(以生成过滤的工件),并将仅依赖于"my-lib"项目,客户端项目将依赖于my-lib-wrapper-xxx-1.0而不是my- lib-1.0.这种方法可能看起来有问题,因为即使这样也会让"my-lib"项目完整(没有额外的分类器和工件),基本上会使项目数量增加一倍,因为对于每个客户端项目我都会有一个lib,只是为了收集所需的来自"my-util"库的类("my-pda-app"项目将需要一个"my-lib-wrapper-for-my-pda-app"项目/依赖项).
[3] - 在每个使用该库的客户端项目中(例如:my-pda-app)添加一些专门的Maven插件来修剪(当生成最终的工件/包时)不需要的类(例如:maven-assembly) -plugin,maven-jar-plugin,proguard-maven-plugin).
在"Maven方式"中解决此类问题的最佳实践是什么?