Im using jdk1.8.0_191, jre1.8.0_191 and apache-maven-3.6.2.
I have a pretty big open liberty / maven project that uses the javax.xml.bind maven library :
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>
The problem occurs on one pc, not on the other. The javax.xml.bind.*; is rendered different on the different computers causing compilation errors , for example im trying to use the class
JAXBContext.newInstance(Class.class)
which works fine on one computer since the method that i can peek definition is as follows:
public static JAXBContext newInstance( Class... classesToBeBound )
throws JAXBException {
return newInstance(classesToBeBound,Collections.<String,Object>emptyMap());
}
But on my ohter pc the class method is rendered like :
public static javax.xml.bind.JAXBContext newInstance(java.lang.String pPath) throws javax.xml.bind.JAXBException {
return null;
}
This causes compilation error like
The method newInstance(String) in the type JAXBContext is not applicable for the arguments (Class<FormObject>)
Also the JAXContext.class file in the none working one has the comment above
// Failed to get sources. Instead, stub sources have been generated by the disassembler.
// Implementation of methods is unavailable.
, and the one that is working has a bunch of documentation.
There's more bugs from the javax.xml.bind.*; lib like that javax.xml.bind.Marshaller for instance. Ive tried to do mvn clean install but nothing seems to fix this issue!
Related
I have developed an Azure Serverless Function in Eclipse.
The function works locally (Run As/Maven/Set Goals=test) but does not work once deployed.
It fails with the following error
[Error] Executed 'Functions.HttpExample' (Failed, Id=0de9ae96-68c6-4620-ba05-63a1c1c99b97,
Duration=24ms)
Result: FailureException: NoClassDefFoundError:
javax/servlet/http/HttpServletStack: java.lang.reflect.InvocationTargetExceptionat
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at
I can see from looking at the code that it is failing at the following line.
boolean tokenVerified = RecaptchaVerification.verifyRecaptchaSite(token);
This is the first line in the code that references a class not in Function.java
Here is the structure of the code in Eclipse
I have used WinSCP and the publish profile credentials to examine what has been deployed.
Everything is there
Does anybody know how to solve this problem?
I could put all the code into Function.java and this would work, but I would prefer to solve this properly. (Incidentally the same issue happened to me when I did development in Visual Studio Code)
UPDATE:
I tried the following also - but to no avail.
I tried running on Java 11 instead of Java 8 (with appropriate changes to the pom.xml file) and trying different versions of FUNCTIONS_EXTENSION_VERSION.
I made sure the artifactID was different from the functionAppName, and that both were in lowercase.
I tried updating the javax.servlet version in pom.xml
I assumed that because the first call to classes outside of function.java failed, all others would fail as well. However the problem was peculiar to RecaptchaVerification.java.
The class that I tried to call looked like this.
public class RecaptchaVerification extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final String SECRET_PARAM = "xxx";
private static final String RESPONSE_PARAM = "xxxx";
If I removed the extends HttpServlet then everything works. Note that I do not know why this solves the problem - I do not think that I should have known this from the error message of NoClassDefFoundError.
(In retrospect I should have posted the code to RecaptchaVerification.java as well in my question)
Currently trying to use Junit to create some concurrency tests to run in Jmeter
My current project Structure looks like this
From RasterTest.java, I'm trying to call a method in CommonMethods.java and a method in SetUp.java.
When I run this as a JUnit Test in eclipse, the methods in CommonMethods and SetUp are called and everything works fine. When I export this to a JAR and run the same in Jmeter, I get an error given below (getProperty is a method inside SetUp )
Trace -- java.lang.NoSuchMethodError: utils.SetUp.getProperty
I couldn't find any resources, hence i thought this maybe due to the methods being static, but i tried accessing the method by creating an object too. That Didn't help, got the same error.
Attaching the class CommonMethods for reference :
public class CommonMethods {
public String getProperty (String key) {
// Some code
}
public void setUrl() {
System.out.println("Hello world");
}
}
Calling it as :
CommonMethods cm = new CommonMethods();
System.out.println(cm.getProperty("URL"));
cm.setUrl();
I don't understand why Jmeter throws this error and how do i get around it? Thanks!
Hope you are using jpgc-perfmon-2.1. If not zip that into jmeter and then remove plugin cmn jar file from lib and update jmeter-plugins-cmn-jmeter.jar file with the latest version.
Seems like its kind of configuration issue.
I am referencing PlayerUtil.getMovementSpeed(player); in my Speed class, and in my PlayerUtil class, I have the method defined as:
public static double getMovementSpeed(Player player) {
//my code here
}
But whenever the getMovementSpeed method is referenced in my other classes, it throws this error:
java.lang.NoSuchMethodError: net.Swedz.util.PlayerUtil.getMovementSpeed(Lorg/bukkit/entity/Player;)D
I thought it may be that Eclipse was exporting incorrectly, but I rebooted it and tried again with no avail.
EDIT: I did try decompiling the exported jar, and the public static double getMovementSpeed(Player player) method does exist in the exported jar.
EDIT: My friend is also having a similar issue, and is using IntelliJ, so Eclipse is not the issue.
EDIT: Class definition for PlayerUtil:
package net.Swedz.util;
public class PlayerUtil implements Listener {
//getMovementSpeed is defined in here
}
Class definition for Speed:
package net.Swedz.hack.detect.move;
public class Speed implements Hack, Listener {
//my detection methods and method containing PlayerUtil.getMovementSpeed(player);
}
SOLUTION: I found on my own that I had classes conflicting between two plugins on my server. I had one jar with net.Swedz.util.PlayerUtil and another with net.Swedz.util.PlayerUtil both with different contents. I added my project name in all lower case after the net.Swedz and it seems to have fixed it!
Thanks!
This is a very simple to troubleshoot.
you have used that method and you were able to compile that class which uses this method.
so that means at compile time it reefers the class PlayerUtil which has this method.
But runtime class loader has loaded the class PlayerUtil which doesn't contain this method.
now what you have to do is just find out where that class has been loaded from (at run time)
if you can recreate the problem while it is running using eclipse/IDEA follow these steps.
(if it runs in in application server or standalone application, then start the application server or application with debug enabled.and you can do remote debug from your IDE).
put a break-point where exception was thrown (where you call this method).
start to debug , it will hit the break-point.
then evaluate this expression PlayerUtil.class.getResource("PlayerUtil.class")
4.you can find the path where the class was loaded from.
now you have two options , decompile the class and check whether that method is these (same return type, same name , same args).
or in debug , you can evaluate PlayerUtil.class.getDeclaredMethods() to find out.
So you can solve the problem by rectifying the class path entries if it was loaded from a wrong place.
I'm writing a unit test for some Java class in Eclipse. I always let Eclipse handle my imports automatically, and it orders them according to whatever default scheme.
Now, I have the following situation. The unit test builds and runs just fine in Eclipse. However, when I build the tests on the command line (using some Ant targets), javac complains that it can't find one of the classes I've imported. Since I'm testing something with caching, the relevant bits of the test file (Test.java let's say) are:
import com.abc.my.stuff.MyCacheLoader.Operation;
import com.google.common.cache.CacheLoader;
public class Test {
... test code, such as ...
List<MyKey> recordedKeys = dummyLoader.getKeysFor(Operation.LoadAll);
}
// Dummy cache loader which just records the keys
class MyCacheLoader extends CacheLoader<MyKey, MyValue> {
enum Operation { Load, LoadAll }
#Override
public MyValue load(MyKey key) throws Exception { .... whatever .... }
#Override
public MyValue loadAll(Iterable<MyKey> key) throws Exception { .... whatever .... }
public List<MyKey> getKeysFor(Operation op) { ... impl ... }
}
Notice that the import for my local class's inner enum appears before the import for the Guava CacheLoader class, because they are ordered alphabetically. When I try to compile this using Ant on the command line, javac can't find 'CacheLoader'. When I switch the order of the imports, the build succeeds (whereas Eclipse doesn't care either way).
I'm mystified as to what's going on here.
Apparently, the compiler in Eclipse doesn't have the following Sun bug:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6391197
which I found via:
http://unimplemented.blogspot.com/2007/08/my-java-puzzle-does-order-of-import.html
This explains why flipping the order of imports makes no difference to Eclipse, but it does to the Sun compiler. Part of the problem is fixed in Java 8, but my particular manifestation is targeted for a fix in Java 9: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7101822
As I have looked for an answer to this exception, but didn't find it anywhere, I'll leave this post here for future reference. So if anyone else runs into this problem, you are welcome.
I'm using the maven shade plugin to create a runnable jar together with org.springframework.data:spring-data-mongodb:1.4.0.RELEASE
I was running into the exception in the title, after creating the jar and running it with java -jar Foo-0.0.1-SNAPSHOT.jar
And the answer:
The error is here: https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java
in this line:
private static final boolean IS_SPRING_4_OR_BETTER = SpringVersion.getVersion().startsWith("4");
SpringVersion.getVersion returns null if it cannot retrieve the version number from the package. As the dependencies are extracted in the shaded jar, there is no package to retrieve the version number from and .startsWith("4") throws a NullPointerException.
To solve this issue (well it's kind of a quick and dirty solution, but it works), create a package org.springframework.core in your source folder and create the following class (I am using the springframework in version 4.0.2-RELEASE):
package org.springframework.core;
/**
* for spring data mongodb
* it can't determine the springversion in the shaded jar
*/
public class SpringVersion {
public static String getVersion() {
return "4.0.2-RELEASE";
}
}
The class will overwrite the original SpringVersion class file.
Like #mininme mentioned in his answer, the problem arises in 4.0.2.RELEASE because of
SpringVersion.getVersion().startsWith("4").
For now it means, that if you have such a problem, you should probably try a more recent version of Spring. At version 4.3.0.RELEASE of Spring there in no such problem anymore.