I am running some unit tests within Eclipse and I am using Mockito to mock as follows:-
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
When I run the test from within Eclipse I get the following stack trace
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
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)
However I do not receive any such errors when run from the command line using maven
I have seen similar questions posted elsewhere and I have made sure I have the implementation jars and not just the API jars. My maven dependency is as follows
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
<version>10.0-b28</version>
<scope>test</scope>
</dependency>
I have spent way too much time on this, fiddling with my classpaths and cleaning my workspace multiple times but to no avail.
I just created a simple test:
#Test
public void test(){
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
System.out.println(request);
}
with my Helios eclipse and with dependency provided by you - everything works as expected, no exceptions.... You might have something else on your classpath in eclipse or the problem might come from a different line.
You can try checking which jar is used using (for example)
HttpServletRequest.class.getProtectionDomain().getCodeSource()
You could also consider using httpunit instead of mocking request.
Related
So I am trying to download files on a rackspace server to my local server. It is laid out here. For some odd reason, I am trying to make the initial call to the cloud and it is giving me some serious feedback. No idea where to go from here. I've tried all sorts of different Maven dependencies to fix the problem, but none have come close. Am I overlooking something? TIA!
My code:
public static void main (String[] args){
CloudFilesApi cloudFilesApi = ContextBuilder.newBuilder(PROVIDER)
.credentials(USERNAME, KEY)
.buildApi(CloudFilesApi.class);
}
And here are my errors (without Guice):
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Stage
at org.jclouds.ContextBuilder.<clinit>(ContextBuilder.java:151)
at com.unidev.download.Main.main(Main.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Stage
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)
... 2 more
Here are my dependencies (now):
<dependencies>
<!-- Rackspace US dependencies -->
<dependency>
<groupId>org.apache.jclouds.provider</groupId>
<artifactId>rackspace-cloudfiles-us</artifactId>
<version>${jclouds.version}</version>
</dependency>
Code snippet for dependency tree(updated): https://codeshare.io/bfbKg
I guess it is a Maven issue... When I was building the Maven project and using the dependencies via the pom file, it was somehow building incorrectly. Instead, I started a Java file and built a lib folder, pulled all the jars I needed and then just tied them in via the build path... and it is working well now...
I am getting up to speed with the FUSE and OSGi and trying to put together a simple blueprint test that should check a Camel route (written by another developer):
public class CamelBrokerTest extends CamelBlueprintTestSupport {
#Override
protected String getBlueprintDescriptor() {
return "OSGI-INF/blueprint/peoplesoft-service.xml";
}
#Test
public void testRoute() throws Exception {
MockEndpoint endpoint = getMockEndpoint("seda:peopleSoftFinanceSchedulerProcessInstances");
endpoint.expectedMessageCount(1);
template.sendBody("activemq:peopleSoftFinanceIncomingFiles", "TRANSACTION_INFO");
assertMockEndpointsSatisfied();
}
}
However, when I try to run it, I end up getting
Caused by: java.lang.ClassNotFoundException: ca.custom.camel.servlet.registry.CamelServletHTTPRegistry
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 40 more
The dependency containing the class is included in the POM file with the test scope:
<dependency>
<groupId>ca.custom</groupId>
<artifactId>camel-servlet-osgi</artifactId>
<version>${camel.servlet.osgi.version}</version>
<scope>test</scope>
</dependency>
And I verified that the file is in the repo, and actually contains the required files. It also looks like the generated OSGi bundle descriptor has the correct dependencies also:
Import-Package: ca.custom.camel.servlet.osgi;version="[1.1,2)",ca.
custom.camel.servlet.registry,ca.mcmaster.uts.service.directory.i
ntegration;version="[1.2,2)",javax.jws,javax.jws.soap,javax.net.ssl,jav
ax.security.auth.callback,javax.xml.bind,javax.xml.bind.annotation,java
This code seems to be running well in production, yet, fails when executed as a JUnit test. Any ideas as to why this exception might occur? Did I miss any configuration steps?
ClassNotFoundException is as far as I know the way of osgi to enforce you to use only packages and bundles that you have declared as dependencies in the manifest file so what I would check is the export packages of the bundle containing the class you are trying to use and see if it matches with the imports that you are using! Another thing is that the bundle you are trying to use might not be activated yet !
I'm using a library to make Wikipedia API calls, called the Java Wiki Bot Framework. I'm also using Maven for builds, and I've added the framework to the pom.xml just as the github page says. However, when I try to instantiate any of the classes in the library, it gives me this error:
Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/jwbf/core/actions/HttpActionClient
at com.FactFinder.WikiParser.makeBot(WikiParser.java:21)
at com.FactFinder.WikiParser.<init>(WikiParser.java:16)
at com.FactFinder.App.main(App.java:15)
Caused by: java.lang.ClassNotFoundException: net.sourceforge.jwbf.core.actions.HttpActionClient
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)
... 3 more
My pom.xml
Apparently this is an error that crops up when your jar can't find a class, but I've checked the classpath, and it looks fine. The jar is included in the proper folder, and I've verified that it includes the classes I tried to use. I considered contacting the library author, but I figured its probably more my problem than his.
Why are you using the Snapshot version 4.0.0-SNAPSHOT? I would strongly suggest to use a final version to avoid issues, of which 3.1.0 seems to be the latest and most popular one:
<dependency>
<groupId>net.sourceforge</groupId>
<artifactId>jwbf</artifactId>
<version>3.1.0</version>
</dependency>
[UPDATE]
Follow naming conventions; package name: com.factfinder (all lowercase). Fix in both your code, pom, and directory names.
Add the version for the maven-jar-plugin
Note that I tried using your pom - it seemed to work for me ...
Are you sure you don't get any other warnings or errors during your maven build? can you do a clean package?
Check line 53 of your POM:
<classpathPrefix>lib\</classpathPrefix>
Should be:
<classpathPrefix>lib/</classpathPrefix>
I'm struggling with a Java/Maven/Jetty problem that I can't solve.
I have a Java Jetty server that starts up correctly but as soon as an HTTP request is sent to it, it aborts showing this stacktrace:
2013-09-30 08:40:24,534 [qtp297240915-11 Selector0] WARN org.eclipse.jetty.io.nio - java.lang.SecurityException: class "javax.servlet.AsyncContext"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:806) ~[na:1.6.0_37]
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487) ~[na:1.6.0_37]
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:625) ~[na:1.6.0_37]
at java.lang.ClassLoader.defineClass(ClassLoader.java:615) ~[na:1.6.0_37]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) ~[na:1.6.0_37]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) ~[na:1.6.0_37]
at java.net.URLClassLoader.access$000(URLClassLoader.java:58) ~[na:1.6.0_37]
at java.net.URLClassLoader$1.run(URLClassLoader.java:197) ~[na:1.6.0_37]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_37]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) ~[na:1.6.0_37]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[na:1.6.0_37]
at org.eclipse.jetty.server.AbstractHttpConnection.<init>(AbstractHttpConnection.java:157) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.server.AsyncHttpConnection.<init>(AsyncHttpConnection.java:50) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.server.nio.SelectChannelConnector.newConnection(SelectChannelConnector.java:285) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newConnection(SelectChannelConnector.java:325) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.server.nio.SelectChannelConnector.newEndPoint(SelectChannelConnector.java:272) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newEndPoint(SelectChannelConnector.java:331) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.createEndPoint(SelectorManager.java:836) ~[jetty-io-7.6.5.v20120716.jar:7.6.5.v20120716]
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.doSelect(SelectorManager.java:491) ~[jetty-io-7.6.5.v20120716.jar:7.6.5.v20120716]
at org.eclipse.jetty.io.nio.SelectorManager$1.run(SelectorManager.java:285) [jetty-io-7.6.5.v20120716.jar:7.6.5.v20120716]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603) [jetty-util-8.1.3.v20120416.jar:8.1.3.v20120416]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538) [jetty-util-8.1.3.v20120416.jar:8.1.3.v20120416]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_37]
Clearly there is something odd going on within the jars included to run it, and in Google I could find some references to this problem but without a clear solution.
Anyway, the strangest thing is that the same application runs perfectly in another machine. To make sure that there were no differences between the two, I copied the directory of the project (including compiled classes, the maven dependencies jars, configuration files, etc) from the machine where it runs fine to the other where it doesn't. The error keeps showing up.
I've also deleted the maven local cache for the machine (~/.m2/), although it shouldn't matter. Java and Maven versions are the same in the two machines.
Clearly, there has to be some environment difference among the two but I don't know where else I should look for apart from the aspects I've just mentioned.
Any ideas?
EDIT: The project was including two conflicting versions of javax.servlet.servlet-api. Excluded the older one from the pom fixed the issue.
Either way, it remains to me a mystery why in one machine although both the jars were loaded (double checked with lsof) the server was running just fine. Maybe the order of the class loader was taken into consideration?
Blockquote
java.lang.SecurityException: class "javax.servlet.AsyncContext"'s signer information does not match signer information of other classes in the same package
This Exception thrown in my project too. At last i find out the solution. The exception thrown because of referring same dependency with different version. So the java code signature mess up with the dependency.
Add proper dependency
Check with dependency version
Avoid multiple dependency of same jar
javax.servlet
servlet-api 2.5
provided
Only one dependency is needed
You shouldn't need to exclude it; any reference to the servlet-api for a project that will be deployed in a container should use <scope>provided</scope> to ensure that only the container's version is present at runtime (how to add the servlet api to my pom.xml).
Hi I am working on Java & am using HtmlUnitDriver.I have created the object
`WebDriver webDriver = new HtmlUnitDriver(true);`
I am using selenium-htmlunit-driver-2.24.1.jar & selenium-java-2.24.1.jar.
When I run my code I am getting following exception.
Exception in thread "Thread-5" java.lang.NoClassDefFoundError: org/openqa/selenium/internal/FindsByCssSelector
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 java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Please guide me how to solve this issue.If there is jar for this Exception then which Jar should I use?
Make sure that all the relevant jars (such as package and library jars) are in the class path. Always make sure to clean and recompile the project once you copied jars.
[You can use a jar search engine to find jars of missing classes.][1]
[http://www.jarvana.com/jarvana/search?search_type=class&java_class=org.openqa.selenium.internal.FindsByCssSelector][1]
Note : It is always advisable to use jars from official release, because of possible compatibility issues due to version difference.