最终目标是我试图用maven在eclipse中构建一个可执行的jar,它的依赖项打包如下。我试图完成的最终文件结构如下..
/target/my-distributable.zip
|- lib (all third party jar's, which I have loaded through maven)
|- images (the images my swing app can reference)
|- my-application.jar (my executable jar, manifiest within with correct classpath references)
|- my-application.properties (the properties my app reads and can modify)
|- READ-ME.TXT从这里开始,最终用户将能够解压缩可分发的zip文件,双击jar来启动位于/lib目录中的依赖项的java swing应用程序。还有一个文本编辑器在/作为swing应用程序的一部分,我想从/images目录中获得参考图像。我想要完成的是让maven创建一个zip文件,其中包含这个/dist文件夹中的所有内容,包括我的可执行jar及其位于lib目录中的依赖项。
我知道我需要让我的exec jar清单包括运行应用程序的主类,并在清单的类路径和我的属性文件中包含lib和映像目录。
我尝试了几个maven阴影插件的组合,它似乎把所有东西都抛到了一个jar中(在这里没有用,因为我需要一个zip,里面有我的exec jar,在exec jar之外需要lib ),以及maven-assembly。
下面是我当前的带有依赖项的POM。
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kiosk</groupId>
<artifactId>kiosk-application</artifactId>
<version>2.1</version>
<name>Kiosk Application</name>
<properties>
<jdk.version>1.5</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>com.shef</groupId>
<artifactId>shef</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.novaworx.syntax</groupId>
<artifactId>novaworx-syntax</artifactId>
<version>0.0.7</version>
</dependency>
<dependency>
<groupId>sam.i.am</groupId>
<artifactId>sam-i-am</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>jtidy.me</groupId>
<artifactId>jtidy-8</artifactId>
<version>8.0</version>
</dependency>
</dependencies>
</project>这是我最后一次尝试使用maven程序集插件添加到上面的pom中。
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<compress>true</compress>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>com.kiosk.app.KioskApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>/src/main/assembly/assembly.xml</descriptor>
</descriptors>
<finalName>kiosk-application_${project.version}</finalName>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<workDirectory>${project.build.directory}/assembly/work</workDirectory>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>还有我的
assembly.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bundle</id>
<formats>
<format>jar</format>
</formats>
<filesets>
<fileset>
<directory>target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileset>
<fileset>
<directory>target/libs</directory>
<outputDirectory>libs</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileset>
</filesets>
</assembly>我的应用结构..。
/src
|- main
|- assembly
|- java
|- com
|- kiosk
|- etc....
|- resources
|- myImage.jpg
|- my-application.properties当我试图使用上面的pom与构建部分使用maven-程序集插件时,我目前正在得到错误。
未能在项目kiosk上执行目标org.apache.maven.plugins:maven-assembly-plugin:2.2.1:single (默认)-应用程序:错误读取程序集:错误读取描述符:/src/main/Assembly.xml:未识别的标记:‘Failed’(位置: START_TAG呈...\r\n . @8:15) ->帮助1
这似乎是一项相当容易完成的任务,但是我从未使用maven来完成这类任务,而且我在编排构建以产生我想要实现的最终结果时遇到了问题。有没有专家能帮我指出正确的方向..?
发布于 2014-03-04 20:04:33
您应该在您的fileSets中使用filesets而不是filesets。注意大写字母S。其他几个XML标记也是如此。
https://stackoverflow.com/questions/22181164
复制相似问题