I'm newbie with Mockito and trying to lean from Here,
All configuration I have done (Using Win-10) which mentioned in the tutorial.
Setting in Environment variable :
Mockito version :
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
<scope>test</scope>
</dependency>
I've started with the example mentioned in the same. but while I do run the test my class it shows below exception :
Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/Mockito
at com.mockitotest.PortfolioTester.setUp(PortfolioTester.java:23)
at com.mockitotest.PortfolioTester.main(PortfolioTester.java:14)
Caused by: java.lang.ClassNotFoundException: org.mockito.Mockito
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
I don't know what went wrong here. Can someone help me ?
The scope test indicates that the dependencies (binary files) are only used using maven's test phase. They are not delivered with the final target jar though. So if you run tests yourself (rather than letting maven do it), you'd better leave the default runtime scope, as follows:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
</dependency>
As a note I got this in the following situation.
A depends on B. B has a "compile" dependency on Mockito, and uses Mockito in its "normal source code".
A has a dependency on B, and on Mockito.
And then that same message "NoClassDefFound org.mockito.Mockito".
Turns on B's pom's "dependency on Mockito" was inheriting "test" from a parent. Apparently this "more local dependency" overrides the other one.
Making it problematic to share Mockito as a non-test dependency. Unless it's always and only used for unit tests, then it'll be available.
Related
I was trying out Log4j2 so I created a Java project in eclipse. My code is same as Log4j2 Manual Automatic Configuration part. I have added log4j-api-2.17.2.jar and log4j-core-2.17.2.jar in the classpath. When I run the application I get following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
at demo.one.MainClass.<clinit>(MainClass.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
I have checked some related questions but didn't find those useful.
In case you use maven, make sure to include Log4j core to the project:
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.18.0</version>
</dependency>
Since, it's a NoClassDefFoundError, that means your JRE is not able to find out the necessary jar(class) artifact holding definition for org.apache.logging.log4j.LogManager.
Look for differences between build and runtime classpaths.
I have both dependency in my quarkus app:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-client</artifactId>
</dependency>
and
<dependency>
<groupId>org.amqphub.quarkus</groupId>
<artifactId>quarkus-qpid-jms</artifactId>
</dependency>
before I've added quarkus-oidc-client everything worked fine.
After add application is working, but it doesn't build to native image, because I have error:
Error: Unsupported features in 2 methods
Detailed message:
Error: Class initialization of io.netty.handler.proxy.Socks5ProxyHandler failed. Use the option --initialize-at-run-time=io.netty.handler.proxy.Socks5ProxyHandler to explicitly request delayed initialization of this class.
Original exception that caused the problem: java.lang.NoClassDefFoundError: io/netty/handler/codec/socksx/v5/Socks5InitialRequest
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1042)
at jdk.unsupported/sun.misc.Unsafe.ensureClassInitialized(Unsafe.java:698)
at jdk.internal.vm.compiler/org.graalvm.compiler.serviceprovider.GraalUnsafeAccess.ensureClassInitialized(GraalUnsafeAccess.java:77)
at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.ensureClassInitialized(ConfigurableClassInitialization.java:178)
at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.computeInitKindAndMaybeInitializeClass(ConfigurableClassInitialization.java:648)
at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.computeInitKindAndMaybeInitializeClass(ConfigurableClassInitialization.java:131)
at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.shouldInitializeAtRuntime(ConfigurableClassInitialization.java:159)
at com.oracle.svm.hosted.SVMHost.isInitialized(SVMHost.java:308)
at com.oracle.graal.pointsto.meta.AnalysisType.isInitialized(AnalysisType.java:723)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.maybeEagerlyInitialize(BytecodeParser.java:4435)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genNewInstance(BytecodeParser.java:4633)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genNewInstance(BytecodeParser.java:4622)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genNewInstance(BytecodeParser.java:4617)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5422)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3477)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.handleBytecodeBlock(BytecodeParser.java:3437)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3282)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1145)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:84)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:81)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:212)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
at com.oracle.graal.pointsto.flow.AnalysisParsedGraph.parseBytecode(AnalysisParsedGraph.java:132)
at com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:616)
at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:163)
at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:321)
at com.oracle.graal.pointsto.flow.MethodTypeFlow.createTypeFlow(MethodTypeFlow.java:293)
at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureTypeFlowCreated(MethodTypeFlow.java:282)
at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:103)
at com.oracle.graal.pointsto.DefaultAnalysisPolicy$DefaultSpecialInvokeTypeFlow.onObservedUpdate(DefaultAnalysisPolicy.java:363)
at com.oracle.graal.pointsto.flow.TypeFlow.notifyObservers(TypeFlow.java:490)
at com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:559)
at com.oracle.graal.pointsto.PointsToAnalysis$2.run(PointsToAnalysis.java:595)
at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:188)
at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:172)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.ClassNotFoundException: io.netty.handler.codec.socksx.v5.Socks5InitialRequest
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 45 more
Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: io.netty.handler.proxy.Socks5ProxyHandler.<init>(java.net.SocketAddress, java.lang.String, java.lang.String). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time.
Trace:
at parsing io.vertx.core.net.impl.ChannelProvider.lambda$handleProxyConnect$2(ChannelProvider.java:205)
Call path from entry point to io.vertx.core.net.impl.ChannelProvider.lambda$handleProxyConnect$2(int, ProxyType, String, String, VertxInternal, SocketAddress, Handler, SocketAddress, String, boolean, boolean, Promise, AsyncResult):
at io.vertx.core.net.impl.ChannelProvider.lambda$handleProxyConnect$2(ChannelProvider.java:193)
at io.vertx.core.net.impl.ChannelProvider$$Lambda$1798/0x00000007c1c35c40.handle(Unknown Source)
at io.vertx.core.impl.WorkerContext.lambda$execute$2(WorkerContext.java:104)
at io.vertx.core.impl.WorkerContext$$Lambda$1637/0x00000007c1bf9c40.run(Unknown Source)
at java.lang.Thread.run(Thread.java:829)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:600)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
I was trying exclusions in dependency:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-client</artifactId>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-haproxy</artifactId>
</exclusion>
</exclusions>
</dependency>
but it didn't change anything, so I've tried exclusions in similiar way for quarkus-qpid-jms: netty-codec-http, netty-codec-http2, netty-codec, and every 3 in the same build, but always is the same situation (sometimes is Unsupported features in 3 methods).
Has someone had this situation?
What could I do with that?
Edit:
I use quay.io/quarkus/centos-quarkus-maven:21.3.2-java11 to build it in Dockerfile
EDIT: Just realised it's caused by a ClassNotFoundException, would still like some help.
I'm trying to update keycloak from version 12.0.3 to version 13.0.0, however when I make that change I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/jsontype/PolymorphicTypeValidator
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructors(Class.java:1651)
at org.jboss.resteasy.util.PickConstructor.pickSingletonConstructor(PickConstructor.java:30)
at org.jboss.resteasy.spi.ResteasyProviderFactory.createConstructorInjector(ResteasyProviderFactory.java:2821)
at org.jboss.resteasy.spi.ResteasyProviderFactory.createProviderInstance(ResteasyProviderFactory.java:2813)
at org.jboss.resteasy.spi.ResteasyProviderFactory.addMessageBodyReader(ResteasyProviderFactory.java:1048)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1821)
at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:3026)
at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.register(ResteasyClientBuilder.java:559)
at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.register(ResteasyClientBuilder.java:48)
at org.keycloak.admin.client.Keycloak.newRestEasyClient(Keycloak.java:71)
at org.keycloak.admin.client.Keycloak.<init>(Keycloak.java:53)
at org.keycloak.admin.client.KeycloakBuilder.build(KeycloakBuilder.java:147)
at socsan.myapp.v1.mymodule.keycloak.KeycloakUserManager.createKeycloakInstance(KeycloakUserManager.java:187)
at socsan.myapp.v1.mymodule.keycloak.KeycloakUserManager.<init>(KeycloakUserManager.java:36)
at socsan.myapp.v1.mymodule.mymodule.startServices(mymodule.java:51)
at socsan.myapp.common.lifecycle.ProcessStarter.runStartupTasks(ProcessStarter.java:61)
at socsan.myapp.common.lifecycle.ProcessStarter.start(ProcessStarter.java:48)
at socsan.myapp.v1.mymodule.mymodule.main(mymodule.java:34)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 20 more
I tried updating the fasterxml databind package too, but it didn't make any difference.
I noticed that the path to the correct jar in the maven repository is different to the path in the error.
In the maven repository there are stored at com/fasterxml/jackson/core/databind.
Does that have any baring on the issue?
How can I fix this?
EDIT 2:
In the parent pom we have this:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.8</version>
</dependency>
The only change made to the module pom was to increase the version as stated above.
looking at the dependency analyser for jackson-databind it does look a bit of a mess, I should also point out that we're using the maven shade plugin:
I've developed some code that executes a quartz job.At first the code was outside the tomcat and it executes very well, but when I tried to embed the same code inside a web application I get java.lang.NoClassDefFoundError: org/quartz/DisallowConcurrentExecution.
I'm using quartz 2.1.5 and it's already in the class path.
Here is the stack trace:
Exception in thread "DefaultQuartzScheduler_QuartzSchedulerThread" java.lang.NoClassDefFoundError: org/quartz/DisallowConcurrentExecution
INFO: Illegal access: this web application instance has been stopped already. Could not load org.quartz.DisallowConcurrentExecution. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
at org.quartz.impl.JobDetailImpl.isConcurrentExectionDisallowed(JobDetailImpl.java:390)
java.lang.IllegalStateException
at org.quartz.simpl.RAMJobStore.acquireNextTriggers(RAMJobStore.java:1447)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1273)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
Caused by: java.lang.ClassNotFoundException: org.quartz.DisallowConcurrentExecution
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.quartz.impl.JobDetailImpl.isConcurrentExectionDisallowed(JobDetailImpl.java:390)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.quartz.simpl.RAMJobStore.acquireNextTriggers(RAMJobStore.java:1447)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264)
make sure you have only 1 quartz-all-.jar in your classpath (maybe you have 2 : 1 in Tomcat lib folder + 1 in your war)
NoClassDefFoundErrors point to a missing JAR or class on the classpath. In this case the problem is likely that in Tomcat you have quartz-<ver>.jar on your classpath when you actually need quartz-all-<ver>.jar.
for them who use maven can use the new version by add
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.1.7</version>
</dependency>
It should be keep the .jar file inside of the project location. Import .jar file from the outside from the location which the project have is the reason for getting this error. also verified that if the project is a maven project, then it should include the maven dependency in the pom.xml to add the dependency to the project
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org</groupId>
<artifactId>quartz_job</artifactId>
<version>2.2.1</version>
</dependency>
Trying to use log4j's built-in JMSAppender to log messages to a local message queue (ActiveMQ).
I set up a test Driver that has an entry main method and that just instantiates the actual class I want to make the connection:
Driver.java:
public static void main(String[] args) {
Log4jAmqBridge bridge = new Log4jAmqBridge();
bridge.run();
}
Log4jAmqBridge.java:
public void run() {
// ...
}
If I leave my run method totally empty (no instructions) and run the Driver, I just get an empty console (Eclipse). But the second I add the following constructor to run():
JMSAppender appender = new JMSAppender();
I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSException
at test.jmsappender.Log4jAmqBridge.run(Log4jAmqBridge.java:11)
at test.Driver.main(Driver.java:11)
Caused by: java.lang.ClassNotFoundException: javax.jms.JMSException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
I checked the javadoc and it doesn't look like the JMSAppender no-arg constructor throws an exception.
Does anybody know whats going on?
Edit:
I am actually using Maven to manage my dependencies and have included the following dependency declarations in my pom:
<dependency>
<scope>compile</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<scope>compile</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
Which puts the following jars under the Maven Dependencies in my project (which are also added to the Eclipse workbench classpath):
slf4j-api-1.6.4
slf4j-log4j12-1.6.4
log4j-1.2.16
Thanks in advance!
Log4jAmqBridge depends on the JMS API.
Add this dependency to your pom.xml :
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
It should solve your problem.