Reputation: 1586
For all Java projects I have participated in so far I have written build scripts using bash javac
and java
. However for my latest project I thought I would dive into Maven.
Whenever I compile my project I am getting compilation errors because a package doesn't exist. I have no external dependencies, but I do have sub packages within my application.
Example structure:
src/
main/
com/
mycompany/
/application
/package1
MyClass.java
/package2
MyClass2.java
App.java
test/
pom.xml
Example Classes:
MyClass.java
package com.mycompany.application.package1;
public class MyClass{
private MyClass(){}
}
App.java
package com.mycompany.application;
import com.mycompany.application.package1.MyClass;
public class App{
public static void main(String[] args){
System.out.println("It works!");
}
}
Upvotes: 0
Views: 132
Reputation: 2456
If you have imported your project in eclipse, please check your project's .classpath file have the following entry.
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Sometimes you need check .classpath file. This extra check has worked for me.
And are you executing maven commands from command line? If you executing - 'mvn clean install' like command from command prompt, ideally you should not get an error for the above mentioned directory structure without any changes.
Upvotes: 0
Reputation: 533
You should move your packages and classes to src/main/java
, that is the root folder of packages in maven.
Hope it helps!
Upvotes: 2