Junit through terminal [duplicate] - java

I used Intellij Idea 12 Community edition. I am trying to create test case for my class by creating test case. When i run my test case it says
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
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)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:44)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
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)
... 25 more
How would i run test case in Intellij. I included the junit4.11 jar file to my module

Did you include the hamcrest-core-1.3.jar file in your classpath? If not included means include that jar and try once again.

add junit.jar to your project dependence.
you may also need to add hamcrest.jar in addition.
Open File->Project Structure,Click Modules->Dependences,add junit.jar.

Latest version of hamcrest-all is available at:
https://search.maven.org/search?q=a:hamcrest-all
Download this version (as opposed to the hamcrest-core) and that should do it.

If you come across this (and a few other threads) on this error and adding the jar to dependencies doesn't work, you will need to add to the general java classpath.
I encountered this error in OSX where maven would download the dependency, but not find it when in fork mode.
Adding all the hamcrest jars to Library/Java/Extensions finally fixed the problem when nothing else would.

Related

java.lang.SecurityException: sealing violation: can't seal package com.sun.xml.bind: already loaded

Could anyone help me to resolve these error in my weblogic server.
Caused by: java.lang.SecurityException: sealing violation: can't seal package com.sun.xml.bind: already loaded
at java.net.URLClassLoader.defineClass(URLClassLoader.java:242)
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)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:295)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:293)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:146)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1169)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at com.sun.xml.ws.spi.ProviderImpl$2.run(ProviderImpl.java:235)
at com.sun.xml.ws.spi.ProviderImpl$2.run(ProviderImpl.java:232)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.ws.spi.ProviderImpl.getEPRJaxbContext(ProviderImpl.java:232)
at com.sun.xml.ws.spi.ProviderImpl.<clinit>(ProviderImpl.java:95)
Why this exception is generic by showing only package "package com.sun.xml.bind"?
Finally we found a solution to fix this by following the steps below,
1) There was an issue like java.lang.SecurityException: sealing violation: can't seal package com.sun.xml.bind: already loaded , but related jar jaxb-impl.jar was not found.
2) We took this jaxb-impl.jar and added in classpath and the flow as successful.
3) Such issue occurs when right set of jars are not loaded in the classpath or class existing in multiple jars.
We should try playing around with the jars related to package com.sun.xml.bind

Unable to create client using client.create() jersey rest api method. Trying to create issue in jira 6.3.5

I am getting the following exception :
java.lang.ClassFormatError: Absent Code attribute in method that is
not native or abstract in class file javax/ws/rs/core/MediaType
The logs are below:
java.lang.ClassLoader.defineClass(ClassLoader.java:621) 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) at
java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2484) at
java.lang.Class.getDeclaredMethods(Class.java:1827) at
com.sun.jersey.core.reflection.MethodList.getAllDeclaredMethods(MethodList.java:70) at
com.sun.jersey.core.reflection.MethodList.<init>(MethodList.java:64) at com.sun.jersey.core.spi.component.ComponentConstructor.getPostConstructMethods(ComponentConstructor.java:131) at
com.sun.jersey.core.spi.component.ComponentConstructor.<init>(ComponentConstructor.java:123) at
com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:165) at
com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:137)
at
com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:256)
at
com.sun.jersey.core.spi.component.ProviderServices.getServices(ProviderServices.java:160)
at
com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:176)
at
com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
at com.sun.jersey.api.client.Client.init(Client.java:342) at
com.sun.jersey.api.client.Client.access$000(Client.java:118) at
com.sun.jersey.api.client.Client$1.f(Client.java:191) at
com.sun.jersey.api.client.Client$1.f(Client.java:187) at
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:187) at
com.sun.jersey.api.client.Client.<init>(Client.java:159) at
com.sun.jersey.api.client.Client.create(Client.java:669)
See this article javaee-api
You maybe have transitive dependency of javaee-api in your project.

Trying to setup a cucumber-project in eclipse without using Maven

I am new to cucumber, I am trying to configure a Java-project without using Maven, I am having the following exception. I think there is an issue with the path of a .feature file
Exception:
java.lang.NoClassDefFoundError: cucumber/io/ResourceLoader
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2398)
at java.lang.Class.getConstructor0(Class.java:2708)
at java.lang.Class.getConstructor(Class.java:1659)
at cucumber.runtime.Utils.hasConstructor(Utils.java:30)
at cucumber.runtime.io.ClasspathResourceLoader.instantiateSubclasses(ClasspathResourceLoader.java:55)
at cucumber.runtime.Runtime.loadBackends(Runtime.java:81)
at cucumber.runtime.Runtime.<init>(Runtime.java:61)
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:59)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: cucumber.io.ResourceLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
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)
... 27 more
I have also attached the image of my project setup.
Any help will be awesome.
Thanks!
java.lang.NoClassDefFoundError: cucumber/io/ResourceLoader
this exception means that the class cucumber.io.ResourceLoader is not found in the classpath of your Project. Try to add the cucumber-core.jar to the classpath of your project following this eclipse documentation.
It would help if you could let us know what libraries you referenced in your project. cucumber-core is referenced by cucumber-java. So if you have cucumber-java, you don't need to have cucumber-core in your class path. Looking at your code, I notice you use #Cucumber.Options. This is deprecated in the latest release, so looks like you are not using latest release. Try using cucumber 1.1.5 jars.
Also any reason why aren't you using maven? Maven is supposed to make these things easier.

ANT throwing exception

My enviromental variables are set like this
ANT_HOME=c:\ant1.6
JAVA_HOME=c:jdk.16
And path includes both %JAVA_HOME%/bin and %ANT_HOME%/bin
Still when I execute ant -version from command prompt it thows an exception like below don't know why its doing that
java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/AntMain
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:14
1)
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 sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:244)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.AntMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 17 more
It seems ant-launcher.jar is missing from the classpath, which is a separate dependency from main ant.jar.

javac in command line with libraries and multiple files

I always used Eclipse to create complex java programs, but a single one is being tricky to solve:
javac -cp ../../mysql-connector-java-5.1.16-bin.jar:../../commons-cli-1.2-sources.jar *.java
I have some java classes on that directory and those java libraries to be ran with it.
when I run javac, it creates the .class files for me.
Now, when I run
java DbTool I get:
Exception in thread "main" java.lang.NoClassDefFoundError: DbTool (wrong name: tool/DbTool)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: DbTool. Program will exit.
any help?

Categories