简体   繁体   中英

build-helper-maven-plugin adding additional source

I am trying to add an additional source folder to my current maven project by using build-helper-maven plugin .

This source folder contains some common classes, like utility classes.

For that, here is my relevant pom.xml

 <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
      <execution>
        <id>add-source</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>add-source</goal> 
        </goals>
        <configuration>
          <sources>
             <source>C:/Users/CommonIncludes/src</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>

Eclipse is showing the following error :

Build path entry is missing.

Here the additional source location : "C:/Users/CommonIncludes/src" is outside of the workspace of the current project. But eclipse always treating this as a location from current project.

I am using Eclipse 4.3 and m2e. How can I overcome this error through MAVEN, so that Eclipse can identify the linked source from correct location.? Or is there any alternate way to do this using MAVEN?

Any help will be greatly appreciated. Thanks in advance.

Found it in an alternate way..works great.!

Steps include

1. Removed from pom .

2. Created another maven project and added the common classes in it. Added in this pom to generate sources.以生成源。

3. To the same pom, added to copy this generated sources to the desired location (My project's src/main/java). 将这个生成的源复制到想要的位置(我的项目的src/main/java)。

4. Run a maven build for common classes project.

Now the common code in my project. Thanks.

I had a lot of inconsistent trouble with this plugin. by far the simplest workaround in my case was simply to apply the addition via the standard 'resources' options. hope this helps someone.

    <build>
        <resources>
           ...
            <resource>
                <directory>${project.build.directory}/generated-sources</directory>
                <targetPath>${project.build.outputDirectory}</targetPath>
            </resource>
    </build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM