Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
maven使用jar和更多文件创建zip_Maven_Maven 3_Maven Assembly Plugin_Maven Jar Plugin - Fatal编程技术网

maven使用jar和更多文件创建zip

maven使用jar和更多文件创建zip,maven,maven-3,maven-assembly-plugin,maven-jar-plugin,Maven,Maven 3,Maven Assembly Plugin,Maven Jar Plugin,我不理解马文。最好使用ant,但是。。。我已经成功地创建了jar(有依赖项或没有依赖项),我已经成功地将batrunner脚本复制到jar附近,但是现在我想用这个jar和这个bat创建zip。所以我使用汇编插件并得到BUUUM!!!!卡达姆!在我的配置中,它与jar打包并行执行。我编写了汇编文件: <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:

我不理解马文。最好使用ant,但是。。。我已经成功地创建了jar(有依赖项或没有依赖项),我已经成功地将batrunner脚本复制到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>

对不起,如果我太善于表达,但我真的对这种含蓄的行为很生气。我真的被这件事难住了。

你必须选择以下选项才能实现你的目标:

  • 选项:创建两个程序集描述符,一个用于jarw/deps,另一个用于zip。Zip接受新创建的jar
  • 选项:在您的项目中再创建两个模块:第一个模块将所有dep放入一个jar(或者将一个着色jar与主jar一起连接,保存另一个模块),让第二个模块依赖它,并将该jar吸进程序集中。你的任务完成了

  • 根据项目的规模和结构,我会选择安全的方式:选项2。这一个保证有正确的构建和dep顺序。选项1在某种程度上违反了maven方式。

    我在pom.xml中创建了两个配置文件:

    <profiles>
        <profile>
            <id>jar-with-dependencies</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.2.1</version>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>by.dev.madhead.lzwj.Main</mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>distro</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.2.1</version>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/distro.xml</descriptor>
                            </descriptors>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    
    
    带有依赖项的jar
    假的
    maven汇编插件
    2.2.1
    by.dev.madhead.lzwj.Main
    带有依赖项的jar
    包裹
    单一的
    发行版
    假的
    maven汇编插件
    2.2.1
    src/main/assembly/distro.xml
    包裹
    单一的
    

    现在我可以创建简单的jar(
    mvn clean package
    ),带有依赖项的jar(
    mvn clean package-Pjar with dependencies
    )。我还可以调用
    mvn package-Pdistro
    来创建zip。但在手动调用maven之前,我需要使用依赖项调用maven-Pjar。除了这个,一切都很好。

    为了防止它对其他人有帮助,我发现这很容易做到,至少对我的基本需求来说是如此。我已经在使用Maven Shade插件构建一个包含所有依赖项的jar:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>2.4.1</version>
      <configuration></configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    
    上面的块引用了
    assembly.xml
    ,它配置:

    
    释放
    拉链
    目标
    MyApp-${app.version}.jar
    /
    CHANGES.md
    0644
    许可证
    0644
    自述
    0644
    
    ${app.version}
    在pom.xml
    元素中定义。)


    就是这样,现在
    mvn包
    同时生成jar和zip。

    jar与依赖项不起作用,所以尝试删除jar。不工作,因为jar是默认的打包…好的,让jar和依赖项一起工作。但仍然需要定制。与其写一大堆你已经做过的事情,不如准确地写下你想要实现的。我很想帮忙,但我在第一段之后就停止了阅读,因为你在主题之外写了太多东西。我想要两个独立的“任务”:使用依赖项创建jar和使用它生成zip+bat文件。第二个“任务”必须依赖于第一个。当我创建两个程序集描述符时,第二个(用于zip)无法找到第一个的输出。如何指定它们的顺序?顺序与pom中定义的顺序相同。附加第二个工件,这个罐子也包括在内。请参见属性。
    <profiles>
        <profile>
            <id>jar-with-dependencies</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.2.1</version>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>by.dev.madhead.lzwj.Main</mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>distro</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.2.1</version>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/distro.xml</descriptor>
                            </descriptors>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>2.4.1</version>
      <configuration></configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.5.5</version>
      <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptors>
          <descriptor>assembly.xml</descriptor>
        </descriptors>
      </configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    
    <?xml version="1.0" encoding="utf-8"?>
    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
        <id>release</id>
        <formats>
            <format>zip</format>
        </formats>
        <fileSets>
            <fileSet>
                <directory>target</directory>
                <includes>
                    <include>MyApp-${app.version}.jar</include>
                </includes>
                <outputDirectory>/</outputDirectory>
            </fileSet>
        </fileSets>
        <files>
            <file>
                <source>CHANGES.md</source>
                <fileMode>0644</fileMode>
            </file>
            <file>
                <source>LICENSE</source>
                <fileMode>0644</fileMode>
            </file>
            <file>
                <source>README</source>
                <fileMode>0644</fileMode>
            </file>
        </files>
    </assembly>