Solving groovy module version conflict - java

How to solve groovy module (groovy-xml) version conflict?
The version 2.4.12 is what my currently project depends on, however, groovysh somehow preload a higher version:
$ groovysh
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:111)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:129)
Caused by: java.lang.ExceptionInInitializerError
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:88)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:82)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:277)
at org.apache.groovy.groovysh.Main.main(Main.groovy:74)
... 6 more
Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-xml is loaded in version 3.0.7 and you are trying to load version 2.4.12
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$DefaultModuleListener.onModule(MetaClassRegistryImpl.java:510)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromProperties(ExtensionModuleScanner.java:87)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromMetaInf(ExtensionModuleScanner.java:81)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModulesFrom(ExtensionModuleScanner.java:63)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModules(ExtensionModuleScanner.java:55)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:125)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:86)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:37)
... 12 more
More info, this is Mac, and groovy is installed by brew install groovy, and there is no GROOVY related environment variables created:
$ env | grep GROOVY | wc
0 0 0

I suggest to use skdman to manage your Groovy installations, this will create the GROVY_HOME env variable for you, the other way is to find the location of your groovy installation and create a GROVY_HOME env pointing to bin location inside Groovy folder.

Pay attention to the fact that when you install groovy, the installer creates an environment variable called "GROOVY_HOME". To resolve your conflict you should remove the 3.0.7 as the default version in your environment.
EDIT ( see OP comment )
In case the above solution doesn't work for you, here is another way:
Edit the project's build.gradle to force gradle load your suitable version of groovy :
configurations.all { resolutionStrategy { force 'org.codehaus.groovy:groovy-all: 2.4.12' } }

Related

Modded mc server not booting up, Reason unknown

So Im having an issue booting up a modded mc server installation using forge 1.12.2.
The reason is unknown but I've had this issue before. All I've heard was to reinstall Java, even though I have done that multiple times.
Here is what my directory looks like:
This is stored inside c:desktop/server. Here is the server boot code: java -Xmx1024M -jar forge-universal.jar nogui.
Here is the error, I cannot understand what any of it means, and there is no offical minecraft crash log:
A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70)
at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34)
Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
... 6 more
You seems to be on Java 16. You can check with java -version.
Forge 1.12 can't be runned with this version of Java. So, I suggest you to :
Install older version such as Java 8.
Change boot code to C:\Dir\To\Jre\java.exe -Xmx1024M -jar forge-universal.jar nogui
OR change JAVA_PATH variable to the Java 8 JRE instead of Java 16's one.

How can I fix NoClassDefFoundError when using Spring framework's WebSocketClient

I am writing a desktop Java application as a web service client. I want to use WebSocket to implement notification "callback" from the server.
I am using the Spring framework's WebSocketStompClient. Below snippet shows how I initialize it:
import org.springframework.web.socket.messaging.WebSocketStompClient;
import org.springframework.web.socket.sockjs.client.SockJsClient;
import org.springframework.web.socket.sockjs.client.Transport;
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
...
List<Transport> transports = new ArrayList<>();
transports.add(new WebSocketTransport(new StandardWebSocketClient()));
stompClient = new WebSocketStompClient(new SockJsClient(transports));
...
It works perfectly if I run it in IntelliJ IDE, however, if I run by command line "java -cp my.jar MyPackage.MyMainClass", it will fail with the following message:
Error: Unable to initialize main class MyMainClass
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/socket/client/WebSocketClient
The above was produced by Java SE 12.0.2. If I run it using Java SE 1.8, the error message will be:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/springframework/web/socket/client/WebSocketClient
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Both java.lang.NoClassDefFoundError and getDeclaredMethods0(Native Method) suggsted that a native module (a DLL) is missing.
Below is my Gradle script:
dependencies {
implementation project(':logman-common')
implementation 'org.springframework:spring-web:5.2.2.RELEASE'
implementation 'org.springframework:spring-websocket:5.2.2.RELEASE'
implementation 'org.springframework:spring-messaging:5.2.2.RELEASE'
... // other unrelated dependencies, such as GUI
}
I don't think it was due to some missing JARs. I tried:
to add tyrus-standalone-client to the dependency list, or
to use StandardWebSocketClient instead of SockJsClient,
but the error remained.
I guess some native libraries are missing in my OS (Win10), but that can't explain why I can run it in IntelliJ...
Could you let me know what is missing? or how can I fix this? Thanks!
Try to create a fat jar which contains all the dependencies and classes.
Update build.gradle script to this given below :
apply plugin: 'java'
version = '...'
sourceCompatibility = 1.8
targetCompatibility = 1.8
// to create a fat jar.
jar {
manifest {
attributes "Main-Class": "MyPackage.MyMainClass"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
dependencies {
implementation project(':logman-common')
implementation 'org.springframework:spring-web:5.2.2.RELEASE'
implementation 'org.springframework:spring-websocket:5.2.2.RELEASE'
implementation 'org.springframework:spring-messaging:5.2.2.RELEASE'
... // other unrelated dependencies, such as GUI
}
It will generate an executable fat jar in the build/libs of your root project which will include all the project files (this includes all of your dependencies, resource files, .class files and so on).
Note: For older versions of Gradle, use this configurations.compile.collect instead of configurations.runtimeClasspath.collect.
You just need to run the jar with this command : java -jar <project-version>.jar
This should solve your problem.
The error message reads, that a JNI error has occurred, so this indeed is related to native assembly (you could debug with LLDB). While I think that library might require Java EE and won't run on Java SE; likely it's the same with Tyrus and other JSR 356 implementations. Either switch to another WebSocket implementation, which is known to work with desktop Java SE or write your own; the WebSocket HBYI protocol isn't that difficult; Java SE 11 even has a WebSocket.Builder.

java.lang.NoSuchFieldException error from jacoco

I am trying to run the tests of the kotlin code provided from here : https://github.com/ligi/ipfs-api-kotlin with gradlew
I got the error listed below.
Could someone tell me what this error means ?
> Task :test FAILED
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/lang/UnknownError could not be instrumented.
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_c13123e.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_c13123e.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.base/java.lang.Class.getField(Class.java:1999)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at line: 422
I was missing the following from my build.gradle:
jacoco {
toolVersion = "0.8.6"
}
While obvious, build.gradle can inherit properties from other gradle files and for reasons I can't figure out, jacoco was passing through in to one subproject but not to another.
Ensure you are using JDK-11,
if using maven, ensure;
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Ensure you are using latest jacoco.
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
Fixed this error changing Java SDK in my project from 14 to 11 and my tests started working fine.
Solution:
IntellijIDEA: File > Project Structure > Project Tab > SDK adopt-opendjdk-11 (in my case for Ubuntu).
Oh! Make sure Gradle Settings are also using the same JVM!
Hope that helps someone out there.
The issue comes from the Java version which needs not to be too recent.
sdk install java 19.3.0.2.r8-grl
makes things ok.
After followed below steps it's working fine for me.
In Eclipse,Go to Window--Preferences--java.Right-click on installed JRE. There add an installed JDK path & remove others.
I had similar issue when I upgraded my jdk1.8 to openjdk11 but it was solved by updating the toolVersion = "0.8.6" (used toolVersion = "0.8.1" with jdk1.8)
Fix in my case was to download and install Java 8 (jdk1.8.0_301) and set it in Project Settings

Unable to run Grails 2.1 with path set to Java 6

I have an application that's built in grails 2.1
My environment variables are set to point to JAVA 8 and Grails 3.8 along with the path.
I am aware of the fact that grails 2.1 has support upto Java 6. But I donot want to make changes to my environment variables in order to make it point to Java 6. So I tried to set home and path for java 6 and grails 2.1 via command line. I was successful in doing so and echoe %JAVA_HOME%, %GRAILS_HOME% and %PATH% did show that values were set correctly. Trying to run the app with grails run-app command from under the project's root directory throws below error :
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/grails/cli/GrailsCli : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.grails.cli.GrailsCli. Program will exit.
I tried to write a batch script that would set the %JAVA_HOME%, %GRAILS_HOME% and %PATH% to Java 6 and Grails 2.1 specific locations and then execute "grails run-app" from under the project's root directory, but while executing the script I got the same above error.
Below is how my batch script looks like:
set JAVA_HOME=C:\Softwares\Java\Java-6\jdk1.6.0_41
set PATH=%PATH%;%JAVA_HOME%\bin
set GRAILS_HOME=C:\Softwares\Grails\Grails_2.1.0
set PATH=%PATH%;%GRAILS_HOME%\bin
cd /D C:\MyWorkspace\MyApplication
grails run-app
REM pause
I have never written a batch script before.So, please correct me where possible.
Also, as for some restrictions in place I do not have the freedom of installing SDKMan.
Any guidance in this regard is greatly appreciated.
It seems you have to set environment variable in front of the existing PATH setting:
set PATH=%JAVA_HOME%\bin;%PATH%;
This will lookup at the first match (the wanted version)}
Also, make sure you are using the exact same version of compile

Error Running Hbase Java API

Successfully compiled my Hbase class using
javac -cp "/hbase/lib/*" CreateTable.java
But during running it is throwing error
java CreateTable
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
at CreateTable.main(CreateTable.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
javac -cp `hbase classpath` CreateTable.java
java -cp `hbase classpath` CreateTable
where hbase classpath is cluster classpath where cluster has installed hbase jar files
If you want to see folder location of your hbase/lib,
you can go to hbase shell and try your hbase lib jars will be displayed there.
Note : if you are using maven for your build then you have to set 'provided' as scope where you are mentioning groupid, artifactid etc...
In addition to specifying the classpath of libraries you're depending on in order to compile your program, you need to specify them when executing your program. The dependencies aren't "compiled-in", they're just referenced during compilation to ensure that they're linked correctly, but they need to be there at runtime as well.
So, you probably want to run something like java -cp ".;/hbase/lib/*" CreateTable in order to have the same libraries at runtime as you used at compile time, as well as the current directory where your complied .class file is.
In enterprise programs, usually a dependency management system like Maven, or at least what's built into most IDEs, is used to help keep track of the dependencies and call Java and related tools with the right paths.

Categories