我不懂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
:
- 跑步者.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>
对不起,如果我表达得太过分了,但我对这种含蓄的行为真的很生气。我真的坚持这一点。