RuntimeException during maven build of Java 9 spring boot application - java

The Java 9 application I am building compiles and works well from IntelliJ IDE. On IDE, I have tried configuring as both Spring Boot application as well as plain Application and both configuration work well.
While executing maven build, I encounter RuntimeException with below stacktrace.
Caused by: java.lang.RuntimeException
at org.springframework.asm.ClassVisitor.visitModule(ClassVisitor.java:148)
at org.springframework.asm.ClassReader.readModule(ClassReader.java:762)
at org.springframework.asm.ClassReader.accept(ClassReader.java:663)
at org.springframework.asm.ClassReader.accept(ClassReader.java:527)
at org.springframework.boot.loader.tools.MainClassFinder.createClassDescriptor(MainClassFinder.java:267)
at org.springframework.boot.loader.tools.MainClassFinder.doWithMainClasses(MainClassFinder.java:223)
at org.springframework.boot.loader.tools.MainClassFinder.findSingleMainClass(MainClassFinder.java:203)
at org.springframework.boot.loader.tools.Repackager.findMainMethod(Repackager.java:365)
at org.springframework.boot.loader.tools.Repackager.findMainMethodWithTimeoutWarning(Repackager.java:354)
at org.springframework.boot.loader.tools.Repackager.buildManifest(Repackager.java:325)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:255)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:248)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:193)
at org.springframework.boot.maven.RepackageMojo.repackage(RepackageMojo.java:221)
at org.springframework.boot.maven.RepackageMojo.execute(RepackageMojo.java:208)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 22 more
On analyzing, its being caused because of the ASM api level provided. With direct execution, it is org.springframework.asm.Opcodes#ASM6, but when using maven build it is Opcodes#ASM4 which is causing the issue.
Further analysis reveals that the instances are created as below -
Maven Build - https://github.com/spring-projects/spring-boot/blob/d3c34ee3d1bfd3db4a98678c524e145ef9bca51c/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java#L301
IDE Execution - https://github.com/spring-projects/spring-framework/blob/43b5e21947f3ad9682ae39cd8b8b5ae4b8f72c14/spring-core/src/main/java/org/springframework/core/type/classreading/ClassMetadataReadingVisitor.java#L71
Let me know if I need to report this as an issue with Spring Framework or if any workarounds exist.
Maven Version: 3.5.0
Spring Boot: 2.0.0.M5
Its a modular build and POM files are here: https://gist.github.com/techpavan/faa81d46321004cd50e7403b03d70a2e
A simpler reproducer is available here - https://github.com/techpavan/java9-maven-spring-boot
With this reproducer, you can find that maven build fails readily. But when put a breakpoint at org.springframework.asm.ClassVisitor > line 78 (Constructor) and update the api value during execution to 393216 (ASM6), you'll find that the build completes successfully. By default the value is set to 262144 (ASM4) which fails at line 147.
Update: The issue is accepted as bug by Spring community and should be fixed in Milestone 6 release - https://github.com/spring-projects/spring-boot/issues/10647
Update: The issue is fixed in the spring-boot master branch on Oct 17, 2017. Should be a part of M6 release.

Your mvn dependency:tree describes it as follows:-
➜[main] [INFO] +- org.springframework.boot:spring-boot-starter-jetty:jar:2.0.0.M5:compile
[main] [INFO] | +- org.eclipse.jetty:jetty-servlets:jar:9.4.7.v20170914:compile
[main] [INFO] | | +- org.eclipse.jetty:jetty-continuation:jar:9.4.7.v20170914:compile
[main] [INFO] | | +- org.eclipse.jetty:jetty-http:jar:9.4.7.v20170914:compile
[main] [INFO] | | +- org.eclipse.jetty:jetty-util:jar:9.4.7.v20170914:compile
[main] [INFO] | | \- org.eclipse.jetty:jetty-io:jar:9.4.7.v20170914:compile
[main] [INFO] | +- org.eclipse.jetty:jetty-webapp:jar:9.4.7.v20170914:compile
[main] [INFO] | | +- org.eclipse.jetty:jetty-xml:jar:9.4.7.v20170914:compile
[main] [INFO] | | \- org.eclipse.jetty:jetty-servlet:jar:9.4.7.v20170914:compile
[main] [INFO] | | \- org.eclipse.jetty:jetty-security:jar:9.4.7.v20170914:compile
[main] [INFO] | | \- org.eclipse.jetty:jetty-server:jar:9.4.7.v20170914:compile
[main] [INFO] | +- org.eclipse.jetty.websocket:websocket-server:jar:9.4.7.v20170914:compile
[main] [INFO] | | +- org.eclipse.jetty.websocket:websocket-common:jar:9.4.7.v20170914:compile
[main] [INFO] | | | \- org.eclipse.jetty.websocket:websocket-api:jar:9.4.7.v20170914:compile
[main] [INFO] | | +- org.eclipse.jetty.websocket:websocket-client:jar:9.4.7.v20170914:compile
[main] [INFO] | | | \- org.eclipse.jetty:jetty-client:jar:9.4.7.v20170914:compile
[main] [INFO] | | \- org.eclipse.jetty.websocket:websocket-servlet:jar:9.4.7.v20170914:compile
[main] [INFO] | | \- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[main] [INFO] | +- org.eclipse.jetty.websocket:javax-websocket-server-impl:jar:9.4.7.v20170914:compile
[main] [INFO] | | +- org.eclipse.jetty:jetty-annotations:jar:9.4.7.v20170914:compile
[main] [INFO] | | | +- org.eclipse.jetty:jetty-plus:jar:9.4.7.v20170914:compile
➜[main] [INFO] | | | +- org.ow2.asm:asm:jar:5.1:compile
[main] [INFO] | | | \- org.ow2.asm:asm-commons:jar:5.1:compile
[main] [INFO] | | | \- org.ow2.asm:asm-tree:jar:5.1:compile
This clearly reflects that the dependency on spring-boot-starter-jetty for your project relies on asm:5.1 and the version of asm is not compatible with the latest Java release. You can try upgrading to 6.0_BETA version of it.
To what I got to know from this issue, jetty didn't upgrade to the latest version because of its incompatibility with OSGI version number. I'd faced that issue while trying to make vaadin8 application work with Java 9 wherein the solution I could achieve was to build jetty locally and then use a custom version in my project as stated in the answer -
This was attained after overcoming the #jetty.project/1758 by
upgrading to the 6.0_BETA of asm and asm-commons libraries and using
the custom 9.4.7-SNAPSHOT built on my local used in the project(commit
- #e34415.)
Update: This indeed is a bug in spring-boot milestone as confirmed in the edited question as well.

Thanks to wilkinsona on GitHub whose workaround helped me on this issue. Just adding a spring-boot-maven-plugin configuration with mainClass entry can solve this problem on M5 release. Expected to have a proper fix on M6.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
+ <configuration>
+ <mainClass>com.test.TestMain</mainClass>
+ </configuration>
</plugin>

Related

How do I upgrade the MongoDB driver in a Kogito Quarkus project?

I'm new to Kogito and Quarkus, so help me a little bit here.
Our application has been recently affected by this bug:
https://jira.mongodb.org/browse/JAVA-4018
Now I want to upgrade the Mongo DB driver version to use the version with the fix but I'm not sure where do I need to do that.
I see these two in the pom.xml:
<project>
...
<dependencies>
...
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-client</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-persistence-mongodb</artifactId>
</dependency>
</dependencies>
</project>
But I'm not sure if I should look for the driver referenced by these dependencies and then add the version tag for any of them...
Can you point me the direction where I need to look to upgrade the driver version?
Which Kogito version are you using? The latest Kogito Quarkus version already uses the latest MongoDB driver:
[INFO] ----< org.kie.kogito.examples:process-mongodb-persistence-quarkus >-----
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # process-mongodb-persistence-quarkus ---
[INFO] org.kie.kogito.examples:process-mongodb-persistence-quarkus:jar:2.0.0-SNAPSHOT
[INFO] +- org.kie.kogito:kogito-addons-quarkus-persistence-mongodb:jar:2.0.0-SNAPSHOT:compile
[INFO] | +- org.kie.kogito:kogito-addons-persistence-mongodb:jar:2.0.0-SNAPSHOT:compile
[INFO] | \- io.quarkus:quarkus-mongodb-client:jar:2.13.0.Final:compile
[INFO] | +- org.mongodb:mongodb-driver-sync:jar:4.7.1:compile
[INFO] | | +- org.mongodb:bson:jar:4.7.1:compile
[INFO] | | \- org.mongodb:mongodb-driver-core:jar:4.7.1:compile
[INFO] | | \- org.mongodb:bson-record-codec:jar:4.7.1:runtime
[INFO] | +- org.mongodb:mongodb-driver-reactivestreams:jar:4.7.1:compile
[INFO] | \- org.mongodb:mongodb-crypt:jar:1.5.2:compile
[INFO] | | +- org.testcontainers:mongodb:jar:1.17.3:test
Can you try upgrading to Kogito 1.27.0.Final?
MongoDB 4.7.1 includes the fix you're looking for.

Maven dependencies available in one project but not another

I have two projects that use identical pom files (one project is an earlier version of the second). The second project compiles fine and allows me to use all the dependencies defined in the pom in my project. However the first project does not, and it appears as though the dependencies are not even recognized by the project.
I looked in my local .m2 folder and see that the dependencies have been downloaded in their respective folders. I even see the mvn install output says it has included the dependency, e.g.:
Including com.fasterxml.jackson.core:jackson-core:jar:2.9.6 in the shaded jar.
And later...
com.fasterxml.jackson.core:jackson-databind:jar:2.9.6 already exists in destination.
I've tried mvn clean and the dependency is still not recognized. I've tried examining the contents of all of the pom files in the project and I can't see any difference between the two projects.
I'm convinced that there is something wrong with my project, but I'm not a maven expert. Any ideas of where to look for the problem?
Here's an example of one of the dependencies that is not recognized:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
Here is my mvn dependency:tree ouput
[INFO] SwirldsProxy:SwirldsProxy:jar:0.0.1-SNAPSHOT
[INFO] +- SwirldsPlatform:platform:jar:0.0.1-SNAPSHOT:compile
[INFO] | +- SwirldsPlatform:fc:jar:0.0.1-SNAPSHOT:compile
[INFO] | | +- SwirldsPlatform:fcfs:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | +- SwirldsPlatform:fcutil:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | | +- SwirldsPlatform:abcl-swirlds:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | | +- org.abcl:abcl-contrib:jar:1.4.0:compile
[INFO] | | | | +- org.apache.derby:derby:jar:10.12.1.1:compile
[INFO] | | | | \- org.beanshell:bsh:jar:2.0b5:compile
[INFO] | | | \- SwirldsPlatform:fcfs-dep-fasl:jar:0.0.1-SNAPSHOT:compile
[INFO] | | +- SwirldsPlatform:fcdb:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | \- SwirldsPlatform:fcdb-dep-fasl:jar:0.0.1-SNAPSHOT:compile
[INFO] | | \- junit:junit:jar:3.8.2:compile
[INFO] | +- com.offbynull.portmapper:portmapper:jar:2.0.4:compile
[INFO] | | +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] | | +- commons-io:commons-io:jar:2.5:compile
[INFO] | | \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] | +- org.slf4j:slf4j-nop:jar:1.7.21:compile
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.7:compile
[INFO] | \- org.apache.logging.log4j:log4j-core:jar:2.7:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] +- com.google.code.gson:gson:jar:2.4:compile
[INFO] +- com.rabbitmq:amqp-client:jar:4.0.2:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] \- com.github.davidmoten:flatbuffers-java:jar:1.6.0.2:compile
Apache Maven 3.5.0 Maven
Java version: 1.8.0_144-1-redhat
UPDATE 8/30/2018
So I discovered some interseting behavior. My project location was under D:\SomeDirectory. I tried moving it to C:\AnotherDirectory and performed mvn install and bingo, the dependencies were now available to my project.
I'm assuming this has something to do with the maven/java installation location, however I find it strange that I saw no errors when trying to run the maven commands, even when the project was under a different root directory (D:) compared to maven/java (C:).
Any ideas?

Maven brings "test" transitive dependency as "compile"

When I run "mvn dependency:tree" for my project it shows the following:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # xxxxx ---
[INFO] com.xxx.xxx:xxxxx:war:3.1.0-SNAPSHOT
...
[INFO] +- commons-configuration:commons-configuration:jar:1.5:compile
[INFO] | \- commons-beanutils:commons-beanutils-core:jar:1.7.0:compile
[INFO] +- org.seleniumhq.selenium:selenium-api:jar:2.34.0:test
[INFO] | +- com.google.guava:guava:jar:14.0:test
[INFO] | \- org.json:json:jar:20080701:test
[INFO] +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.34.0:test
[INFO] | +- org.seleniumhq.selenium:selenium-remote-driver:jar:2.34.0:test
[INFO] | | +- cglib:cglib-nodep:jar:2.1_3:test
[INFO] | | +- net.java.dev.jna:jna:jar:3.4.0:test
[INFO] | | \- net.java.dev.jna:platform:jar:3.4.0:test
[INFO] | \- net.sourceforge.htmlunit:htmlunit:jar:2.12:test
[INFO] | +- org.apache.commons:commons-lang3:jar:3.1:test
[INFO] | +- org.apache.httpcomponents:httpmime:jar:4.2.3:test
[INFO] | +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.12:test
[INFO] | +- xerces:xercesImpl:jar:2.10.0:test
>>>[INFO] | | \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.18:test
[INFO] | +- net.sourceforge.cssparser:cssparser:jar:0.9.9:test
[INFO] | | \- org.w3c.css:sac:jar:1.3:test
[INFO] | \- org.eclipse.jetty:jetty-websocket:jar:8.1.9.v20130131:test
[INFO] +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.34.0:test
...
As you see on the marked line, the xml-apis has "compile" scope, and as result it is packed into .war file. Why could it happen?
More interestingly it happens only while Java5 is used, for Java6 the dependency appears as "test".
Maven version: 3.0.4
Study the output of the following Maven command.
mvn -X dependency:tree -Dverbose
That should tell you why Maven upgraded the scope from test to compile.
If you take a look at xercesImpl it contains a dependency to xml-apis:xml-apis:jar:1.4.01:compile with the scope compile so the display of dependency plugin is correct. The usage of -Dverbose will do things as written in the docs:
Whether to include omitted nodes in the serialized dependency tree.
Apart from the above a test dependency as in your case is never being packaged into a war file.
There must be an other source of the same dependency which causes the packaging into the war
Furthermore the change in behaviour in relationship with adding explicit xml-apis to your pom is a supplemental evidence for this.
I had a similar problem.
In my case an entry in the dependencyManagement of a parent pom set the scope of the dependent artefact to compile. Actually I omitted the scope tag which effectively is the same as setting it to compile. Changing it to provided helped.
Seems the scope in dependencyManagement takes precedence over the transitive scope. Which makes sense but can still cause confusion when all you wanted to do is define the version.
It was actually not hard to spot: Looking at the effective-pom showed the dependencyManagement entry.

Spring 4.0.0 + Eclipse + Maven + WAS8.0 = ClassNotFoundException: org.springframework.asm.commons.EmptyVisitor

I followed http://www.codejava.net/frameworks/spring/creating-a-spring-mvc-project-using-maven-and-eclipse-in-one-minute to get a basic Spring MVC skeleton set up. That worked right out of the box running on WAS8.0. We use Spring 4.0.0.RELEASE here, so I went into the pom.xml and changed the spring version to 4.0.0.RELEASE, and now the app no longer works. Browsing to the webpage gives
Error 500: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet
And examining the error in the Eclipse console: http://fpaste.org/107837/07216414/
My current pom.xml (only file that has changed from the tutorial) http://fpaste.org/107880/02080310/
The only change made was changing the spring.version to 4.0.0.RELEASE.
Contents of /WEB-INF/lib
aopalliance-1.0.jar
commons-logging-1.1.1.jar
spring-aop-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar
Output of mvn dependency:tree:
com.redacted.test:Spring4MVCTest2:war:0.0.1-SNAPSHOT
+- org.springframework:spring-context:jar:4.0.0.RELEASE:compile
| +- org.springframework:spring-aop:jar:4.0.0.RELEASE:compile
| \- org.springframework:spring-expression:jar:4.0.0.RELEASE:compile
+- org.springframework:spring-webmvc:jar:4.0.0.RELEASE:compile
| \- org.springframework:spring-web:jar:4.0.0.RELEASE:compile
+- org.springframework:spring-core:jar:4.0.0.RELEASE:compile
| \- commons-logging:commons-logging:jar:1.1.1:compile
+- org.springframework:spring-beans:jar:4.0.0.RELEASE:compile
+- org.springframework:spring-orm:jar:4.0.0.RELEASE:compile
| +- aopalliance:aopalliance:jar:1.0:compile
| +- org.springframework:spring-jdbc:jar:4.0.0.RELEASE:compile
| \- org.springframework:spring-tx:jar:4.0.0.RELEASE:compile
+- org.springframework:spring-test:jar:4.0.0.RELEASE:test
+- javax.servlet:servlet-api:jar:2.4:provided
\- javax.servlet.jsp:jsp-api:jar:2.1:provided
http://fpaste.org/107879/08026714/
Any assistance would be greatly appreciated, thanks!

Class 'XXX/XXX/XXX ' is not accessible through the ClassLoader warning in Sonar analysis with Jenkins build and maven project

I know it's recurent question but I couldn't find a solution to my issue.
In JENKINS, I run a SONAR analysis after the build. When Soanar gets to Java bytecode scan... it displays : WARN - Class '.../.../.../...' is not accessible through the ClassLoader.
The scan is on a Maven project, and Sonar keeps displayin this message throw many other classes that uses Maven dependancies.
The Sonar analysis is using the SONAR-RUNNER.
I saw in many posts, that the issue could be fixed by adding sonar.librairies=/path/to/libraries/*jar in the sonar-project.properties but with Maven , dependancies are not grouped under one folder. Jar's are dispatched under different folders under the maven-repositories.
So how can I fix this issue to scan my code without these warnings ?
FYI :
Jenkins 1.555
Sonar 4.2
Sonar Runner 2.3
Java 1.7
Maven 3.04
Stack Trace :
09:23:55.605 INFO - Java bytecode scan...
09:23:55.646 WARN - Class 'org/springframework/context/ApplicationContext' is not accessible through the ClassLoader.
09:23:55.656 WARN - Class 'com/mongodb/MongoClient' is not accessible through the ClassLoader.
09:23:55.657 WARN - Class 'com/mongodb/DB' is not accessible through the ClassLoader.
09:23:55.661 WARN - Class 'org/springframework/context/ApplicationContext' is not accessible through the ClassLoader.
09:23:55.662 WARN - Class 'org/springframework/context/ApplicationContext' is not accessible through the ClassLoader.
...
09:23:55.749 WARN - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
09:23:55.773 INFO - Java bytecode scan done: 168 ms
Edit :
Running mvn dependency:tree in jenkins build :
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli)
[INFO] +- org.springframework:spring-context:jar:4.0.3.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.0.3.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-beans:jar:4.0.3.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:4.0.3.RELEASE:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] | \- org.springframework:spring-expression:jar:4.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.0.3.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:4.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.0.3.RELEASE:test
[INFO] +- org.apache.poi:poi:jar:3.9:compile
[INFO] | \- commons-codec:commons-codec:jar:1.5:compile
...
...
[INFO] +- org.mockito:mockito-all:jar:1.9.5:test
[INFO] +- com.jayway.jsonpath:json-path:jar:0.9.1:test
[INFO] | \- net.minidev:json-smart:jar:1.2:test
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:test
[INFO] \- junit:junit:jar:4.11:test (scope not updated to compile)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Thanks
Since Maven lists the missing classes, you're probably using the Jenkins plugin to run Sonar. I never used this plugin but my guess is that it doesn't know about Maven. Therefore, it can't create a classpath from the POM and the classes are really missing when it runs.
Try to run Sonar using the Maven goal: mvn sonar:sonar after configuring the Sonar plugin for Maven correctly.

Categories