0

Java EE アプリケーションを Windows と Linux に配布する必要があります。アプリケーションには、WEB-INF/bin フォルダーにいくつかのシステム依存ファイル (dll など) があります。

私はこのアプローチを試みています。

プロジェクト フォルダ ツリーは次のようになります。

  • プロジェクト
    -- src
    ---- メイン
    ---- Java
    ------ webapp
    -------- ...
    -------- WEB-INF
    ------- ---- bin (現在は空のフォルダー)
    -- ターゲット

すべての bin ファイルを次の場所に移動しました。

  • プロジェクト
    -- 配布
    ---- ビン
    ------ 勝利
    ------ linux

最初のステップで、Maven を構成して、distrib/bin/win をターゲット フォルダーの WEB-INF/bin にコピーしようとしています。

2 番目のステップでは、最初のプロファイルが機能したら、2 つのプロファイル (1 つは Windows 用、もう 1 つは 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が初めてなので、助けが必要です。

4

2 に答える 2

1

コピーしたいファイルは にあると言っていまし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>
于 2012-11-07T18:44:28.523 に答える
1

WEB-INF/binwar 内のフォルダーにバイナリ ファイルをコピーすることだけが必要な場合は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 バイナリのいずれかを選択できます。

于 2012-11-08T09:57:23.317 に答える