2

I am using the maven-eclipse-plugin (not M2E!) to generate my project. I have checked out the project under a source directory: C:\source, and this source is not organized in the Maven convention. My eclipse work space is under C:\eclipse\workspace, where I have the POM files.

In the POM, I have specified to create linked / virtual folders to organize the source in the Maven format (src/main/java, etc):

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <linkedResources combine.children="append"> 
            <linkedResource>
              <name>src</name>
              <type>2</type>
              <locationURI>virtual:/virtual</locationURI> 
            </linkedResource>
            <linkedResource>
              <name>src/main</name>
              <type>2</type>
              <locationURI>virtual:/virtual</locationURI> 
            </linkedResource>
            <linkedResource>
              <name>src/main/java</name>
              <type>2</type>
              <locationURI>WORKSPACE_LOC/source/mymodule</locationURI>
            </linkedResource>
          </linkedResources>
          ...
        </plugin>

When I create a project for eclipse by running mvn eclipse:clean eclipse:eclipse, the .project file hence generated has linked folders (or virtual folders):

<linkedResources>
    <link>
        <name>src</name>
        <type>2</type>
        <locationURI>virtual:/virtual</locationURI>
    </link>
    <link>
        <name>src/main</name>
        <type>2</type>
        <locationURI>virtual:/virtual</locationURI>
    </link>
    <link>
        <name>src/main/java</name>
        <type>2</type>
        <locationURI>WORKSPACE_LOC/source/mymodule</locationURI>
    </link>
</linkedResources>

but the .classpath file generated does not add those folders to the classpath as source folders for my project, i.e., an entry like the following is missing:

<classpathentry including="**/*.java" kind="src" path="src/main/java"/>

If I were to create a project using eclipse (and not using the maven-eclipse-plugin), I could create virtual / linked folders as necessary and add them as source folders to the project.

Using the plugin, I am forced to point to the absolute path to the source folder as sourceDirectory. The plugin does not seem to recognize linked / virtual folders and hence does not add them as a source folder to my project. Is there a solution for this where I can add a linked folder as a source folder to my eclipse project generated using the Maven eclipse plugin?

Thanks in advance.

4
  • So, to be clear, does your source in version control have a POM file and can be built with mvn clean install? I was confused by your comment "My eclipse work space is under C:\eclipse\workspace, where I have the POM files." Oct 4, 2012 at 14:47
  • No, the source from SCM is separate from the Mavenized project. So there is no POM under italic_C:\source_italic, it only has the source code. The POMs are located in the Mavenized project in the work space.
    – Neel
    Oct 4, 2012 at 15:09
  • Wow, that feels a highly convoluted approach. Have you considered adding a POM to the source code and just running eclipse:eclipse there? Some effort would be required to get the POM to accept the non-standard hierarchy, but it should be doable. Then the invocation of eclipse:eclipse would be "normal" and you could just import the existing project into your Eclipse workspace using the menus. Oct 4, 2012 at 17:36
  • Hmm, no, the source cannot be mavenized at this point of time, hence the search for a workaround.
    – Neel
    Oct 4, 2012 at 19:57

1 Answer 1

2

Have you tried the following approach?

  1. Check out source (including existing POM file) to C:\source.

  2. Open Eclipse to workspace C:\eclipse\workspace.

  3. Select File > Import... > Maven > Existing Maven Projects

  4. Navigate to the directory containing your pom.xml file and proceed to import.

This works for me on projects where I keep the source and workspace paths completely separate.

8
  • But when I import the project, there is no source attached to it. Do I not need to manually configure the source folders then?
    – Neel
    Oct 3, 2012 at 13:47
  • You shouldn't have to. Does your Maven project follow the standard project layout? My answer also assumed you have an existing pom.xml file (which builds fine from the command line). Oct 3, 2012 at 14:34
  • No, the source does not follow the standard layout either, which is why I wanted to create virtual folders as per the standard layout. As an example, the source module is like: /source/module/java-package, which when I import as a source folder would be like: module/src*/main*/java*/java-package - where *: virtual folder. It might not be possible at this moment to re-structure the source, hence the problem.
    – Neel
    Oct 4, 2012 at 13:29
  • 1
    I guess this might be confusing, but when I say eclipse plugin, I do not mean the m2e plugin for eclipse. I mean the maven-eclipse-plugin. Now to answer your question, I have been running eclipse:clean eclipse:eclipse from the command prompt and there I see the problem. The thing is when the plugin generates the .project file, it correctly creates the virtual folders, but in the generated .classpath file, it does not have any references to the virtual folders as source.
    – Neel
    Oct 4, 2012 at 14:22
  • 1
    My mistake, sorry I went off on the wrong tangent. I don't know the answer off hand. Any chance you could post a little pom.xml and suggest a project layout so that I can test this? I would add that to the main question so that others can experiment. Oct 4, 2012 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.