Я впервые использую maven, и я пытаюсь понять, как это работает. Поэтому у меня есть небольшой пример с двумя классами в разных пакетах.
package maven.callee ;
public class Callee {
public void callMe() {
System.out.println("Callee says: You called me!");
}
}
А теперь класс Caller с основной функцией.
package maven.caller ;
import maven.callee.Callee ;
public class Caller {
public static void main(String [] args) {
Callee callee = new Callee ();
callee.callMe ();
}
}
Я знаю, что структура каталога src отличается от стандартной.
Когда я запускаю команду mvn package для файла pom.xml, я получаю следующий вывод:
[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
Пожалуйста, что происходит здесь? почему Maven не может найти этот файл? мой файл POM, что я делаю не так?
<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>