18

我的项目由多个 Java 项目、一个作为桥梁的 Java-JNI-C++ 项目和一个保留算法库的纯 C++ 项目组成。我设法为所有 3 种项目类型编写了 Maven 构建配置。因此,当我在命令行(Windows 7、64 位)上调用它们时,一切正常。

我不使用任何 make 文件或类似的东西。我使用 exec-maven-plugin 在没有 cygwin 的情况下调用我的 mingw 64 位安装(而且我至少也没有故意安装 msys)。因此,JNA 和库项目各有 2 个纯命令行 g++ 命令。

我现在需要一个流畅的开发工作流程,能够在 Eclipse 中构建和调试这个项目,但使用 maven 构建脚本,因为我不想将工作放入我的 poms 并另外配置 eclipse 构建器。这应该是一致的!此外,Eclipse 中的错误解析是否应该与 maven 构建的输出一致。

对于我的 Java 项目,它开箱即用。Eclipse 选择了 maven 配置,CLEAN 和 BUILD 准确地产生了它应该的东西。(虽然我看到 Java Builder 在项目的属性中仍然处于活动状态。为什么??)。但我无法让它与 CDT 一起使用。

当我禁用 C++ Builder 时,Eclipse 只是用 maven 构建(我想要的),但是干净的命令不能正常工作。此外,我得到标记的错误不是编译器的错误。当然,这应该是一致的。

这个用例有教程吗?

我没有找到有关该主题的信息。我不确定我是否通常会走错方向,缺少最佳实践或其他什么?!

由于这是我的第一个问题,请随时就我的问题给我反馈。我能提供的我会提供的;-)

一些信息:

系统 Windows 7, 64 位

日食朱诺,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.xml 的生命周期映射中使用“执行”而不是“忽略”。但这可能会导致构建非常缓慢,因为每次更改都会触发整个构建。这仍然不会“神奇地”使来自 Maven 的错误出现在您的文件中。

于 2013-12-13T14:47:48.343 回答