1

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. Project->Right Click->Java build path->Source->

Project/Users/CommonIncludes/src(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.

Dominic Philip
  • 108
  • 2
  • 10
  • Wouldn't it be better to create from those sources a separate maven build which can be used as dependency would make your life easier and your build portable. – khmarbaise Apr 10 '15 at 10:29
  • Thanks @khmarbaise for you comments. If I do like that I will face two problems. 1. If I make a change in those common classes, I must have to go for a recombile, so that current project will get the updated classes. 2. This dependency will not be added to my project war file, if am not putting that dependency in mvn repository. – Dominic Philip Apr 10 '15 at 10:55
  • This means you have either two options. Yes make a separate project using a SNAPSHOT version and you can update it on demand. This can be done in Eclipse without the need to do a command line `mvn install`. Or you can move those classes into a multi module of which one of the childs is your web application the other child is the common module. It only dependends on if your common classes/module is used by more than one project? If the answer is yes you should go the path to have separate maven project. – khmarbaise Apr 10 '15 at 15:09
  • Thank you @khmarbaise. Am almost there. I have created separate mvn project and added that as a dependency to my proj. Everything looks great, common classes are available in my project. But the next problem is that, maven not identifying those classes during maven build for creating war file. BUILD FAILURE -The repository system is offline but the artifact common:common:jar:0.0.1-SNAPSHOT is not available in the local repository. I want those classes in my war too (Not as a dependency from maven repo). Any suggestions? – Dominic Philip Apr 12 '15 at 11:16

2 Answers2

2

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

Steps include

1. Removed build-helper-maven-plugin from pom .

2. Created another maven project and added the common classes in it. Added maven-source-plugin in this pom to generate sources.

3. To the same pom, added maven-dependency-plugin to copy this generated sources to the desired location (My project's src/main/java).

4. Run a maven build for common classes project.

Now the common code in my project. Thanks.

Dominic Philip
  • 108
  • 2
  • 10
0

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>
Jason
  • 526
  • 7
  • 9