Jackson library error calling 'writeValue' function - java

I'm trying to use Jackson for converting string to JSON object in java. I have both jar file and maven project of the library, with which I tried one by one but both giving error while calling writeValue function. Error says -
The type com.fasterxml.jackson.core.JsonGenerator cannot be resolved. It is indirectly referenced from required .class files
I have correctly added the library to build path.
After looking at eclipse-error-indirectly-referenced-from-required-class-files ,I realized that the problem is because of missing com.fasterxml.jackson.core.JsonGenerator class file.So Which jar file I missed to add to build path?. Tried by adding the maven project on build path too- same error.

To find which jar contains the required file, you can always use http://search.maven.org and search for the class prefixing it with fc:, like this:
http://search.maven.org/#search%7Cga%7C1%7Cfc%3Acom.fasterxml.jackson.core.JsonGenerator
Looks like you're missing jackson-core jar on your classpath.

Make sure that you have in your path jackson-databind and jackson-core

build path is used during compile. You need to set up the Deployment Assembly for run time classpath (under project settings, look for Deployment Assembly )

Related

Why are my Alexa Skills Kit dependencies missing?

I cloned Amazon's ASK java repository on github and ran
mvn package
on it, and it produced the following .jars:
ask-sdk-core-2.3.4.jar
ask-sdk-apache-client-2.3.4.jar
ask-sdk-dynamodb-persistence-adapter-2.3.4.jar
ask-sdk-lambda-support-2.3.4.jar
ask-sdk-servlet-support-2.3.4.jar
ask-sdk-2.3.4.jar
I noticed that when attempting to make certain imports for classes on https://developer.amazon.com/docs/custom-skills, such as import com.amazon.speech.speechlet.servlet.SpeechServlet;
I received a message stating that com.amazon.speech could not be resolved, indicating that the file didn't exist. However, after further investigation, I noticed that there was a SkillServlet class that seemed to essentially replace the SpeechServlet class as it was able to do everything that SpeechServlet could,
so I assumed that the developer site hadn't been updated yet to reflect the changes. I then noticed that RequestHandler, a class in the repository, had a method that returned an object of type Optional< Response >. When I tried to import Response with the following import:
import com.amazon.ask.model.Response;
I recieved an error message stating The type com.amazon.ask.model.Response cannot be resolved. It is indirectly referenced from required .class files
This suggests that the class definition doesn't exist in the project's classpath, despite having included all of the above .jars. I searched through and was unable to find a model directory. Did my maven build fail, and am I missing any .jars? I'm using Eclipse EE IDE, which I know is susceptible to errors, but I've cleaned my project as well as restarted the IDE to no avail.
Update:
I noticed that the pom.xml file within the ask-sdk-core-2.3.4 directory contained a dependency for ASK SDK Model, but it doesn't seem to be obtaining the dependency. I also noticed that though ask-sdk-2.3.4 should also include everything that ask-sdk-core-2.3.4 does, as the latter is listed as a dependency in the former, I have to include ask-sdk-core's jar file separately or Eclipse is not able to recognize certain classes. I think this means that maven has failed, so I just downloaded the jar directly from mvnrepository.com. Any idea why this might have happened?
If you use ask-sdk-2.3.4.jar, then it should include all the dependencies you need like you noticed in your update blurb. When you look at Hello World sample in their Github repo, the pom.xml only contains ask-sdk-2.3.4.jar but not other dependencies that ask-sdk-2.3.4.jar has in it. https://github.com/alexa/alexa-skills-kit-sdk-for-java/blob/2.0.x/samples/helloworld/pom.xml
To your error message on Response, that is because you are missing ask-sdk-model jar which you can find from maven central. http://central.maven.org/maven2/com/amazon/alexa/ask-sdk-model/
I would suggest using maven and pom.xml so that you don't have to download jars individually.

Eclipse Plugin - adding a jar used by eclipse itself

I'm trying to write an Eclipse-Plugin using Eclipse. The plugin uses org.eclipse.jdt.core.
At some point in my code, I'm getting an object of CompilcationUnit from the menus-action-handlers, and I want to find the java-file's path that was clicked on using my plugin.
At first, on the line getting an object of type "CompilcationUnit", I got a NoClassDefFoundError (I referenced the org.eclipse.jdt.core.jar that was in my eclipse/plugins folder).
This thread solved that issue:
Eclipse plugin: java.lang.NoClassDefFoundError
Similar solution found it:
Java eclipse : Importing jar file in eclipse plugin project
Now, I have a different error. I'm trying to verify the element is of type CompilationUnit and then use it.
I wrote the following code:
System.out.println(element.getClass());
System.out.println(org.eclipse.jdt.internal.core.CompilationUnit.class);
System.out.println(element instanceof org.eclipse.jdt.internal.core.CompilationUnit);
System.out.println(element.getClass().getPackage());
System.out.println(org.eclipse.jdt.internal.core.CompilationUnit.class.getPackage());
System.out.println(element.getClass().getProtectionDomain().getCodeSource().getLocation());
System.out.println(org.eclipse.jdt.internal.core.CompilationUnit.class.getProtectionDomain().getCodeSource().getLocation());
org.eclipse.jdt.internal.core.CompilationUnit cu = (org.eclipse.jdt.internal.core.CompilationUnit)element;
The output is this:
class org.eclipse.jdt.internal.core.CompilationUnit
class org.eclipse.jdt.internal.core.CompilationUnit
false
package org.eclipse.jdt.internal.core
package org.eclipse.jdt.internal.core
file:/C:/Program Files/Eclipse/plugins/org.eclipse.jdt.core_3.11.1.v20150902-1521.jar
file:/D:/Svn/OrderingTR/Source/ClassMethodsRearranger/external/org.eclipse.jdt.core_3.11.1.v20150902-1521.jar
And then I get an exception:
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.jdt.internal.core.CompilationUnit cannot be cast to org.eclipse.jdt.internal.core.CompilationUnit
I do not understand this. It seems the element is of the same type that my code is referencing. Only my code references the type in ile:/D:/Svn/OrderingTR/Source/ClassMethodsRearranger/external/org.eclipse.jdt.core_3.11.1.v20150902-1521.jar
and the element is of the same type of the same jar, only located in file:/C:/Program Files/Eclipse/plugins/org.eclipse.jdt.core_3.11.1.v20150902-1521.jar.
Now, I need to reference the file in D:/Svn/... because that is the project's jar, and it is needed for eclipse plugins (otherwise I get the NoClassDefFoundError solved earlier).
But I am unable to use the element I get from the menu-actions-handlers (I believe because it originated in a different jar file). I need to use that element.
What can I do? Has someone encountered this kind of problem? I searched and searched and found nothing on the subject... It seems it is specific to eclipse plugins and using the jdt.core.
Thank you very much, I really appreciate the long read.
I eventually solved it by adding the reference in the MANIFEST.MF.
At the dependencies, I added org.eclipse.jdt.core in the Required Plug-ins.

How to add compile dependency to javadoc class path in gradle

In gradle if I my project depends on another package, for example:
compile 'com.example:foo:0.82.2'
And in my javadoc, it references symbol in that package.
Then if I run javadoc task, it will say error: reference not found
I know I should add that package to class path, just like the following way to add android library
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
But how could I know the classpath for my dependency except add a hard coding path point to the gradle cache?

NoSuchMethodError after cleaning the project

I'm currently getting this error:
java.lang.NoSuchMethodError: org.json.JSONObject.keySet()Ljava/util/Set;
at ee.ut.cs.Parser.accessLint(Parser.java:39)
I have tried cleaning the project to no awail.
I suspect I have an error in the src/plugin/parse-htmlraw/build.xml while creating the jar file but I'm not certain. I understand that this error is because the function does not exist at runtime, but the object is created which means that the class is there, just not that function. I decompiled the .class file in created jar and it has the necessary functions.
Code is available at https://github.com/jaansusi/WCAGgrader
Q: What is wrong with the build that produces this error?
The problem is that even if I put the necessary class files in the jar I create, they are not linked correctly and the class that's called in the jar can't locate functions inside the other classes. The class object JSONObject is created but the functions inside the JSONObject class can't be found.
If you do not find the problematic version, there is a possibility you get it (especially if you are using Spring) from the following dependency -
<artifactId>android-json</artifactId>
<groupId>com.vaadin.external.google</groupId>
excluding it worked for me,
An easy way of analyzing dependencies is the maven-helper plugin in Intellij, see here
Check for the version you have used.
There might be a case where 2 different versions are being used which in turn causes this error.
To their own maven local repository com\Google\code\gson\gson, see if there are two or more version about json, will have to do is to delete the old, and remember to look at any other place in the project is introduced into the old version of the dependence, if any, change the old version of the dependence to the new version is perfectly solved this problem

Could not initialize class org.apache.axis.client.AxisClient

i'm facing problem with following exception.anyone help me how to get rid of it.i have added axis.jar in classpath still facing this issue.
j
ava.lang.NoClassDefFoundError: Could not initialize class org.apache.axis.client.AxisClient
org.apache.axis.client.Service.getAxisClient(Service.java:104)
org.apache.axis.client.Service.<init>(Service.java:113)
com.netsuite.webservices.platform_2013_2.NetSuiteServiceLocator.<init>(NetSuiteServiceLocator.java:12)
com.zyom.netsuite.NetsuiteIntegrationManager.<init>(NetsuiteIntegrationManager.java:169)
com.zyom.netsuite.NetsuiteIntegrationManager.getNetSuiteIntegrationManager(NetsuiteIntegrationManager.java:68)
com.zyom.netsuite.controller.NetsuiteIntegrationManagerContoller.execute(NetsuiteIntegrationManagerContoller.java:33)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
com.zyom.security.LoginMonitorFilter.doFilter(LoginMonitorFilter.java:67)
You're probably missing some dependant library. In Eclipse you can look inside the jar file from project explorer and verify that there is a package 'org.apache.axis.client' and it contains class AxisClient.
(If you're not in Eclipse then otherwise you can just unpack your jar and see that the class is there - many possibilities for that, you can even rename the jar into zip and unpack it).
If the class file is in place, you're still missing it from classpath.
You would need to add commons-logging and commons discovery dependency jar in the library folder

Categories

Resources