XJC Maven Plugin(jaxb2-maven-plugin) Java 11 Migration Issues - java

I am currently working on java 11 migration project where jaxb2-maven-plugin has been used for XJC task. As XJC executable is not present in the JDK 11 version, I am getting below mentioned errors.
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc (xjc-schema1) on project paymaster-service: Execution xjc-schema1 of goal org.codehaus.mojo:jaxb2-maven-plugin:2.2
:xjc failed: A required class was missing while executing org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc: com/sun/codemodel/CodeWriter
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:jaxb2-maven-plugin:2.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/voletis/.m2/repository/org/codehaus/mojo/jaxb2-maven-plugin/2.2/jaxb2-maven-plugin-2.2.jar
[ERROR] urls[1] = file:/C:/Users/voletis/.m2/repository/javax/xml/bind/jaxb-api/2.2.11/jaxb-api-2.2.11.jar
[ERROR] urls[2] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-core/2.2.11/jaxb-core-2.2.11.jar
[ERROR] urls[3] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar
[ERROR] urls[4] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar
[ERROR] urls[5] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-jxc/2.2.11/jaxb-jxc-2.2.11.jar
[ERROR] urls[6] = file:/C:/Users/voletis/.m2/repository/com/thoughtworks/qdox/qdox/2.0-M3/qdox-2.0-M3.jar
[ERROR] urls[7] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[8] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[9] = file:/C:/Users/voletis/.m2/repository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar
[ERROR] urls[10] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar
[ERROR] urls[11] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[12] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[13] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[14] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-compiler-api/2.5/plexus-compiler-api-2.5.jar
[ERROR] urls[15] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[16] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-build-api/0.0.7/plexus-build-api-0.0.7.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] : com.sun.codemodel.CodeWriter
[ERROR] -> [Help 1]
[ERROR]
Below is my pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>xjc-schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<target>2.2</target>
<schemaFiles>SubmitPaymentBatch/SubmitPaymentRequest.xsd</schemaFiles>
<packageName>app.test.services.submitpayment.request</packageName>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</plugin>
I have added necessary dependencies like JAXB, JAXB-IMPL, etc., as per java 11 requirements. But still not able to fix the issues. Do you have any suggested fix for this ? Thank in Advance.

jaxb2-maven-plugin 2.5.0 is now compatible with Java 11:
https://github.com/mojohaus/jaxb2-maven-plugin/issues/43
https://github.com/mojohaus/jaxb2-maven-plugin/releases/tag/jaxb2-maven-plugin-2.5.0

I had issues with making jaxb working with maven and Java 11 too. My solution looks as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>de.powerstat.my.generated</packageName>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</plugin>
Hope this helps others.

I have fixed this issue by following below reference link.
https://github.com/davidmoten/jax-maven-plugin
As per the above tutorial reference, I have modified my plugin as below and i am able to fix this.
<plugin>
<groupId>com.github.davidmoten</groupId>
<artifactId>jax-maven-plugin</artifactId>
<version>VERSION_HERE</version>
<executions>
<execution>
<id>xjc-schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<target>2.2</target>
<schemaFiles>SubmitPaymentBatch/SubmitPaymentRequest.xsd</schemaFiles>
<packageName>app.test.services.submitpayment.request</packageName>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>

I've just found a workaround for problems with using jaxb2-maven-plugin with Java 11. It consists of adding extra dependencies in pom.xml and adding an extra, dummy XSD file to the project, next to proper XSD files. I've put it altogether in my blog-post here:
https://artofcode.wordpress.com/2019/02/26/jaxb2-maven-plugin-2-4-and-java-11/

I was able to solve the issue for JDK11 by adding all dependencies which are listed here: https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/pom.xml#L251-L290 which the apache.cxf project uses in their example projects starting for JDK9

Related

kapt not working with maven and dagger in mixed kotlin/java project

Kapt doesnt work with maven, if we dont use kapt and just use the maven compiler for java it generates dagger code perfectly fine, but the problem is that java compiles after kotlin compiles and kotlin gives and error because it can't use dagger components before they are created, so the solution would be to use kapt.
this is the plugin configuration
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<!-- Specify your annotation processors here. -->
<annotationProcessorPath>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.9</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.myanimelist/com.example.myanimelist.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and this is the error that gives
"C:\Program Files\BellSoft\LibericaJDK-17-Full\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList -Dmaven.home=C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4 -Dclassworlds.conf=C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=63596:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2022.1 compile
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.example:MyAnimeList >-----------------------
[INFO] Building MyAnimeList 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- kotlin-maven-plugin:1.6.21:kapt (kapt) # MyAnimeList ---
[WARNING] 'tools.jar' was not found, kapt may work unreliably
[WARNING] C:\Users\Roberto\.m2\repository\org\checkerframework\checker-compat-qual\2.5.5\checker-compat-qual-2.5.5.jar: (-1, -1) The root is ignored because a module with the same name 'org.checkerframework.checker.qual' has been found earlier on the module path at: C:/Users/Roberto/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-base\17.0.1\javafx-base-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.base' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-controls\17.0.1\javafx-controls-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.controls' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-fxml\17.0.1\javafx-fxml-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.fxml' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-graphics\17.0.1\javafx-graphics-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.graphics' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:12: error: cannot find symbol
#Component(modules = {FiltersModule.class})
^
symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:13: error: cannot find symbol
#Singleton
^
symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:13: error: cannot find symbol
#Component(modules = {RepositoriesModule.class})
^
symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:14: error: cannot find symbol
#Singleton
^
symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\AnimeDTO.java:13: error: cannot find symbol
#Data
^
symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\BackupDTO.java:12: error: cannot find symbol
#Data
^
symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\FiltersModule.java:12: error: incompatible types: Module cannot be converted to Annotation
#Module(includes = RepositoriesModule.class)
^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\RepositoriesModule.java:17: error: incompatible types: Module cannot be converted to Annotation
#Module
^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\LoginController.kt: (4, 46) Unresolved reference: DaggerControllersComponent
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\RegisterController.kt: (3, 46) Unresolved reference: DaggerControllersComponent
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.254 s
[INFO] Finished at: 2022-05-16T00:29:31+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.6.21:kapt (kapt) on project MyAnimeList: Compilation failure: Compilation failure:
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:12: error: cannot find symbol
[ERROR] #Component(modules = {FiltersModule.class})
[ERROR] ^
[ERROR] symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:13: error: cannot find symbol
[ERROR] #Singleton
[ERROR] ^
[ERROR] symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:13: error: cannot find symbol
[ERROR] #Component(modules = {RepositoriesModule.class})
[ERROR] ^
[ERROR] symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:14: error: cannot find symbol
[ERROR] #Singleton
[ERROR] ^
[ERROR] symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\AnimeDTO.java:13: error: cannot find symbol
[ERROR] #Data
[ERROR] ^
[ERROR] symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\BackupDTO.java:12: error: cannot find symbol
[ERROR] #Data
[ERROR] ^
[ERROR] symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\FiltersModule.java:12: error: incompatible types: Module cannot be converted to Annotation
[ERROR] #Module(includes = RepositoriesModule.class)
[ERROR] ^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\RepositoriesModule.java:17: error: incompatible types: Module cannot be converted to Annotation
[ERROR] #Module
[ERROR] ^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\LoginController.kt:[4,46] Unresolved reference: DaggerControllersComponent
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\RegisterController.kt:[3,46] Unresolved reference: DaggerControllersComponent
[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
Process finished with exit code 1
I have tried using older jdks versions but nothing changed

Unable to build with dependencies with a maven project

Hi Everyone hope you're doing fine.
So I'm new to Maven.
I've created a maven project #Apache NetBeans IDE 13, java JDK 17.02 and Apache tomcat server 9.0.
And every time I try to build with dependencies I'm getting this particular error,"Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project ECommerceWebsite: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.3' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null".
I've spent hours trying to fix this error. Trying to fix with some of the previous users who had asked this question.
I deleted the .m2 folder but still it's giving the same error after re-building.
So I need advice how I can fix this error.
here is the error I've been receiving.
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project ECommerceWebsite: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.3' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null
-----------------------------------------------------
realm = plugin>org.apache.maven.plugins:maven-war-plugin:2.3
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/Mritunjay/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.3/maven-war-plugin-2.3.jar
urls[1] = file:/C:/Users/Mritunjay/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
urls[2] = file:/C:/Users/Mritunjay/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
urls[3] = file:/C:/Users/Mritunjay/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar
urls[4] = file:/C:/Users/Mritunjay/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
urls[5] = file:/C:/Users/Mritunjay/.m2/repository/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar
urls[6] = file:/C:/Users/Mritunjay/.m2/repository/org/codehaus/plexus/plexus-io/2.0.5/plexus-io-2.0.5.jar
urls[7] = file:/C:/Users/Mritunjay/.m2/repository/org/codehaus/plexus/plexus-archiver/2.2/plexus-archiver-2.2.jar
urls[8] = file:/C:/Users/Mritunjay/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.15/plexus-interpolation-1.15.jar
urls[9] = file:/C:/Users/Mritunjay/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[10] = file:/C:/Users/Mritunjay/.m2/repository/com/thoughtworks/xstream/xstream/1.4.3/xstream-1.4.3.jar
urls[11] = file:/C:/Users/Mritunjay/.m2/repository/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar
urls[12] = file:/C:/Users/Mritunjay/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar
urls[13] = file:/C:/Users/Mritunjay/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.8/plexus-utils-3.0.8.jar
urls[14] = file:/C:/Users/Mritunjay/.m2/repository/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar
Number of foreign imports: 1
import: Entry[import from realm ClassRealm[maven.api, parent: null]]
-----------------------------------------------------
: ExceptionInInitializerError: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module #4391a2d8
-> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
and here is pom.xml file
<?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.mycompany</groupId>
<artifactId>ECommerceWebsite</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ECommerceWebsite</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Update the plugins, according to https://maven.apache.org/plugins/, it worked perfectly for me.

Maven: package com.sun.istack.internal does not exist

I have little maven project that uses com.sun.istack.internal.Nullable.
I tried both JDK 9 and 1.8, and still get error about package does not exists.
I search for the package and find some: https://mvnrepository.com/search?q=+com.sun.istack but they still not supply necessary one.
The JAVA_HOME:
apshenichnikov#IAS-WS-UX02:~/NetBeansProjects/newlps$ echo $JAVA_HOME
/usr/local/java/jdk1.8.0_121/
And JDK:
apshenichnikov#IAS-WS-UX02:~/NetBeansProjects/newlps$ sudo update-alternatives --config java
There are 4 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-oracle/bin/java 1091 auto mode
1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
2 /usr/lib/jvm/java-9-oracle/bin/java 1091 manual mode
* 3 /usr/local/java/jdk1.8.0_121/ 1 manual mode
4 /usr/local/java/jdk1.8.0_121/bin/java 1 manual mode
Press <enter> to keep the current choice[*], or type selection number:
And the 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.beinteractive</groupId>
<artifactId>newlps</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>newlps</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.code.externalsortinginjava</groupId>
<artifactId>externalsortinginjava</artifactId>
<version>0.1.9</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
I injected:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
Inside the POM.xml
And I still have compilation exception
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.286 s
[INFO] Finished at: 2017-12-13T15:28:45+03:00
[INFO] Final Memory: 20M/261M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project newlps: Compilation failure: Compilation failure:
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/ParamUtils.java:[3,31] package com.sun.istack.internal does not exist
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/StringUtils.java:[3,31] package com.sun.istack.internal does not exist
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/ParamUtils.java:[36,74] cannot find symbol
[ERROR] symbol: class Nullable
[ERROR] location: class su.ias.utils.ParamUtils
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/ParamUtils.java:[46,68] cannot find symbol
[ERROR] symbol: class Nullable
[ERROR] location: class su.ias.utils.ParamUtils
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/StringUtils.java:[19,36] cannot find symbol
[ERROR] symbol: class Nullable
[ERROR] location: class su.ias.utils.StringUtils
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/StringUtils.java:[45,6] cannot find symbol
[ERROR] symbol: class Nullable
[ERROR] location: class su.ias.utils.StringUtils
[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
Try import import org.jetbrains.annotations.Nullable instead. It has the same you need for #Nullable annotation.
Then add this dependency:
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
</dependency>

Error while parsing POM

I am trying to integrate Browserstack with jenkins, using maven to build java code for testing.
However when I run the Job I got this errors and pretty much crashes the build and next steps.
[WARNING] The POM for org.codehaus.mojo:aspectj-maven-plugin:jar:1.8 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
that leads to the next errors what I think are related:
[ERROR] Failed to execute goal com.browserstack:automate-maven-plugin:0.7.2-SNAPSHOT:test-compile (default) on project NewTest: Execution default of goal com.browserstack:automate-maven-plugin:0.7.2-SNAPSHOT:test-compile failed: A required class was missing while executing com.browserstack:automate-maven-plugin:0.7.2-SNAPSHOT:test-compile: org/apache/commons/lang/StringUtils
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>com.browserstack:automate-maven-plugin:0.7.2-SNAPSHOT
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/com/browserstack/automate-maven-plugin/0.7.2-SNAPSHOT/automate-maven-plugin-0.7.2-SNAPSHOT.jar
[ERROR] urls[1] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[2] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[3] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar
[ERROR] urls[4] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar
[ERROR] urls[5] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[6] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[7] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[8] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/codehaus/plexus/plexus-utils/3.0.24/plexus-utils-3.0.24.jar
[ERROR] urls[9] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/codehaus/mojo/aspectj-maven-plugin/1.8/aspectj-maven-plugin-1.8.jar
[ERROR] urls[10] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/org/aspectj/aspectjtools/1.8.7/aspectjtools-1.8.7.jar
[ERROR] urls[11] = file:/var/lib/jenkins/workspace/testbrowserstack/.repository/com/browserstack/automate-testassist/0.7.2-SNAPSHOT/automate-testassist-0.7.2-SNAPSHOT.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: org.apache.commons.lang.StringUtils
[ERROR] -> [Help 1]
Here is my pom file which also uses the right version of the openjdk:
<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>NewTest</groupId>
<artifactId>NewTest</artifactId>
<version>0.1-Unittest</version>
<dependencies>
<!--
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>automate-testassist</artifactId>
<version>0.7.2-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.browserstack</groupId>
<artifactId>automate-maven-plugin</artifactId>
<version>0.7.2-SNAPSHOT</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<complianceLevel>1.8</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
No sure what would be the issue.
The culprit here is automate-maven-plugin used by you. The error message as well clearly reads this
[ERROR] Failed to execute goal
com.browserstack:automate-maven-plugin:0.7.2-SNAPSHOT:test-compile
(default) on project NewTest: Execution default of goal
com.browserstack:automate-maven-plugin:0.7.2-SNAPSHOT:test-compile
failed: A required class was missing while executing
com.browserstack:automate-maven-plugin:0.7.2-SNAPSHOT:test-compile:
org/apache/commons/lang/StringUtils
Also trying to use the 0.7.2-SNAPSHOT of automate-maven-plugin along with specifying the same pluginRepositories wouldn't work in general. Seems like you are locally building and using this. So probably you can go ahead and update the plugin possibly.

Scala/Java Project not finding Dependencies during Maven compile

I have a Java/Scala hybrid project. When building in Intellij, things work fine. However, trying to run Maven builds from command line is giving me this error when running 'mvn clean install':
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:12: error: object model is not a member of package com.test.userlib
[ERROR] import com.test.userlib.model.cte.{ItemResponse, CteUser}
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:13: error: object utils is not a member of package com.test.userlib
[ERROR] import com.test.userlib.utils.UserLibProperties
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:26: error: not found: value UserLibProperties
[ERROR] .hosts(UserLibProperties.CTE_USERSERVICE_HOST + ":" + UserLibProperties.CTE_USERSERVICE_PORT)
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:32: error: not found: value UserLibProperties
[ERROR] ClientAuthTlsConfigUtil.createSslContext(new File(UserLibProperties.CTE_USERSERVICE_KEYSTORE),UserLibProperties.CTE_USERSERVICE_KEYSTORE_PASSWORD,new File(UserLibProperties.CTE_USERSERVICE_TRUSTSTORE),UserLibProperties.CTE_USERSERVICE_TRUSTSTORE_PASSWORD)
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:35: error: not found: type CteUser
[ERROR] protected def getUser(dn :String) :CteUser = {
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:36: error: not found: value UserLibProperties
[ERROR] val rb = RequestBuilder().url(s"${UserLibProperties.CTE_USERSERVICE_ENDPOINT}/user?dn=${URLEncoder.encode(dn,"utf-8")}&aacAttribs=true").buildGet
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:42: error: not found: type ItemResponse
[ERROR] case HttpResponseStatus.OK => new ObjectMapper().readValue(respTry.get.getContent.toString("UTF-8"), classOf[ItemResponse]).getItem.getUser
[ERROR] ^
[ERROR] 7 errors found
So, clearly my Scala class isn't finding the Java dependencies it needs. Here's my project's structure:
And here is the build portion of my pom.xml:
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Do I have to add the classpath to the Scala compiler somehow?
I think UserLibProperties file should be in proper file extension UserLibProperties.scala. Please check you folder and do a list command and check for file extensions, in Intelij it will work without proper extension.
I think, SBT is best way to build a hybrid project.
For example:
https://github.com/databricks/learning-spark/blob/master/build.sbt
It has little learning curve, but worth to invest time in SBT.

Categories