NoSuchMethodFound error: dependency error in GWTP. ResourceDelegate usage - java

I'm working in a GWTP + GAE project based on the CarStore example delviered by ArcBees. Maven dependencies are taken from that project too. My current version of GWTP is 1.5-SNAPSHOT.
The project compiles perfectly well. But when I run it, I'm stucked in this error:
[ERROR] Error injecting com.gwtplatform.dispatch.rest.delegates.client.ResourceDelegate<com.rmideas.sportbinder.shared.api.SessionResource>:
Unable to create or inherit binding: No #Inject or default constructor found for com.gwtplatform.dispatch.rest.delegates.client.ResourceDelegate<com.rmideas.sportbinder.shared.api.SessionResource>
The error refers to the ResourceDelegate declared in LoginPresenter. But i can´t find anything wrong in my code.
I analyzed the stacktrace and found this cause:
[INFO] Caused by: java.lang.NoSuchMethodError: com.gwtplatform.dispatch.rest.rebind.events.RegisterGinBindingEvent.postSingleton(Lcom/google/common/eventbus/EventBus;Lcom/gwtplatform/dispatch/rest/rebind/utils/ClassDefinition;Lcom/gwtplatform/dispatch/rest/rebind/utils/ClassDefinition;)
[INFO] at com.gwtplatform.dispatch.rest.delegates.rebind.DelegateGenerator.maybeRegisterGinBinding(DelegateGenerator.java:162)
This refers to a call between two Class objects. DelegateGenerator is the caller and is obtained from this dependency:
<dependency>
<groupId>com.gwtplatform.extensions</groupId>
<artifactId>dispatch-rest-delegates</artifactId>
<version>${gwtp.version}</version>
<scope>provided</scope>
</dependency>
And RegisterGinBindingEvent is the receiver. It belongs to here:
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-rest</artifactId>
<version>${gwtp.version}</version>
<scope>provided</scope>
</dependency>
Now, this happens in line 162 of DelegateGenerator:
RegisterGinBindingEvent.postSingleton(eventBus, definition, getClassDefinition());
This shouldn't be a problem, but the key the eventBus sends as the first parameter is of a different type in both classes.
DelegateGenerator has this import statement:
import com.google.common.eventbus.EventBus;
And RegisterGinBindingEvent has this EventBus class:
import com.gwtplatform.dispatch.rest.rebind.utils.EventBus;
I guess that this is causing the problem. Both dependencies are using the same version (1.5-SNAPSHOT). If I downgrade the version to 1.4, this won´t happen. But it still has issues running ResourceDelegate with this code.
Does anyone know what am I be doing wrong? Or if this is a bug?

Thanks for using the snapshots.
For some reason the CI didn't deploy a snapshot for the last commits. This should now be fixed. Can you try another build? Add -U to your maven command line to make sure you grab the latest snapshot.

Related

How to exclude packages in Maven that uses the same attribute?

So, I am working with webservices using SOAP and Maven. This error - I think - is a warning instead because it let me run the application and the service just fine for now. Whenever I call any other package inside this module class it turns red. If I don't add packages the error disappears but I need jasperreports (strange, as the involved package got nothing to do with this)
I've followed this: Module reads package from both
Using the solution "implementation and excludes" does nothing. Probably because it is Gradle but I had to try restricting the xml transform using the suggested message.
I also tried Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base' this.
I followed this guide as well. https://maven.apache.org/guides/mini/guide-multiple-modules.html
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<optional>true</optional> <!-- value will be true or false only -->
</dependency>
Making those package use optional does not help either.
Important note, using a different package I want to use the ERROR WILL CHANGE. I removed and added some so you can withness it. Check these:
In short, a Web Service dependency using some of the declared in the client as well. As mentioned, I went one by one until I found it.
Also, updating javax.xml version of the dependency was a necessary step in order to solve the problem.

java.lang.NoSuchMethodError when using twilio SMS

I am using Java web in Netbeans 8.2 RC
I try to send an SMS message using Twillio client:
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(
new com.twilio.type.PhoneNumber(getContact()),
new com.twilio.type.PhoneNumber("+phonenumber"),
"Sample message"
).create();
The message is successfully delivered.
But the code does not continue after .create().
Following exception is thrown:
java.lang.NoSuchMethodError:
com.fasterxml.jackson.datatype.jsr310.deser.JSR310DateTimeDeserializerBase.findFormatOverrides(Lcom/fasterxml/jackson/databind/DeserializationContext;Lcom/fasterxml/jackson/databind/BeanProperty;Ljava/lang/Class;)Lcom/fasterxml/jackson/annotation/JsonFormat$Value;
What I tried
I do not have a pom.xml or build.gradle. I only have web.xml
I have already imported the libraries: twilio-8.9.0-jar-with-dependencies.jar
How can I solve this issue?
The libraries I have:
Twillio SDK, exactly the create() method, seems to depend on Jackson (FasterXML converter library), particularly its module for handling Java8 DateTime (JSR-310). This is obvious when a call of create() results in a NoSuchMethod... for a missing method of class JSR310DateTimeDeserializerBase.
🔎 If you would have included the complete error output such as the stack-trace of this exception, then we could have easily seen that.
Analysis
ℹ️ A NoSuchMethod runtime-error is usually not caused by import statements or web.xml. It usually correlates with mismatching dependency-versions.
See the Twilio Java SDK v 8.9.0 (jar) as shown in Maven's web-UI (same as v 8.8.0) includes pom.xml with following dependency:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>?
and under the properties the required version:
<jackson.version>2.12.1</jackson.version>
Check dependency versions
Make sure that this jar or package is included within the Twillio jar or at least on your classpath.
⚠️ Also the versions must match (e.g. jackson-core v1 is often depending on jackson-datatype v1). A newer or older version may either change the method (currently not found) i.e. the call or the method-declaration.
Did the method change in Jackson versions?
In previous version (2.11) I also found the method findFormatOverrides with expected signature (parameters and return types) in class JSR310DateTimeDeserializerBase.
It was called inside the JsonDeserializer for a Java date-time property. Here when the deserializer is created in context, the parent-class' method is called:
#Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());
Solving suggestions
See How do I fix a NoSuchMethodError?. A comment to that question fits yours:
In Netbeans: Right click on project in Projects tab, use "Clean and Build". Solved it for me.
💡 This article on NoSuchMethod is very helpful for this issue.
Use Gradle or Maven
💭 You should consider to use a dependency-management and build-automation tool like Maven or Gradle:
Twilio: Java Helper Library, Using with a build automation tool
suggested in similar question: json - java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException

java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery - Hibernate Error

Above exception has been throwing While creating a hibernate session factory.
In application lib folder have hibernate-jpa-2.1-api and javax.persistence.2.1.0. I can able to see the NamedStoredProcedureQuery class in both jar. But I am getting runtime error for classnotfoundexception. Any suggestion?
NamedStoredProcedureQuery class is available in hibernate-jpa-2.1-api jar. But this jar refers some other jar in run time. So I didn't get error in compile time and getting exception during runtime. I just added other hibernated libs through maven repository.Initially i used only hibernate-core. Now artifactIDs are hibernate-core,hibernate-validator,hibernate-commons-annotations,hibernate-jpa-2.0-api and hibernate-entitymanager.
I have a non-ideal solution. I ended up using hibernate-core 3 (3.6.10) which doesn't throw the same error.
I got this idea from Mario Schwaiger, CodeRanch, for a different, but similar, class not found exception: http://www.coderanch.com/t/509836/ORM/databases/Hibernate-java-lang-ClassNotFoundException-javax
Details: I'm doing something slightly different - integrating Hibernate 4 with Struts 1 (instead of Spring), but ran into the same NamedStoredProcedureQuery class not found problem. Adding hibernate-validator threw different errors. Other things that did not work for me were: adding hibernate-entitymanager, adding javax.persistence, and changing tomcat or eclipse java versions between Java 8 and 7.
You'll need to instantiate the sessionfactory differently between Hibernate 3 and 4.
Hopefully somebody will post a better solution to your Spring problem.
You have to add hibernate-entitymanager to your classpath.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>

java/spring- getting NoClassDefFoundError at org.springframework.context.support.AbstractApplicationContext

I am trying to initialise an RMI client for which I have used Spring.
Now, the application's RMI context is stored in file= rmiClientAppContext.xml
The relevant code for using the above file is given below--
//RMI Client Application Context is started...
ApplicationContext context = new ClassPathXmlApplicationContext("rmiClientAppContext.xml");
However, when I try and run the program, this is the error I am getting--
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:164)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:90)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
On further investigation of the first line of error message above, I found that
"164 is not a valid line number in org.springframework.context.support.AbstractApplicationContext"
What have i done wrong here? I am using Spring v3.1.3
How do I resolve the above error? Also, exactly which JARs do I have to include for the RMI client? And is there any specific order in which those JARs should be added to Java build path in Eclipse?
In this particular case you should include commons-logging-1.1.1.jar in your client classpath. Spring-Core depends on it.
In general I suggest you to use Maven or similar tool to manage your dependencies.
Sounds like you are missing very important spring-web jar file. Add this to your pom file to fix this issue.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>

NoSuchMethod error getting a gdata service

I get the following error:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
at com.google.gdata.client.Service.<clinit>(Service.java:558)
at testproject.TestProject.run(TestProject.java:22)
at testproject.TestProject.main(TestProject.java:31)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
This comes from the following code:
package testproject;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.util.*;
import java.util.logging.*;
public class TestProject {
public static void main(String[] args) {
try {
YouTubeService service = new YouTubeService("Test", "developerKey");
service.setUserCredentials("root#gmail.com", "pa$$word");
} catch (AuthenticationException ex) {
Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
At first, I included every library in http://code.google.com/p/gdata-java-client/downloads/list and also imported much more than I needed to.
I've since removed the libraries I deemed unnecessary (thanks thinksteep). So the libraries I'm currently including are the following libraries:
mail.jar
activation.jar
ant.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
guava-11.0.1.jar
gdata-youtube-2.0.jar
gdata-youtube-met-2.0.jar
(There are probably a few libraries there which are not necessary... But I'm at my whit's end...)
I'm just trying to test getting a YouTube service so I can get things going on this project, but no dice. Oh, and I've also included this library: http://code.google.com/p/guava-libraries because before I was getting a NoClassDefFound error and including that library seemed to solve it. Thank you in advance for the help!
Oh, and I also followed every step exactly (or at least I think so) in the gdata getting started guide. My test build was successful by the end... Thanks again!
Adding more than required may cause issue too. java.lang.NoSuchMethodError error typically happens in case where runtime couldn't find required method with exact signature. Possible causes are:
1) There might be mulitple jars with same code, which may cause wrong class get loaded.
2) Incompatable version of jar, the jar you have in classpath might be older version/newer version.
Make sure none of those cases happening.
Issue with latest version of gdata still referencing older guava methods
Check Out
http://code.google.com/p/gdata-java-client/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=344
Solution
I switched to guava-r07.jar located at
http://code.google.com/p/guava-libraries/downloads/detail?name=guava-r07.zip&can=4&q=
This got me past
ContactsService service = new ContactsService("");
Jar's in use:
Default Eclipse plugin jar's
gdata-base-1.0.jar
gdata-client-1.0.jar
gdata-contacts-3.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
guava-r07.jar
Apache (servlet-api.jar)
JavaMail (mail.jar)
JavaBeans Activation Framework (activation.jar)
I dont know if its still relevant but i had the same exception
there is a problem with guava 11.02.jar (currently latest version)
when using guava-10.0.1 (can be found here) everything went well.
The Required library jars are as follows.
gdata-client-1.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
gdata-youtube-2.0.jar
guava-11.0.2.jar
java-mail-1.4.4.jar
I am using the above mentioned library . Please make use of it ; because the ultimate aim is to get the YouTubeService Object. Check below for the code snippet.
package com.baba.test;
/*
* Author : Somanath Nanda
*/
import java.net.MalformedURLException;
import java.net.URL;
import com.google.gdata.client.youtube.YouTubeQuery;
import com.google.gdata.client.youtube.YouTubeService;
public class Test {
private static final String CLIENT_ID = "XXXXXXXX.XXXXX.XXX.XXX";
private static final String DEVELOPER_KEY = "*********************************88";
public static void main(String[] args) throws MalformedURLException {
YouTubeService service = new YouTubeService(CLIENT_ID,DEVELOPER_KEY);
System.out.println("Service : "+service);
}
If you're using a build tool, such as Maven, then you could simply do something similar to the following example from a portion of the dependencies section in my pom.xml:
<!-- The mail dependency is required BEFORE the javaee-api dependency.
The gdata dependency (YouTube API) requires the mail dependency. -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>core</artifactId>
<version>1.47.1</version>
</dependency>
I have added googlecollection-exp.jar into my build path then the previous execption was gone.
Pay attention to this jar gdata-core-1.0.jar I have the same problem, and I realized I have problem with this jar gdata-core-1.0.jar, and I found from website the same jar gdata-core-1.0.jar, but the content is different. After I replaced the new gdata-core-1.0.jar, problem solved.
So it's tricky that the jar with the same name but their contents are not the same. you thought you have the jar, actually it's not the right one
It could be that some of your jars would be having dependency on google/guava jars and if they're not in build path or if multiple of them are there it might raise inconsistency hence the error. A quick solution could be add latest version of guava to your pom
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
Now check in dependency hierarchy if any of your Jar apart from guava is referring to any other older jar of guava/google-collections. If so then exclude it, something like this
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>

Categories