0

I created an empty maven project and it created a folder structure src/main/java. Now I want to link source from my local repo to this src/main/java.

If I go to buildpath->link source, and name the folder as src/main/java, I get the

folder already exists error

If I delete the folder and then do the same step, I get following error.

enter image description here

What is the best way to go forward?

I cannot change the project structure in the repo location and copying the folder to my workspace would mean manually merging changes later.

EDIT Folder Structure:

enter image description here

And build part of my pom.xml:

<build>
    <sourceDirectory>java</sourceDirectory>    
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <excludes>
                <exclude>**/old/**/*.java</exclude>
          </excludes>
          <includes>
            <include>java/com/**/*.java</include>            
          </includes>
        </configuration>
      </plugin>
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <excludes>
                    <exclude>**/old/**/*.java</exclude>                 
                </excludes>
                <archive>
                    <manifest>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>com.start.Start</mainClass>
                    </manifest>
                </archive>
            </configuration>
       </plugin>
    </plugins>
  </build>
tryingToLearn
  • 10,691
  • 12
  • 80
  • 114

1 Answers1

1

When you configure your project source with buildpath->link source it is just a configuration for eclipse. All it does is adding a linked source entry in the eclipse .project file. Maven does not know anything about this configuration. When you try to install your project with this configuration (with maven), you will not see any source code in the installed artifact.

If you have to do it this way add following to your pom.xml file. This will inform maven that you are using a different project folder structure. (this configuration is not recomended, but in your case it is usable)

<build>
   <sourceDirectory>Reletive path to source folder</sourceDirectory>
   .....
</build>

At eclipse side just give folder the name, that your sources main folder name. (like "Source")

https://maven.apache.org/guides/mini/guide-using-one-source-directory.html

miskender
  • 7,460
  • 1
  • 19
  • 23