【发布时间】:2012-01-07 02:11:47
【问题描述】:
我不懂maven。更好地使用 ant,但是......我已经成功地创建了 jar(有或没有依赖项),我已经设法将 bat runner 脚本复制到 jar 附近,但现在我想用这个 jar 和这个 bat 创建 zip。所以我使用程序集插件并得到 BUUUM !!!卡达姆!在我的配置中,它与 jar 打包并行执行。我写了汇编文件:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jg</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>/123</outputDirectory>
<excludes>
<exclude>assembly/**</exclude>
<exclude>runners/**</exclude>
</excludes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
然后,我绑定了maven-assembly-plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>false</inherited>
<configuration>
<archive>
<manifest>
<mainClass>by.dev.madhead.lzwj.Main</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/assembly/assembly.xml</descriptor>
<!-- <descriptorRef>jar-with-dependencies</descriptorRef> -->
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
现在我在./target:
- runner.bat
- jar_without_dependencies.jar(它来自 maven-jar-plugin,对吧?)
- jar_without_dependencies.jar
第三个让我很生气。它包含: 而123目录包含:
如您所见,我得到了带有解压依赖项的 jar,EXCLUDED DIRS!!!! 和 dir 123,这实际上是我想要的(哦!程序集插件做到了!!!)。
我想获取带有依赖项的 jar 并使用类路径正确清单。作为一个选项,我想要带有解压依赖项的 jar(我知道 <unpack>false</unpack> 在程序集中,但无法让它工作)。我想将 /123 更改为 / 并获得没有排除文件的普通 JAR !!!我想要两个单独的任务来构建 jar 和 zip(它是用 maven 中的配置文件完成的吗??)就像在 ant 中一样,我会写这样的东西:
<target name="jar_with_deps" depends-on="compile">
<jar>
here i copy classes (excluding some dirs with runner script), and build manifest
</jar>
<copy>
copy bat file from src/main/resources/runner/runner.bat
</copy>
</target>
<target name="zip" depends-on="jar_with_deps">
<zip>
Get jar from previous target, get runner.bat. Put them in zip
</zip>
</target>
对不起,如果我表达得太过分了,但我对这种含蓄的行为真的很生气。我真的被这个困住了。
【问题讨论】:
-
jar-with-dependencies 也不起作用 -
试图删除
jar 。不起作用,因为 jar 是默认包装... -
好的,jar-with-dependencies 工作了。但仍需要对其进行自定义。
-
与其把你所做的事情写得一团糟,不如写出你想要达到的目标。我很想帮忙,但在第一段之后我就停止阅读了,因为你写的离题太多了。
-
我想要两个单独的“任务”:创建带有依赖项的 jar 并使用它生成 zip + 来自资源的 bat 文件。第二个“任务”必须依赖于第一个。
标签: maven maven-3 maven-assembly-plugin maven-jar-plugin