[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.433 s
[INFO] Finished at: 2023-02-10T07:48:17+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project Healthcare-doctor-ms: Compilation failure: Compilation failure:
[ERROR] /C:/Users/compu/Desktop/Healthcare-ms/Healthcare-doctor-ms/src/main/java/com/healthcare/doctor/iserviceimpl/IDoctorImpl.java:[13,39] package com.healthcare.basedomains.dtos does not exist
But i have those classes in the src/main/java.
Initially i was not getting src/main/java then i added it manually to build path. when i was trying to maven build i was getting can't build.
I tried multiple commands and multiple ways but issue not resolved.
Help me out, Thanks in advance .
here is pom:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.healthcare.doctor</groupId>
<artifactId>Healthcare-doctor-ms</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Healthcare-doctor-ms</name>
<description>this is healthcare doctor microservice</description>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2022.0.1</spring-cloud.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Related
Using liquibase with maven spring boot project have generated the snapshot at one state of db later tried generating the difference between the snapshot and online db using mvn liquibase:diff.
liquibase.properties as follows.
changeLogFile=src/main/resources/bd.changeLog-base.xml
diffChangeLogFile=src/main/resources/bd.changeLog-base.xml
outputChangeLogFile=src/main/resources/liquibase-new-changeLog.xml
url=offline:mysql?snapshot=src/main/resources/snap_shot.json
driver=com.mysql.jdbc.Driver
referenceDriver=com.mysql.jdbc.Driver
referenceUrl=jdbc:mysql://localhost:3306/db_sample
referenceUsername=yyyy
referencePassword=xxxx
using the following maven-plugin dependency in pom.xml
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--<version>2.4.2</version>-->
<version>2.2.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>Liquibaseapplicationexample</groupId>
<artifactId>Liquibaseapplicationexample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>liquibase-demo</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.5</version>
<configuration>
<propertyFile>src/main/resources/liquibase/config/liquibase.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>development</id>
<properties>
<build.profile.id>development</build.profile.id>
</properties>
</profile>
</profiles>
</project>
I am getting following error.
[INFO] Scanning for projects...
[INFO]
[INFO] ------< Liquibaseapplicationexample:Liquibaseapplicationexample >-------
[INFO] Building Liquibaseapplicationexample 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.6.1:diff (default-cli) # Liquibaseapplicationexample ---
[INFO] ------------------------------------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO] File: src/main/resources/liquibase/config/liquibase.properties
[INFO] 'outputChangeLogFile' in properties file is not being used by this task.
[INFO] ------------------------------------------------------------------------
[INFO] Starting Liquibase at Mon, 05 Apr 2021 01:21:53 IST (version 3.5.5 built at 2018-04-11 09:05:04)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.778 s
[INFO] Finished at: 2021-04-05T01:21:53+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.5:diff (default-cli) on project Liquibaseapplicationexample: Error setting up or running Li
quibase: liquibase.exception.UnexpectedLiquibaseException: Cannot parse snapshot offline:mysql?snapshot=src/main/resources/snap_shot.json: src/main/resources/snap_shot.j
son does not exist -> [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/MojoExecutionException.
Please help in solving this issue!
For me this issue fixed by upgrading liquibase-maven-plugin from 3.5.5 version to 3.10.1.
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.10.1</version>
As title, I deploy the package to jcenter successly,this is my pom.xml .
<?xml version="1.0" encoding="UTF-8"?>
<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>io.github.bloodnighttw.JDAwP</groupId>
<artifactId>JDAwP</artifactId>
<version>1.0.0_6</version>
<packaging>jar</packaging>
<name>JDAwP</name>
<distributionManagement>
<repository>
<id>bintray-bloodnighttw-JDAwP</id>
<name>bloodnighttw-JDAwP</name>
<url>https://api.bintray.com/maven/bloodnighttw/JDAwP/JDAwP/;publish=1</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.1.1_104</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName></shadedClassifierName> <!-- Any name that makes sense -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
So i run mvn deploy ,it deploy successly.(this is my source code)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:00 min
[INFO] Finished at: 2020-02-11T18:56:26+08:00
[INFO] ------------------------------------------------------------------------
And i want to use this package in another project.
So i add something into my another project's pom.xml.
This is my "Another Project's" pom.xml
<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>io.github.bloodnighttw</groupId>
<artifactId>Another-Projects</artifactId>
<version>0.0-SNAPSHOT</version>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.github.bloodnighttw.JDAwP</groupId>
<artifactId>JDAwP</artifactId>
<version>1.0.0_5</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
There is only a class in my projects(locate in /src/main/java/)
It is "Main.java", And the code of this file is that:
import io.github.*;
public class Main{
//nothing here
}
And I run mvn install , I got this error!
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.212 s
[INFO] Finished at: 2020-02-11T18:49:06+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Another-Projects: Compilation failure
[ERROR] /home/bbeenn1227/桌面/testMaven/src/main/java/Main.java:[1,1] package io.github does not exist
(By the way,I pretty sure that i have package "io.github.*")
I keep google a solution in this week,but I can't find any answer how to solve it.
So I decided to post a question on stackoverflow.
If you think my question is so stupid,just give me a little information about how to deal with it.
(And sorry about my bad english)
The dependency should probably be
<dependency>
<groupId>io.github.bloodnighttw.JDAwP</groupId>
<artifactId>JDAwP</artifactId>
<version>1.0.0_5</version>
</dependency>
instead of
<dependency>
<groupId>io.github.bloodnighttw.JDAwP</groupId>
<artifactId>JDAwP</artifactId>
<version>1.0.0_5</version>
<type>pom</type>
</dependency>
I have a project. Originally it was a single module project with structure like this
java-cloud-sample\
src\
main\
java
pom.xml
I decided to make it into a multi-module structure - I use java 9 anyway.
So I separated it like this
java-cloud-sample\
java-cloud-rest-api\
src\
pom.xml
pom.xml
Where root pom.xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<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.lapots.breed.platform.cloud</groupId>
<artifactId>java-cloud-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>java-cloud-rest-api</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And module pom.xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>com.lapots.breed.platform.cloud</groupId>
<artifactId>java-cloud-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>java-cloud-rest-api</artifactId>
<description>Demo project for Spring Boot</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<encoding.source>${project.build.sourceEncoding}</encoding.source>
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
But when I try to run mvn clean package I get
INFO] java-cloud-rest-api ................................ FAILURE [ 1.060 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.104 s
[INFO] Finished at: 2017-09-08T17:15:46+03:00
[INFO] Final Memory: 27M/331M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.2:compile (default-compile) on project java-cloud-rest-api: Fatal error compiling: invalid flag: --module-path -> [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/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :java-cloud-rest-api
What is the problem? (maybe I should split maven project into separate modules and each maven module split into java modules)
This failure occurs when maven installed on your machine is configured with java8 as the default java version. You can confirm this by executing
mvn -version
on your terminal and checking the Java version stated in the configuration.
To resolve the version to a newer and supported version like java9 at the moment, you can create/edit the mavenrc(on MacOS) file on your machine:
vi ~/.mavenrc
to include these
export PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/
export PATH=${PATH}:$JAVA_HOME/bin
Once you save this configuration, you can confirm maven should be using Java version 9 using the same command and then your project shall build without the stated error.
I had this error with the Maven compiler plugin 3.8.1 when a project was defining a module-info.java and Java 8 was used with Maven to compile the project. It seems that as soon a module-info.java is seen by the Maven compiler plugin it is adding the flag --module-path to the command line which is unknown to the Java 8 compiler. A way to exclude this file and compile the project without module support is to exclude the module-info.java from compilation based on a Maven profile:
<profiles>
<profile>
<id>java8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
I am creating a maven project from scratch, first just learn how to use maven.
The main project contains no source code file, but it has two modules (app, and util). App depends on util. I would like to have a .jar from app, and have no manifest file if possible.
I am able to compile the whole project with mvn clean install, but can not run the app from console.
The main project .pom is
<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.proba</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<modules>
<module>util</module>
<module>app</module>
</modules>
</project>
Util .pom is
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.proba</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>util</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
app pom is
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.proba</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>app</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.proba</groupId>
<artifactId>util</artifactId>
<version>0.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.proba.app.App</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>site-deploy</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.proba.app.App</mainClass>
<!--<arguments> <argument>myArg1</argument> <argument>myArg2</argument>
</arguments> -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The code doesn't do too much.
App.java (that inside the app module) is
package com.proba.app;
import com.proba.util.UtilClass;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
UtilClass uc = new UtilClass();
System.out.println( "QQQQQ: " + uc.print() );
}
}
I compile it with
mvn clean install
[INFO] Reactor Summary:
[INFO]
[INFO] myproject .......................................... SUCCESS [ 0.406 s]
[INFO] util ............................................... SUCCESS [ 2.074 s]
[INFO] app ................................................ SUCCESS [ 0.535 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
myproject, util, app is SUCCESS.
I try to run it with
java -jar app/target/app-0.0.1.jar
Hello World!
Exception in thread "main" java.lang.NoClassDefFoundError: com/proba/util/UtilClass
at com.proba.app.App.main(App.java:17)
Caused by: java.lang.ClassNotFoundException: com.proba.util.UtilClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
As you can see, Hello World! is printed out, but UtilClass is not found.
I am able to run the build from eclipse, but not from the console.
What I am doing wrong? Do you have any idea?
What you missing is the jar of UtilClass. You just need to add shade plugin in your pom.
As reference: maven-shade-plugin
In the pom.xml of app module,You have writtent the compile thats why at runtime your jar is not getting into the classpath.Remove the compile line.And it will work.
Util.jar is added to your app pom.xml as dependency but the scope is compile. So it is not getting added to your Manifest as classpath entry. Remove scope element and then try.
PROJECT-A is a war. It has some code I want to use in the unit tests of PROJECT-B.
To do this, I think I need PROJECT-A to output a jar with it's classes. Here is an excerpt of the POM:
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>au.com.name.redacted</groupId>
<artifactId>PARENT-PROJECT</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PROJECT-A</artifactId>
<packaging>war</packaging>
... snip
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>PROJECT-A-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
When I run
cd PROJECT-A
mvn clean install
it outputs
[INFO] --- maven-jar-plugin:2.4:jar (PROJECT-A-jar) # PROJECT-A ---
[INFO] Building jar: D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # PROJECT-A ---
[INFO] Installing D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar to C:\Users\myusername\.m2\repository\au\com\name\PARENT-PROJECT\PROJECT-A\1.0\PROJECT-A-1.0.war
I do see
D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar
D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.war
but I do not see the jar in in my repo - only the war.
C:\Users\myusername\.m2\repository\au\com\name\PARENT-PROJECT\PROJECT-A\1.0\PROJECT-A-1.0.war
So then in PROJECT-B I am attempting to have it get PROJECT-A as a dependency..
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>au.com.name.redacted</groupId>
<artifactId>PARENT-PROJECT</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PROJECT-B</artifactId>
<packaging>war</packaging>
... snip
<dependency>
<groupId>au.com.name.redacted</groupId>
<artifactId>PROJECT-A</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
And it fails with
[ERROR] Failed to execute goal on project PROJECT-B: Could not resolve dependencies for project au.com.name.redacted:PROJECT-B:war:1.0: Failure to find au.com.name.redacted:PROJECT-A:jar:1.0 in http://repo.server.com.au:8081/artifactory/repo was cached in the local repository, resolution will not be reattempted until the update interval of repo has elapsed or updates are forced -> [Help 1]
I've used war plugin for this purpose. Maybe this will help:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
It generates war and jar with sources after build which will be commited to local m2 repo. Configuration <attachClasses>true</attachClasses> is important.
In pom of project B use something like this (important part - <classifier>classes</classifier>):
<dependency>
<groupId>projectA-groupid</groupId>
<artifactId>projectA-artifactId</artifactId>
<version>projectA-version</version>
<classifier>classes</classifier>
</dependency>