标签: maven-assembly-plugin

如何在干净安装时将多个jar文件发布到maven

我有一个使用maven程序集插件从一个jar创建多个jar现在问题是我必须将这些jar发布到本地repo,就像其他maven jars发布时由他们自己构建maven clean install我将如何能做到这一点

这是我的pom文件

<project>
 <parent>
  <groupId>parent.common.bundles</groupId>
  <version>1.0</version>
  <artifactId>child-bundle</artifactId>
 </parent>
 <modelVersion>4.0.0</modelVersion>
 <groupId>common.dataobject</groupId>
 <artifactId>common-dataobject</artifactId>
 <packaging>jar</packaging>
 <name>common-dataobject</name>
 <version>1.0</version>
 <dependencies>
      </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.jibx</groupId>
    <artifactId>maven-jibx-plugin</artifactId>
    <version>1.2.1</version>
    <configuration>
     <directory>src/main/resources/jibx_mapping</directory>
     <includes>
      <includes>binding.xml</includes>
     </includes>
     <verbose>false</verbose>
    </configuration>
    <executions>
     <execution>
      <goals>
       <goal>bind</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
   <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
     <execution>
      <id>make-business-assembly</id>
      <phase>package</phase>
      <goals>
       <goal>single</goal>
      </goals>
      <configuration>
       <appendAssemblyId>false</appendAssemblyId>
       <finalName>flight-dto</finalName>
       <descriptors>
        <descriptor>src/main/assembly/car-assembly.xml</descriptor>
       </descriptors>
       <attach>true</attach>
      </configuration>
     </execution>
     <execution>
      <id>make-gui-assembly</id>
      <phase>package</phase>
      <goals>
       <goal>single</goal>
      </goals>
      <configuration>
       <appendAssemblyId>false</appendAssemblyId>
       <finalName>app_gui</finalName>
       <descriptors>
        <descriptor>src/main/assembly/bike-assembly.xml</descriptor>
       </descriptors>
       <attach>true</attach>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

  </project>
Run Code Online (Sandbox Code Playgroud)

这是我的汇编文件

<assembly> …
Run Code Online (Sandbox Code Playgroud)

maven-2 maven-assembly-plugin

3
推荐指数
1
解决办法
8532
查看次数

Maven程序集插件chmod输出文件夹

我正在尝试使用像这样的maven-assembly插件来构建我的项目JAR的zip以及运行它所需的所有库:

        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
<descriptor>src/main/assembly/exportWithDepends.xml</descriptor>
                            </descriptors>
                            <finalName>myname</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

我的装配看起来像:

<assembly>
    <id>jar-with-dependencies</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <unpack>false</unpack>
            <scope>runtime</scope>
            <outputDirectory>lib</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <fileMode>755</fileMode>
        </dependencySet>
    </dependencySets>
    <files>
        <file>  
<source>${project.build.directory}/${project.build.finalName}.jar</source>
        </file>
    </files>
</assembly>
Run Code Online (Sandbox Code Playgroud)

这适用于制作合适的拉链.

然后,dependencySet上的fileMode标志为LIB内的每个元素提供755 CHMOD.问题是,实际的LIB文件夹本身保持777.有没有办法让LIB文件夹也得到755?

让maven做一些它不想做的事情总让我伤心:(

java maven maven-assembly-plugin

3
推荐指数
1
解决办法
6471
查看次数

可以maven组装插件挑选指定java包吗?

假设我们的项目中有以下包

org.xxx.dao,org.xxx.service,org.xxx.service.impl

所有的包都在源文件夹src/main/java中

我可以将包装配到分离的罐子里(xxx-dao.jar,xxx-service.jar,xxx-service-impl.jar)?

maven maven-assembly-plugin

3
推荐指数
1
解决办法
904
查看次数

如何调试内置的 maven 插件?

运行 maven-assembly-plugin 时出现 NullPointerException。它似乎是由我的程序集的特定部分引起的。如何对这个插件进行源代码级调试,以便缩小问题范围?

我正在使用 Eclipse 和 M2E。

eclipse maven maven-assembly-plugin m2e

3
推荐指数
1
解决办法
1126
查看次数

使用maven-assembly-plugin生成OSGi包分发

我有一个多模块项目,其中每个模块使用Apache Felix maven-bundle-plugin打包为OSGi包.整个项目使用父POM构建,列出上述模块.某些模块包含配置资源(例如.properties文件),这些资源不应该在捆绑包内用于部署,而是在专用配置文件夹中外部化.我的目标是创建一个分发文件夹(可能是一个zip文件),看起来像这样:

my-app-distribution
    /bundles
        module1-bundle.jar
        module2-bundle.jar
        etc.

    /conf
        external1.properties
        external2.properties
        etc.
Run Code Online (Sandbox Code Playgroud)

目录下的属性文件/conf是从各个模块的/target文件夹中手工挑选的文件.究其原因,.properties文件需要从目标文件夹与在src文件夹拾起的是,我使用Maven资源过滤,和属性文件包含${..}了特定环境下的值的占位符.这些占位符在构建过程中正确解析 - 每个构建配置文件 - 并且target/文件夹包含实际的特定于环境的值.

我已经多次完成了这样的分发文件操作 - 对于具有可执行JAR的发行版等.在这种情况下,我想使用程序集描述符的"moduleSets"配置 - 很容易将所有二进制文件/ jar放入单个分发文件夹中使用moduleSet /二进制描述符.在maven-bundle-plugin中也很容易将某些文件排除在打包到OSGi包中.我遇到的唯一问题是创建/conf分发文件夹并在那里收集必要的属性文件.我试图在"moduleSet/sources"描述符中使用"fileSets"来仅包含**/target每个模块的特定文件,但这似乎不起作用.

有人有建议吗?必须有一个简单的方法.或者我根本不应该使用?

谢谢,

简历


@PetrKozelka我不确定将特定于不同软件包的配置文件提取到一个单独的模块中是个好主意.OSGi的重点在于捆绑包是独立的,并且可以在开发和分发中重复使用.只有在源代码中将功能实现和相关配置文件组合在一起才有意义.对于特定的发行版,虽然我可能需要提取一些文件 - 如果管理员需要控制某些参数.对于不同的分发/应用,这可能是不同的.装配配置可能会更改,但捆绑/源将保持不变.此外,每个捆绑包可能会被单独开发和使用,并非所有捆绑包都必须始终是同一个超级项目的一部分 - 正如您所假设的那样.工件的类型(例如"模型","服务","数据访问","配置"等),而不是功能域/特征.这种方法在单个应用程序/项目中正常工作,但在企业级别上失败,因为通常需要重用垂直组件的子集(按功能域划分).

至于你依赖于模块中的文件布局,我同意不应该有这样的依赖.文件可以通过其显式名称或命名约定来手工挑选 - 根据非常具体的发行版要求.(这正是我面临的情况.)

osgi distribution maven maven-assembly-plugin maven-resources-plugin

3
推荐指数
1
解决办法
2309
查看次数

构建OSGi包包含与maven-assembly-plugin的依赖关系

我需要创建一个包含依赖项的OSGi包,我正在使用maven-assembly-plugin,这是我的pom.xml

<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>
    <artifactId>logstat</artifactId>
    <packaging>bundle</packaging>
    <name>Log Stat Demo</name>
    <version>1.0</version>
    <groupId>org.test</groupId>
    <dependencies>
        <dependency>
            <groupId>org.jruby</groupId>
            <artifactId>yecht</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-json</artifactId>
            <version>2.2.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.4.0</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>activator.*,service.*,impl.*</Export-Package>
                        <Bundle-Activator>activator.Activator</Bundle-Activator>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>activator.Activator</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-my-jar-with-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

当我运行maven build时,它创建了2个jars文件,一个带有依赖项,一个没有

但是在具有依赖关系的那个中,MANIFEST.MF不包括OSGi配置,如:

Manifest-Version: 1.0
Bnd-LastModified: 1392281245886
Build-Jdk: 1.6.0_45
Built-By: myname
Bundle-Activator: activator.Activator
Bundle-ManifestVersion: …
Run Code Online (Sandbox Code Playgroud)

osgi maven maven-assembly-plugin

3
推荐指数
1
解决办法
1万
查看次数

在java 8中构建maven程序集

我在我的Project中更改了使用的java版本.现在我正在使用lambdas表达式.

如果我编译IDE(IntelliJ),它运行良好.但是当我使用maven:assembly进行编译时,它会失败.

这是输出:

[ERROR] ...../commands/parser/CommandParser.java:[141,73] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
Run Code Online (Sandbox Code Playgroud)

和我的pom.xml:

<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.lefrantguillaume</groupId>
<artifactId>ServerTinyTank</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>

<dependencies>
    <dependency>
        <groupId>com.esotericsoftware</groupId>
        <artifactId>kryonet</artifactId>
        <version>2.22.0-RC1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.9</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.9</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>args4j</groupId>
        <artifactId>args4j</artifactId>
        <version>2.32</version>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.lefrantguillaume.Main</mainClass> …
Run Code Online (Sandbox Code Playgroud)

maven-assembly-plugin java-8

3
推荐指数
1
解决办法
6578
查看次数

maven 程序集插件:将文件添加到依赖 jar 中

有这个 maven 模块,比如说 prj-package-module,它使用 maven-assembly-plugin 将项目工件打包到一个 tar 文件中。在 prj-package-module/pom.xml 中也有 jars 作为依赖添加并打包到 tar 文件中。

现在的要求是在打包到 tar 文件之前,将一个文件 prj-pakacge-module/src/main/resources/file.xml 添加到这些依赖 jar 之一。我怎样才能做到这一点?

编辑:该文件是一个 JNLP,其中动态添加了依赖 jar 列表。出于安全原因,Javaws 还要求 JNLP 文件添加一个 jar 并对该 jar 进行签名。这就是我遇到问题的地方。

java maven-3 maven maven-assembly-plugin maven-jar-plugin

3
推荐指数
1
解决办法
1955
查看次数

在Maven中存储汇编文件的正确位置是什么?

在Maven的汇编指南(https://maven.apache.org/guides/mini/guide-assemblies.html)中,声明:

您会注意到程序集描述符位于$ {project.basedir}/src/assembly中,这是程序集描述符的标准位置.

但是在maven程序集插件页面(https://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html)中,它说:

注意:程序集描述符必须位于目录/ src/main/resources/assemblies中才能用于Assembly Plugin.

他们是两个不同的东西?他们中的任何一个都过时了吗?

java maven maven-assembly-plugin

3
推荐指数
1
解决办法
292
查看次数

如何解决maven插件中所有模块的依赖关系?

我正在编写一个Maven插件来获取已解析的依赖项.它适用于单个模块项目/ pom,但在多个模块项目上失败.

这是一段代码片段

@Mojo(
  name="scan",
  aggregator = true,
  defaultPhase = LifecyclePhase.COMPILE,
  threadSafe = true,
  requiresDependencyCollection = ResolutionScope.TEST,
  requiresDependencyResolution = ResolutionScope.TEST,
  requiresOnline = true
)
public class MyMojo extends AbstractMojo {

  @Parameter(property = "project", required = true, readonly = true)
  private MavenProject project;

  @Parameter(property = "reactorProjects", required = true, readonly = true)
  private List<MavenProject> reactorProjects;


  @Override
  public void execute() throws MojoExecutionException {
    for(MavenProject p : reactorProjects) {
      for(Artifact a : p.getArtifacts()) {
         ...consolidate artifacts
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码将整合所有模块中所有已解析的依赖项,但它包含一些额外的依赖项.

这是一个可以使用的示例项目.请下载此github …

maven-plugin maven maven-assembly-plugin

3
推荐指数
1
解决办法
653
查看次数