简体   繁体   English

将src / main / aspect作为源文件夹添加到Eclipse Maven项目中

[英]adding src/main/aspect as a source folder to an eclipse maven project

I would like to be able to configure the pom.xml so that when I import it into eclipse it specifies src/main/aspect as an eclipse source folder. 我希望能够配置pom.xml,以便在将其导入eclipse时将src/main/aspect指定为eclipse源文件夹。

At the moment, importing creates the default source folders but that is all. 目前,导入会创建默认的源文件夹,仅此而已。

What should be done? 应该做什么?

Thanks 谢谢

edit 1 编辑1

I have configured the aspectj plugin thus: 我因此配置了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>

edit 2 编辑2

I have configured the m2e plugin thus: 我因此配置了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>

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. 您不应该配置插件默认值 ,因为它已经定义了src / test / aspect和src / main / aspect,并且没有必要配置一些补充编译等内容。

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: 此外,eclipse的问题可能是由于您的m2e插件缺少映射而引起的,这意味着要在构建中添加以下内容:

<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. 这可能会导致您在Eclipse中看不到正确导入源文件夹的问题。

I believe source is supposed to be a java version, not a directory. 我相信source应该是Java版本,而不是目录。 Same for target . target相同。 sources allows you to specify the source directories, and the docs say that if not specified, the java sources of the current project will be used - just one for your project as configured currently. sources允许您指定源目录,文档说如果未指定,则将使用当前项目的java源-仅用于当前配置的项目。

I would try listing the directories in the sources parameter, and if that didn't work, I'd remove sources and try build-helper:add-source . 我会尝试在sources参数中列出目录,如果那行不通,我将删除sources并尝试build-helper:add-source I'm not sure there's an m2e connector for build-helper-maven-plugin yet so you might have to add a similar mapping to the one khmarbaise mentioned. 我不确定是否有用于build-helper-maven-plugin的m2e连接器,因此您可能必须为上述khmarbaise添加类似的映射。

I think it would not be added as source folder by Eclipse. 我认为它不会被Eclipse添加为源文件夹。 you could add it on your own in Java Build Path > Source . 您可以在Java Build Path > Source自己添加它。

This is not necessary: Then you need to have AJDT plugin installed in and convert the project to AspectJ Project, otherwise the .aj files will be full of errors complained by Eclipse. 这不是必需的:然后,您需要安装AJDT插件并将项目转换为AspectJ Project,否则.aj文件将充满Eclipse抱怨的错误。 The errors does not affect maven compiling. 该错误不影响Maven编译。

In my experience, recognized or not as source would not affect maven compiling the .aj files under src/main/aspect 以我的经验,识别或不识别为源不会影响Maven在src/main/aspect下编译.aj文件

Both aspectDirectory and aspectTestDirectory have default values as you given. AspectDirectoryaspectTestDirectory都具有您指定的默认值。 they are not needed if the same as default. 如果与默认值相同,则不需要它们。

Here below is my pom configuration (didn't try test-compile ) and it works: 下面是我的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Maven项目导入Eclipse 3.7(m2e 1.0),但是src / main / java未显示为源包 - Imported Maven Project into Eclipse 3.7 (m2e 1.0) but src/main/java are not shown as source-package Eclipse-Maven:更新项目从构建路径中排除 src/main/resources 文件夹 - Eclipse-Maven: Updating project excludes src/main/resources folder from build path Eclipse 中 Maven 项目的类路径 - src vs src/main/java - Classpath for Maven project in Eclipse - src vs src/main/java 在没有 Maven 的情况下在 Eclipse 中创建 src/main/java 文件夹结构 - Creating a src/main/java folder structure in Eclipse without Maven Maven无法将src / main / java识别为代码的源文件夹 - Maven does not recognise src/main/java as the source folder for code 使用 maven 创建 eclipse 源文件 src/main/java 和 src/main/groovy - Creating eclipse source files src/main/java and src/main/groovy with maven 无法从 src/main/resources Java 项目 Maven 获取文件夹 - cannot get folder from src/main/resources Java project Maven Maven只选择src / main / java或src / main / scala作为源文件夹,而不是两者 - Maven only picks src/main/java or src/main/scala as source folder, never both JSP Maven 项目不会在 Eclipse 中包含 src 文件夹 - JSP Maven project won't include src folder in Eclipse Eclipse将插件导入为源项目,但不包括src文件夹 - Eclipse import a plugin as source project but it's not include src folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM