我能够使用Maven编译并启动我的Spring项目:
mvn -e clean compile exec:java -Dexec.mainClass=de.fraunhofer.fkie.tet.vmware.manager.Test
Run Code Online (Sandbox Code Playgroud)
但是,当我使用maven-assembly-plugin(包括applicationContext.xml)在一个文件中组装所有jar时,我总是Exception在java执行期间得到一个:
java -cp target/test-jar-with-dependencies.jar:. de.fraunhofer.fkie.tet.vmware.manager.Test
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Sep 6, 2010 10:37:21 AM org.springframework.util.xml.SimpleSaxErrorHandler warning
WARNING: Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
...
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: …Run Code Online (Sandbox Code Playgroud) 我使用程序集插件从几个maven工件创建一个超级jar.
现在,我想在创建的程序集jar的Manifest中添加一些公司特定的条目.
但是怎么样?
所述archive元件犯规允许任意元素(或者是有一个方法来添加foobar: tutu内部archive标签?)
此外,maven-jar-plugin它不起作用,因为这只影响项目的默认工件,而不是组装.
知道怎么做吗?
maven-2 assemblies manifest maven-plugin maven-assembly-plugin
我们有一个小项目,有一些重量级依赖(例如Spring),我们只使用小部件.因此,我们在打包所有依赖项时得到的JAR重达几兆字节,即使对于两类服务器也是如此.这似乎没必要.
有没有办法将JAR程序集限制为实际使用的(类)文件?
我有一个有多个程序集执行的pom.当我跑步时,例如mvn package,它运行所有的执行.我怎么能告诉它只运行foo执行?
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>foo/id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<configuration>...</configuration>
</execution>
<execution>
<id>bar</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<configuration>...</configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)
在我看来,我的上述内容类似于以下内容Makefile:
all: foo bar
foo:
... build foo ...
bar:
... build bar ...
Run Code Online (Sandbox Code Playgroud)
我可以运行make all或只是make构建一切,或者我可以运行make foo或make bar构建单个目标.我怎样才能用Maven实现这个目标?
我是maven的新手,花了大约3天时间使用汇编插件生成zip文件,参考http://www.petrikainulainen.net/programming/tips-and-tricks/creating-a-runnable-binary-distribution-with- maven-assembly-plugin /我的项目是多模块的,所以我也提到使用Maven程序集插件管理多模块依赖项
我还有几个效率低下的问题.下面是assembly.xml(我从第一个链接继承)
<assembly>
<id>bin</id>
<!-- Generates a zip package containing the needed files -->
<formats>
<format>zip</format>
</formats>
<!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
<dependencySet>
<!-- Project artifact is not copied under library directory since it is
added to the root directory of the zip package. -->
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<moduleSets>
<moduleSet>
<!-- Enable access to all projects in the current multimodule build! <useAllReactorProjects>true</useAllReactorProjects> -->
<!-- Now, select which …Run Code Online (Sandbox Code Playgroud) 我很遗憾在这里听起来很无知,但我是Maven的新手,并且一直在抨击我肯定非常简单的事情.
该文件说:
[...]项目可以生成一个ZIP程序集,其中包含根目录中项目的JAR工件,lib /目录中的运行时依赖项以及用于启动独立应用程序的shell脚本.
这正是我想要做的!但我似乎无法实现它.
我的POM如下:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.anearalone</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
[...]
<build>
<finalName>myapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assemble/dist.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.anearalone.myapp.CLI</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
Run Code Online (Sandbox Code Playgroud)
引用的dist.xml如下所示:
<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<outputDirectory>/</outputDirectory>
<source>src/main/bin/arkify.sh</source>
<fileMode>755</fileMode>
</file>
</files>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>*:jar</include>
</includes>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<includes>
<include>com.anearalone:myapp:jar:0.0.1-SNAPSHOT</include>
</includes>
<outputDirectory>/</outputDirectory>
</dependencySet>
</dependencySets>
</assembly> …Run Code Online (Sandbox Code Playgroud) 这是场景:
两个Maven 3项目构建.
Build 1具有部署到Nexus的快照jar.
Build 2依赖于快照,引用类似1.0.0-SNAPSHOT,使用该mvn clean package assembly:single命令打包并压缩.
我们遇到的问题:偶尔在创建程序集时,jar的MANIFEST文件有时会说some.jar.1.0.0-SNAPSHOT,有时它会说some.jar.1.0.0-datetime戳,因此导致类未定义错误.
有没有办法在清单文件中阻止此命名问题?
- 编辑 -
进一步的研究发现了以下内容:
"如果快照是从一个仓库解决的,那么它将被加上时间戳,如果它来自反应堆或本地仓库,那么它将是-SNAPSHOT.该插件调用maven解析逻辑,因此这是核心maven行为."
这是正在遇到的确切问题.第二个构建清单文件总是有一个./lib/Framework-1.0.0-SNAPSHOT.jar条目,其中实际的jar文件名在./lib/Framework-1.0.0-SNAPSHOT.jar和./lib/之间变化Framework-1.0.0-timestamp.jar基于上面的引用.
直到现在我使用maven程序集插件为每个工件生成两个JAR - 编译源和依赖项 - 原因很简单 - 仅通过网络部署已编译的源比使用40 MB部署一体式JAR要快得多数据的.
由于覆盖了内部文件,我不得不切换maven shade插件才能使用该<transformers>功能.但是我无法管理两个执行:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade-libs</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile>
<artifactSet>
<excludes>
<exclude>...</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade-main</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>target/assembly/${project.artifactId}.jar</outputFile>
<artifactSet>
<includes>
<include>...</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
当我运行时mvn package,只运行第二次执行.第一个总是被忽略.使用maven程序集插件,它运行得很好.
当然解决方案可能是同时使用装配和阴影插件,但我想找到更一致的解决方案.
我有一个只包含文件的项目.我想将这些文件打包成zip并将它们存储在maven存储库中.我有配置插件配置来构建zip文件,该部分工作正常,但我似乎无法弄清楚如何安装zip文件?
另外,如果我想在另一个工件中使用这个程序集,我该怎么做?我打算调用依赖:unpack,但我没有在存储库中有一个工件来解压缩.
如何将zip文件放在我的存储库中,以便我可以在另一个工件中重复使用它?
父母pom
<build>
<plugins>
<plugin>
<!--<groupId>org.apache.maven.plugins</groupId>-->
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<filters>
<filter></filter>
</filters>
<descriptors>
<descriptor>../packaging.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
儿童POM
<parent>
<groupId>com. ... .virtualHost</groupId>
<artifactId>pom</artifactId>
<version>0.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Virtual Host - ***</name>
<groupId>com. ... .virtualHost</groupId>
<artifactId>***</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
Run Code Online (Sandbox Code Playgroud)
我把名字过滤掉了.这个POM是否正确?我只想将特定虚拟主机的文件捆绑在一起.
谢谢,
沃尔特
我有一个Maven项目,在src/main目录下有一个名为output的子目录.这个文件夹需要打包成tar.gz. 使用程序集插件时如下:
从pom.xml:
<build>
<finalName>front</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
assembly.xml:
<assembly>
<id>bundle</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/output</directory>
</fileSet>
</fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
我的问题是我尝试的结果将是运行tar实用程序本身,这意味着在解压缩时获取输出目录及其所有内容.我得到的是包含所有项目路径的输出文件夹 - name/src/main/output.