18

私のプロジェクトは、複数のJavaプロジェクト、ブリッジとしての1つのJava-JNI-C ++プロジェクト、およびアルゴリズムライブラリを保持する1つの純粋なC++プロジェクトで構成されています。3種類すべてのプロジェクトのMavenビルド構成を作成することができました。したがって、コマンドライン(Windows 7、64ビット)でそれらを呼び出すと、すべてがうまく機能します。

私はmakeファイルなどを使用していません。私はexec-maven-pluginを使用して、cygwinなしでmingw 64ビットインストールを呼び出します(また、少なくとも故意にmsysをインストールしませんでした)。したがって、JNAおよびライブラリプロジェクト用にそれぞれ2つの純粋なコマンドラインg++コマンドがあります。

スムーズな開発ワークフローのために今必要なのは、Eclipse内からこのプロジェクトをビルドおよびデバッグできるようにすることですが、pomsに作業を入れて、Eclipseビルダーを追加で構成したくないため、Mavenビルドスクリプトを使用します。これは一貫している必要があります!さらに、Eclipseでのエラー解析は、Mavenビルドの出力と一致している必要があります。

私のJavaプロジェクトの場合、これは箱から出してすぐに機能します。EclipseがMaven構成を取得し、CLEANとBUILDが正確に必要なものを生成します。(Java Builderがプロジェクトのプロパティでまだアクティブになっていることはわかりますが、なぜですか??)。しかし、CDTで動作させることはできません。

C ++ Builderを無効にすると、Eclipseはmaven(必要なもの)でビルドするだけですが、cleanコマンドが正しく機能しません。また、コンパイラによるエラーではないエラーがマークされます。もちろん、これは一貫している必要があります。

このユースケースのチュートリアルはありますか?

その件に関する情報は見つかりませんでした。一般的に、ベストプラクティスなどを見逃して、間違った方向に進んでいるかどうかはわかりません。

これが私の最初の質問ですので、私の質問に対するフィードバックもお気軽にどうぞ。私が提供できるもの;-)

いくつかの情報:

システムWindows7、64ビット

Eclipse Juno、m2e

ライブラリPOM:

<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>test</groupId>
  <artifactId>mylib</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>MyLib</name>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <versionRange>[1.1.1,)</versionRange>
                    <goals>
                      <goal>exec</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute>
                      <runOnIncremental>true</runOnIncremental>
                    </execute>
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1.1</version>
        <executions>
          <execution>
            <id>compile-Windows_x64</id>
            <phase>compile</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>g++</executable>
              <workingDirectory>target/cpp/Windows_x64</workingDirectory>
              <arguments>
                <argument>-Wall</argument>
                <argument>-m64</argument>
                <argument>-c</argument>
                <argument>-DAPI_EXPORT</argument>
                <argument>-g3</argument>
                <argument>-std=c++0x</argument>
                <argument>../../../src/main/cpp/*.cpp</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>link-Windows_x64</id>
            <phase>compile</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>g++</executable>
              <workingDirectory>target</workingDirectory>
              <arguments>
                <argument>-shared</argument>
                <argument>-s</argument>
                <argument>-m64</argument>
                <argument>-oMyLib_Windows_x64.dll</argument>
                <argument>cpp/Windows_x64/*.o</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/assembly.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <phase>none</phase>
          </execution>
          <execution>
            <id>default-compile</id>
            <phase>none</phase>
          </execution>
        </executions>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-resources</id>
            <phase>none</phase>
          </execution>
          <execution>
            <id>default-testResources</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>none</phase>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

JNI POM:

<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>test</groupId>
  <artifactId>myprog</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>MyProg</name>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>truezip-maven-plugin</artifactId>
                    <versionRange>[1.1,)</versionRange>
                    <goals>
                      <goal>copy</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute>
                      <runOnIncremental>true</runOnIncremental>
                    </execute>
                  </action>
                </pluginExecution>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <versionRange>[1.1.1,)</versionRange>
                    <goals>
                      <goal>exec</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute>
                      <runOnIncremental>true</runOnIncremental>
                    </execute>
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>truezip-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>get-library-headers</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <fileset>
                <directory>../MyLib/target/mylib-0.0.1-SNAPSHOT-dll.zip</directory>
                <includes>
                  <include>headers/*</include>
                </includes>
                <outputDirectory>${project.build.directory}/myLib</outputDirectory>
              </fileset>
            </configuration>
          </execution>
          <execution>
            <id>get-library</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <fileset>
                <directory>../MyLib/target/mylib-0.0.1-SNAPSHOT-dll.zip</directory>
                <includes>
                  <include>*.dll</include>
                </includes>
                <outputDirectory>${project.build.directory}</outputDirectory>
              </fileset>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1.1</version>
        <executions>
          <execution>
            <id>compile-Windows_x64</id>
            <phase>compile</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>g++</executable>
              <workingDirectory>target/cpp/Windows_x64</workingDirectory>
              <arguments>
                <argument>-Wall</argument>
                <argument>-m64</argument>
                <argument>-c</argument>
                <argument>-g3</argument>
                <argument>-std=c++0x</argument>
                <argument>-I../../myLib/headers</argument>
                <argument>../../../src/main/cpp/*.cpp</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>link-Windows_x64</id>
            <phase>compile</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>g++</executable>
              <workingDirectory>target</workingDirectory>
              <arguments>
                <argument>-m64</argument>
                <argument>-s</argument>
                <argument>-oMyProg_Windows_x64.exe</argument>
                <argument>cpp/Windows_x64/*.o</argument>
                <argument>MyLib_Windows_x64.dll</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <phase>none</phase>
          </execution>
          <execution>
            <id>default-compile</id>
            <phase>none</phase>
          </execution>
        </executions>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-resources</id>
            <phase>none</phase>
          </execution>
          <execution>
            <id>default-testResources</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

ありがとう

4

1 に答える 1

2

EclipseはMavenビルドを使用しません。代わりに、POMに従ってJDTを構成します。これは、M2E(MavenからEclipse)コネクターを介して行われます。CDTでも同じように機能させたい場合は、そのためのM2Eコネクタが必要になります。私は既存のものを知らないので、そのためのEclipseプラグインを作成する必要があります。これを行う方法の詳細については、 http://wiki.eclipse.org/M2E/Extension_Developmentを参照してください。

もちろん、pomのlifecycleMappingで「無視」の代わりに「実行」を使用することもできます。ただし、変更のたびにビルド全体がトリガーされるため、ビルドがかなり遅くなる可能性があります。それでも、これによって「魔法のように」Mavenからのエラーがファイルに表示されることはありません。

于 2013-12-13T14:47:48.343 に答える