Java Web Application Failed to run as maven project - java

I am new to java . I am using apache netbeans 12.2 version to create new project and the java version is 17 . I followed the step to create java web application with maven but when I build it and try to run it I am getting following errors in the console window.
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project JavaProject: 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 checked in pom.xml file the required dependency already there , But why it not able to run?.
Here is the Pom.xml code .
<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>JavaProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>JavaProject-1.0-SNAPSHOT</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<jakartaee>8.0</jakartaee>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${jakartaee}</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.8</source>
<target>1.8</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-api</artifactId>
<version>${jakartaee}</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here is the entire console with error message.
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project JavaProject: 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:/Users/mohammadhossan/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.3/maven-war-plugin-2.3.jar
urls[1] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
urls[2] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
urls[3] = file:/Users/mohammadhossan/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar
urls[4] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
urls[5] = file:/Users/mohammadhossan/.m2/repository/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar
urls[6] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-io/2.0.5/plexus-io-2.0.5.jar
urls[7] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-archiver/2.2/plexus-archiver-2.2.jar
urls[8] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.15/plexus-interpolation-1.15.jar
urls[9] = file:/Users/mohammadhossan/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[10] = file:/Users/mohammadhossan/.m2/repository/com/thoughtworks/xstream/xstream/1.4.3/xstream-1.4.3.jar
urls[11] = file:/Users/mohammadhossan/.m2/repository/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar
urls[12] = file:/Users/mohammadhossan/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar
urls[13] = file:/Users/mohammadhossan/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.8/plexus-utils-3.0.8.jar
urls[14] = file:/Users/mohammadhossan/.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 #73bb1337
-> [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

Your version of Java is incompatible with your version of NetBeans because NetBeans 12.2 does not support the use of JDK 17. From the NetBeans 12.2 Release notes Downloading Apache NetBeans 12.2:
Apache NetBeans 12.2 runs on JDK LTS releases 8 and 11, as well as on
JDK 15, i.e., the current JDK release at the time of this NetBeans
release.
In general, when changing your version of NetBeans and/or Java, make sure that the versions are compatible. This is always documented in the NetBeans release notes.
You have two options to resolve this:
Upgrade to NetBeans 12.6 which supports Java 17.
Stay on NetBeans 12.2, but downgrade to Java 15 or lower. That is, make JDK 15 (or lower) your default platform for NetBeans 12.2.
Of course you may also have other issues with your project, but there is no point in worrying about those until you have fixed this problem.

Related

Could not find artifact jdk.tools

I am migrating my code from Java 1.8 to Java 11. I have done the below change in my pom.xml
From:
<java.version>1.8</java.version>
To:
<java.version>11</java.version>
Also changed the source and target in maven compiler as per below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
When I execute the command maven install I get the below error:
[ERROR] Failed to execute goal on project store: Could not resolve dependencies for project. Could not find artifact jdk.tools:jdk.tools:jar:1.7 at specified path C:\Program Files\Java\jdk-11.0.12/../lib/tools.jar -> [Help 1]
How do I solve this error? Please help

java.lang.UnsupportedClassVersionError org/sonar/batch/bootstrapper/EnvironmentInformation

sonarQube9.0.1 CE(Java 11 ) + pgsql (docker install) 。 my project is Java 8
when i excute mvn sonar:sonar,my project failed
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:sonar-maven-plugin:3.9.0.2155
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/D:/project/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.0.2155/sonar-maven-plugin-3.9.0.2155.jar
[ERROR] urls[1] = file:/D:/project/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
by the way, sonarqube9 needs java 11 means my project also needs java 11?
You can use Java 11 compiler to produce Java 8 code. The configuration could be set on the maven-compiler-plugin, you can see an example below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${jdk.console.version}</release>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
Where ${jdk.console.version} would be 1.8 in case you want compile to be executed in a JRE 8

gwt-maven-plugin failing on gwt-app

I am having problems with getting the gwt-maven-plugin working as the docs have stated.
using GWT 2.8.2
using InteliJ 2018
Start with a sample project generated from the 2.8.2 webAppCreator with the templates maven,sample, readme.
That basic project has packaging set to war
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>org.gwtproject.tutorial</groupId>
<artifactId>TodoList</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>org.gwtproject.tutorial.TodoList</name>
The gwt-maven-plugin is set to 1.0-rc-8
<!-- GWT Maven Plugin-->
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0-rc-8</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleName>org.gwtproject.tutorial.TodoList</moduleName>
<moduleShortName>TodoList</moduleShortName>
<failOnError>true</failOnError>
<!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use
a different source language for java compilation -->
<sourceLevel>1.8</sourceLevel>
<!-- Compiler configuration -->
<compilerArgs>
<!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
<arg>-compileReport</arg>
<arg>-XcompilerMetrics</arg>
</compilerArgs>
<!-- DevMode configuration -->
<warDir>${project.build.directory}/${project.build.finalName}</warDir>
<classpathScope>compile+runtime</classpathScope>
<!-- URL(s) that should be opened by DevMode (gwt:devmode). -->
<startupUrls>
<startupUrl>TodoList.html</startupUrl>
</startupUrls>
</configuration>
</plugin>
At this point I can run in DEV mode. Once I change the packaging to gwt-app ( per the plugin's docs https://tbroyer.github.io/gwt-maven-plugin/usage.html) it fails.
[ERROR] Unknown packaging: gwt-app # line 9, column 14
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.gwtproject.tutorial:TodoList:1.0-SNAPSHOT (D:\ToDoList\pom.xml) has 1 error
[ERROR] Unknown packaging: gwt-app # line 9, column 14
[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]
Any idea as to the issue?
thanks
You're probably missing the <extensions>true</extensions> in the plugin.
Be aware that a gwt-app is only client code, with no server-side at all. I'd suggest using https://github.com/tbroyer/gwt-maven-archetypes instead of the webAppCreator as a starting point. The modular-webapp archetype is functionally identical to the sample project generated by the webAppCreator, but in a more Maven-oriented setup.

Maven sonar misconfiguration, maybe missing source directory?

When I do a mvn clean package locally everything works fine. When I do a mvn clean package on the jenkins server I get errors. I am running Jenkins 1.596, Maven 3.2.5, SonarQube 4.5.1, Maven plug-in 2.4 is defined in the Jenkins sonar settings.
This is the output from the Jenkins job.
[INFO] --- sonar-maven-plugin:2.4:sonar (default-cli) # myproject ---
[INFO] SonarQube version: 4.5.1
INFO: Work directory: /var/lib/jenkins/workspace/myporject/target/sonar
[INFO] [22:48:12.147] Base dir: /var/lib/jenkins/workspace/myproject
[INFO] [22:48:12.148] Working dir: /var/lib/jenkins/workspace/myproject/target/sonar
[INFO] [22:48:12.148] Source paths: src
[INFO] [22:48:12.148] Test paths: src/test/java
[INFO] [22:48:12.148] Binary dirs: target/classes
[INFO] [22:48:12.148] Source encoding: UTF-8, default locale: en_US
[INFO] [22:48:12.148] Index files
[ERROR] File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project myproject: File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project myproject: File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
It appears that something is missing from my Sonar plug-in settings but I'm not sure what or where to define it.
Here are some snippets from my 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>com.blah</groupId>
<artifactId>myproject</artifactId>
<version>99</version>
<packaging>war</packaging>
<name>myproject</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<routePath>${pom.project.build.directory}/routes</routePath>
<spring.release.version>3.2.4.RELEASE</spring.release.version>
<rabbitmq.version>3.1.4</rabbitmq.version>
<spring.amqp.version>1.2.0.RELEASE</spring.amqp.version>
</properties>
<build>
<finalName>myproject</finalName>
<sourceDirectory>src</sourceDirectory>
<scriptSourceDirectory>src/main/java</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.8.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.1.8-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>GROOVY_DSL_SUPPORT</classpathContainer>
</classpathContainers>
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/integration/**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem seems to be that your source folder is a prefix of your test folder. In other words, if you say that your test folder is src/test/java/, your source folder should be src/main/java, not src since this causes the plugin to find the same class twice, which is what causes the error
Removing <sourceDirectory>src</sourceDirectory> should do the trick since it will use maven's default (src/main/java). While you're at it, remove also testSourceDirectory since you are setting it to the default value, so you don't need it. In general the pom should be as simple as possible since maven is all about convention over configuration

Maven Plugin Build fails when Lambdas are used

I wrote a maven plugin/mojo to generate some code. The plugin works well, and is built in Java JDK 1.8.
I am seeing an odd bit of behavior though: It builds, installs, etc just fine if I use pre-1.8 syntax, but as soon as I use a Java 8 Lambda expression, I get the following error when executing mvn clean install:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project my-maven-plugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 13557 -> [Help 1]
Here's my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.group.id</groupId>
<artifactId>my-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Maven Mojo</name>
<url>http://maven.apache.org</url>
<properties>
<org.springframework.version>4.0.1.RELEASE</org.springframework.version>
<joda-time.version>2.3</joda-time.version>
</properties>
<dependencies>
<!-- several dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- The following manual call to the maven-plugin plugin is necessary to get around a bug in maven 3.1.1.
If the build server gets updated to 3.2.2+ we can remove this -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>inin-release</id>
<name>ININ Release Repository</name>
<url>http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-release</url>
</repository>
<snapshotRepository>
<id>inin-snapshot</id>
<name>ININ Snapshot Repository</name>
<url>http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-snapshot</url>
</snapshotRepository>
</distributionManagement>
</project>
The issue appears in this case when I attempt to use a lambda to define a FileFilter rather than the traditional anonymous inner class.
This works:
List<File> controllerFiles = Arrays.asList(packageDirFile.listFiles(new FileFilter()
{
#Override
public boolean accept(File file)
{
return file.isFile() && file.getName().endsWith(".java");
}
}));
While this produces the aforementioned error:
List<File>
controllerFiles =
Arrays.asList(packageDirFile.listFiles(file -> file.isFile() &&
file.getName().endsWith(".java")));
Obviously given that I have a workaround this isn't critical, but the lambda is much cleaner than the anonymous inner class IMO and given that I'm working in Java 8 I'd much prefer to use it. Anybody have any tips, particularly given that I've already set skipErrorNoDescriptorsFound to true?
The note on MPLUGIN-273 says lambdas work if the build is using maven-plugin-plugin version 3.3. The error message shown references maven-plugin-plugin version 3.2 . Make sure you're using the correct version of the plugin and see if that fixes the issue.
I just realized I answered my own question. In my second comment there's a link to a Maven Jira issue, in which somebody commented that upping the maven-plugin-plugin version to 3.3 from 3.2 fixes the issue, and after trying it I discovered the same. So this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
...
</plugin>
becomes
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.3</version>
...
</plugin>
And the problem goes away.

Categories

Resources