0

我希望能够配置 pom.xml,以便当我将其导入 eclipse 时,它​​指定src/main/aspect为 eclipse 源文件夹。

目前,导入会创建默认的源文件夹,仅此而已。

应该做什么?

谢谢

编辑 1

我已经配置了aspectj插件:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.4</version>
    <executions> 
    <execution>
        <goals>
            <goal>compile</goal>    
            <goal>test-compile</goal>                           
        </goals>
         <configuration>
            <source>${project.build.source}</source>
            <target>${project.build.target}</target>
            <aspectDirectory>src/main/aspect</aspectDirectory>
            <testAspectDirectory>src/test/aspect</testAspectDirectory>
        </configuration>
    </execution>
   </executions>
</plugin>

编辑 2

我已经配置了 m2e 插件:

<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>
                            aspectj-maven-plugin
                        </artifactId>
                        <versionRange>
                            [1.4,)
                        </versionRange>
                        <goals>
                            <goal>test-compile</goal>
                            <goal>compile</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <ignore></ignore>
                    </action>
                </pluginExecution>
            </pluginExecutions>
        </lifecycleMappingMetadata>
    </configuration>
</plugin>
4

3 回答 3

0

You shouldn't configure the defaults of the plugin, cause it defines already the src/test/aspect and src/main/aspect and it shouldn't be necessary to configuration something supplemental to compile etc.

Furthermore the problem with eclipse could be based on a missing mapping for your m2e plugin this means to add the following to your 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>aspectj-maven-plugin</artifactId>
                <versionRange>[1.4,)</versionRange>
                <goals>
                  <goal>compile</goal>
                  <goal>test-compile</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <execute />
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

This might cause you problem in Eclipse not to see the source folder correctly imported.

于 2012-05-21T14:46:14.697 回答
0

我相信source应该是 java 版本,而不是目录。对target. sources允许您指定源目录,并且文档说如果未指定,则将使用当前项目的 java 源 - 只有一个用于当前配置的项目。

我会尝试在参数中列出目录sources,如果这不起作用,我会删除sources并尝试build-helper:add-source。我还不确定是否有 m2e 连接器,build-helper-maven-plugin因此您可能必须向提到的 khmarbaise 添加类似的映射。

于 2012-05-21T17:15:38.727 回答
0

我认为它不会被 Eclipse 添加为源文件夹。您可以在Java Build Path > Source.

这不是必需的:然后您需要安装AJDT 插件并将项目转换为 AspectJ Project,否则.aj文件将充满 Eclipse 抱怨的错误。这些错误不会影响 maven 编译。

根据我的经验,识别或不识别为源不会影响 maven 编译.aj下的文件src/main/aspect

aspectDirectory并具有您给定的默认值aspectTestDirectory如果与默认值相同,则不需要它们。

下面是我的 pom 配置(没有尝试test-compile),它可以工作:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.4</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <!--<Xlint>ignore</Xlint>--><!--bypass xlint warnings -->
    </configuration>
    <dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.7.2</version>
    </dependency>
    </dependencies>
    <executions>
    <execution>
        <goals>
            <goal>compile</goal>
        </goals>
    </execution>
    </executions>
</plugin>
于 2013-06-27T02:31:26.833 回答