maven用jar和更多文件创建zip文件 [英] maven create zip with jar and some more files

查看:95
本文介绍了maven用jar和更多文件创建zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不懂行家.更好地使用ant,但是...我设法创建了jar(有或没有依赖项),我设法复制了与jar接近的蝙蝠奔跑者脚本,但现在我想用这个jar和这个蝙蝠来创建zip文件.因此,我使用汇编插件并得到BUUUM !!!! CADAAAM!在我的配置中,它的发生恰好使它与jar包装并行执行.我写了汇编文件:

I do not understand maven. Better use ant, but... I've managed to create jar (with, or without dependencies), I've managed to copy bat runner script close to jar but now i want to create zip with this jar and this bat. So i use assembly plugin and get BUUUM!!!! CADAAAM! In my configuration it happens so, that it executes parallel to jar packaging. I wrote assembly file:

    <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:

Then, I bound 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中得到了这个

  1. runner.bat
  2. jar_without_dependencies.jar(来自maven-jar-plugin,对吧?)
  3. jar_without_dependencies.jar

第三个人激怒了我.它包含: 123目录包含:

And the third angers me. It contains: And the 123 directory contains:

如您所见,我得到的jar带有解包的依赖项,EXCLUDED DIRS !!!!和dir 123,这实际上是我想要的(哦!汇编插件做到了!!).

As you see, I get jar with unpacked dependencies, EXCLUDED DIRS!!!!, and with dir 123, which is actually what I want (Oh! assembly plugin did that!!!).

我想获取具有依赖项的jar并使用classpath纠正清单.作为一种选择,我希望jar具有未打包的依赖项(我知道汇编中的<unpack>false</unpack>,但无法使其工作).我想将/123更改为/并获得没有排除文件的NORMAL JAR !!!我想要两个单独的任务来构建jar和zip文件(是在maven中用配置文件完成的吗?),就像在ant中一样,我会这样写:

I want to get jar with dependencies and correct manifest with classpath. As an option i want jar with unpacked dependencies (I know about <unpack>false</unpack> in assembly, but cannot get it work). I want to change /123 to / and get NORMAL JAR WITHOUT EXCLUDED FILES!!! I want two separate tasks to build jar and zip (is it done with profiles in maven??) As in ant, i would wrote something like this:

    <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>

对不起,如果我表现力太强,但我真的对这种隐性行为感到生气.我真的很坚持.

Excuse me, if I am too expressive, but I am really angry with this implicit behavior. I am really stuck with this.

推荐答案

您必须选择实现自己的目标:

You have to options to achieve your goal:

  1. 选项:创建两个程序集描述符,一个用于jar/deps的描述符,另一个用于zip. Zip使用新创建的jar.
  2. 选项:在项目中再创建两个模块:第一个模块阴影将所有的部件放入一个罐子中(或将阴影罐子与您的主罐子一起附加,保存另一个模块),让第二个模块依靠它,并在您的组件中吸取该罐子.完成了.
  1. option: Create two assembly descriptors, one for jar w/ deps and one for zip. Zip takes the the newly created jar.
  2. option: Create two more modules in your project: first modules shades all deps into one jar (or attach a shaded jar along with your main jar, save another module), have the second module depend on it and suck in that jar in your assembly. Your done.

根据您项目的大小和结构,我会选择一种安全的方法:选项2.保证该选项具有正确的构建和dep顺序.选项1有点违反行家方式.

Depending on the size and structure of your project, I would go for the safe way: option 2. This one is guaranteed to have the correct build and dep order. Option 1 violates the maven way somewhat.

这篇关于maven用jar和更多文件创建zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆