使用Maven在战争中包括系统依赖的二进制文件



我必须向Windows和Linux分发Java EE应用程序。应用程序在Web-Inf/bin文件夹中有几个依赖系统的文件(DLL等)

我正在尝试这种方法。

项目文件夹树是这样的:

  • 项目
    -SRC
    ----主要
    ---- Java
    ------ WebApp
    -------- ...
    -------- Web-Inf
    ------------ bin(现在是一个空文件夹)
    - 目标

我将所有bin文件移至:

  • 项目
    - 分布
    ---- bin
    -------赢
    ------ Linux

在第一步中,我试图配置Maven将分布/bin/win复制到目标文件夹中的Web-Inf/bin

在第二步中,当第一个工作起作用时,我将添加两个用于Windows的配置文件,另一个用于Linux。

在我的pom.xml中,我已经放了这些行:

<build>
    <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <executions>
            <execution>
              <id>distro-assembly</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
              <configuration>
                <descriptors>
                  <descriptor>distrib/bin.xml</descriptor>
                </descriptors>
              </configuration>
            </execution>
          </executions>
        </plugin>
    </plugins>

在这里您有bin.xml来源:

    <assembly 
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd" >
  <id>webtop10.2_bin</id>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}/distrib/bin/win</directory>
      <outputDirectory>/WEB-INF/bin</outputDirectory>
      <includes>
          <include>*.*</include>
      </includes>
      <fileMode>0750</fileMode>
      <directoryMode>0755</directoryMode>
      <lineEnding>keep</lineEnding>
    </fileSet>
  </fileSets>
</assembly>

当我执行MVN软件包时,构建成功,但文件未复制到Web-Inf/bin文件夹。装配插件说:

[INFO] --- maven-assembly-plugin:2.2-beta-5:single (distro-assembly) @ sibila ---
[INFO] Reading assembly descriptor: distrib/bin.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

我是Maven的新手,所以我需要帮助。

如果您想要的只是将二进制文件复制到战争内的WEB-INF/bin文件夹中,那么我认为您不应该使用maven-assembly-plugin

这是一种简单得多的方法:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>distrib/win</directory>
                        <targetPath>WEB-INF/bin</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

这可以专门使用构建配置文件,以便您选择Windows或Linux二进制文件。

您说要复制的文件位于project/distrib/bin/win中,但是您的汇编描述符文件集是从${project.build.directory}/distrib/bin/win复制的。除非您更改了POM中项目的构建目录,否则${project.build.directory}project/target。大会文件集中的目录可能只是distrib/bin/win,因为我认为目录是相对于项目基础的:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>webtop10.2_bin</id>
    <fileSets>
        <fileSet>
            <directory>distrib/bin/win</directory>
            ...
        </fileset>
    </fileSets>
</assembly>

最新更新