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)
Related
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.
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.
I wrote a performance test class marked as #Ignore because it takes a very long time to run and I don't normally need to run it. I'd like to be able to right click one of the #Tests and say "run" but when I do that in intellij it doesn't run the test because the class is marked as ignored.
I don't want to comment out the #Ignore because it's too easy to accidentally commit the file with the #Ignore removed. But I feel that if I explicitly tell Intellij to run a test it should run it regardless of the #Ignore. Keep in mind, if I run a group of classes (eg: all in a package) I still would want this test class to be ignored.
Is it possible to get this functionality in Intellij?
I found this link which says that you can do something tricky with Assume.assumeTrue that will mark the test as ignored if the condition is false, and normally this is a system property that is used in the condition, so you can pass it in as a parameter on the command line. IntelliJ lets you customize the command line parameters, so it should work, but I haven't tried it myself.
The example from the link is:
#Test
public void shouldTryEveryPossiblePhoneticAttributeSet() throws IOException {
Assume.assumeTrue(TestEnvironment.hasBigParseSets());
...
}
public class TestEnvironment {
private static final String HAS_BIG_PARSESETS = "hasBigParseSets";
public static boolean hasBigParseSets(){
return "true".equalsIgnoreCase(System.getProperty(HAS_BIG_PARSESETS));
}
}
And "mvn test -P bigParseSets" vs "mvn test".
edit: And I just found this neat thread on StackOverflow that tells how to run a single junit test. I assume I don't need to quote that since it's to a post here on StackOverflow. That explains how to do it from a command line, but you should be able to do something very similar to that one that has hard coded values for the class and method names, and then just right click on the SingleJUnitTestRunner class and ask IntelliJ to run it.
I'm working in Java and have come across an incredibly odd error. I have a very basic class as follows:
public class ClassA{
private static Logger log = Logger.getLogger(ClassA.class.getName());
private boolean trace;
public ClassA(){
trace = log.isTraceEnabled();
}
public void doSomething(){
//does stuff
}
}
I can use this class just fine within my current project. However, when I build, package, and install to my local repo (using Maven, no remote artifact repo set up), other projects cannot properly use this class because they cannot instantiate it. When I try anything like:
ClassA classA = new ClassA();
I get the following compilation error:
ClassA() has private access in [package].ClassA
I've decompiled the .jar in my local repo to ensure the constructor is present and is public - it is. I've also used the -U flag to force updates and the compilation continues to fail. What could be causing this error?
Maybe you have some other ClassA.class file somewhere in the classpath. Check all the jars used by the project that cannot call the constructor: one of them should contain an old version of your class.
My only thought is that you have a problem with your package. Make sure to define the package at the top of the source file for classA using the package keyword. When you call it ensure that the file is in include list with the include keyword. You could be running into the error because ClassA exists in some default package and that is what you are actually calling instead of calling your locally made ClassA class. The code you posted looks fine and you have already double checked to ensure the changes have taken effect in your repository.
//for those with Kotlin-Java mixed projects:
If the said file (With constructor) is in Kotlin and is being used in Java:
Instead of A a = new A(); //which causes the said error
Use A.INSTANCE. …
I have this error, where write "private", instead "public" for class constructor;