Reputation: 243
This is my first time using maven and i'm trying to understand how it works. Therefore i have a small example with two classes in different packages.
package maven.callee ;
public class Callee {
public void callMe() {
System.out.println("Callee says: You called me!");
}
}
And now the Caller class with the main function.
package maven.caller ;
import maven.callee.Callee ;
public class Caller {
public static void main(String [] args) {
Callee callee = new Callee ();
callee.callMe ();
}
}
I know the structure of the src directory is not the same as the standard. When i run the command mvn package on the pom.xml file i get the following output:
[INFO] Compiling 1 source file to /home/ced/workspaceForOxygene/build/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[2,20] package maven.callee does not exist
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,4] cannot find symbol
symbol: class Callee
location: class maven.caller.Caller
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,24] cannot find symbol
symbol: class Callee
location: class maven.caller.Caller
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.645 s
[INFO] Finished at: 2018-04-24T17:12:36+02:00
[INFO] Final Memory: 13M/158M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project mavenTest: Compilation failure: Compilation failure:
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[2,20] package maven.callee does not exist
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,4] cannot find symbol
[ERROR] symbol: class Callee
[ERROR] location: class maven.caller.Caller
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,24] cannot find symbol
[ERROR] symbol: class Callee
[ERROR] location: class maven.caller.Caller
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Please what happening hier? why can't maven locate that file? hier is my POM file, what i am doing wrong?
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.swt.build</groupId>
<artifactId>mavenTest</artifactId>
<version>1.0</version>
<build>
<sourceDirectory>src/maven/caller</sourceDirectory>
<!--specify output directory for binaries -->
<outputDirectory> classes </outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins </groupId>
<artifactId> maven-jar-plugin</artifactId>
<version> 3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath> true </addClasspath>
<mainClass> maven.caller.Caller </mainClass>
</manifest>
</archive>
<!--specify output directory for jar file -->
<outputDirectory>jars</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Upvotes: 2
Views: 10466
Reputation: 26
maven.callee is missing from compiler path. It should be part of source dir or should be defined as lib dependency. With the current setting, Maven will try to compile the java files only under src/maven/caller. Change sourceDirectory to src/maven in pom.xml.
Upvotes: 1