Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven custom directory structure - no sources to compile despite specifying sourceDirectory

I am using a custom directory structure and have specified the directory in sourcedirectory tag. But still I get the message No sources to compile. Although the build is successful.

My directory structure:

enter image description here

So instead of src/main/java, I am using java. (And I have a reason to do that, so right now it's not possible to switch to src/main/java)

Here's my pom.xml:

<artifactId>application</artifactId>  
  <name>application</name>
  <packaging>jar</packaging>

   <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.test.skip>true</maven.test.skip>
  </properties>
    <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>

When I run command mvn clean package, I get following output:

enter image description here

The source is not compiled and resultant jar is empty. All the sources I have referred for using custom directory structure with maven say that using sourceDirectory should solve the problem. But in my case it doesn't solve

EDIT

I am using custom directory structure as using standar directory structure did not work for me. Hers' my question related to that: Getting error in linking a source folder in eclipse maven

EDIT2:

I am linking source in java directory. That is, on the file system, application->java does not exist, but in eclipse through link source option, I have added the Java source folder from a different directory. Therefore it appears in eclipse. Also I have run maven commands with mvn command line as well as through eclipse.

like image 901
tryingToLearn Avatar asked Mar 11 '18 14:03

tryingToLearn


People also ask

What is src folder in maven?

The src directory contains all of the source material for building the project, its site and so on. It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on.

What is src main Java?

As the name indicates, src/main is the most important directory of a Maven project. Anything that is supposed to be part of an artifact, be it a jar or war, should be present here. Its subdirectories are: src/main/java – Java source code for the artifact.

Can maven be used for non Java projects?

Can Maven Be Used For Non-Java Projects? Yes. There are hundreds of archetypes for Maven, ranging from Java web application development to eBook publishing.

Which option rightly gives the project's source directory in Maven?

Source Directories The Maven property ${project. basedir} defaults to the top level directory of the project, so the build directory defaults to the target directory in project base dir. It also sets the property ${project.


1 Answers

If I understand your issue correctly, You have an application folder and the actual source (java) folder is from somewhere else in the file system. And you linked the external folder as java source through eclipse for compilation.

By linking in Eclipse, maven will not automatically know where the source files are. Maven follows standard directory structure for looking up java and test files. You can use this Build Helper plugin to customize the way maven looks up sources.

An example talked here

like image 88
Anil Bachola Avatar answered Oct 18 '22 07:10

Anil Bachola