Jayway is looking up net.minidev classes when Im using Gson - java

Im using Gson for some Jayway code that Im writing:
private static final Configuration JACKSON_CONFIGURATION = Configuration
.builder()
.mappingProvider(new GsonMappingProvider())
.jsonProvider(new GsonJsonProvider())
.build();
but when I run it (Trying to apply some criteria for selection of elements inside the JSON), this exception occurred:
Exception in thread "main" java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
at com.jayway.jsonpath.internal.DefaultsImpl.<init>(DefaultsImpl.java:17)
at com.jayway.jsonpath.internal.DefaultsImpl.<clinit>(DefaultsImpl.java:15)
at com.jayway.jsonpath.Configuration.getEffectiveDefaults(Configuration.java:48)
at com.jayway.jsonpath.Configuration.access$000(Configuration.java:34)
at com.jayway.jsonpath.Configuration$ConfigurationBuilder.build(Configuration.java:229)
at com.jayway.jsonpath.internal.filter.ValueNode$PathNode.evaluate(ValueNode.java:778)
at com.jayway.jsonpath.internal.filter.RelationalExpressionNode.apply(RelationalExpressionNode.java:37)
at com.jayway.jsonpath.Criteria.apply(Criteria.java:57)
at com.jayway.jsonpath.internal.path.PredicatePathToken.accept(PredicatePathToken.java:75)
at com.jayway.jsonpath.internal.path.PredicatePathToken.evaluate(PredicatePathToken.java:59)
at com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:81)
at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:77)
at com.jayway.jsonpath.internal.path.PathToken.handleArrayIndex(PathToken.java:133)
at com.jayway.jsonpath.internal.path.ArrayPathToken.evaluateIndexOperation(ArrayPathToken.java:63)
at com.jayway.jsonpath.internal.path.ArrayPathToken.evaluate(ArrayPathToken.java:52)
at com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:81)
at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:77)
at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:53)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:61)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:187)
at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:164)
at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:151)
at com.wfx.wte.Test.fn(Test.java:44)
at com.wfx.wte.Test.main(Test.java:32)
Caused by: java.lang.ClassNotFoundException: net.minidev.json.writer.JsonReaderI
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 25 more
It seems to be looking up some net.minidev classes. Any clues?

add net.minidev.json-smart to the classpath
if needed,add net.mimidev.asm to the classpath

Related

PDFBox failing with DamagedFontException (Arial font)

I am trying to parse the existing PDF and it is failing with DamagedFontException.
I looked at the PDF and it is using Arial font. So I am trying right now to add Arial font and this is the error I am getting now.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fontbox/ttf/TTFParser
at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:147)
at org.apache.pdfbox.examples.interactive.form.FillFormField.main(FillFormField.java:54)
Caused by: java.lang.ClassNotFoundException: org.apache.fontbox.ttf.TTFParser
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
I modified the existing FillFormField class in PDFBox examples and added the Arial text field to the test PDF and was able to reproduce the error.
Here is the code which I added:
PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
acroForm.getDefaultResources().put(
COSName.getPDFName("Arial"),
PDType0Font.load(pdfDocument, new File("src/main/resources/org/apache/pdfbox/Arial.ttf")));
What I am doing wrong? My main goal is to just fill the form in the document, and that's it.
UPDATE:
The DamageFontException happens when I just modify existing PDF in the example
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fontbox/type1/DamagedFontException
at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:76)
at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:143)
at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.validateAndEnsureAcroFormResources(AppearanceGeneratorHelper.java:150)
at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.<init>(AppearanceGeneratorHelper.java:111)
at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:261)
at org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:210)
at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:218)
at org.apache.pdfbox.examples.interactive.form.FillFormField.main(FillFormField.java:87)
Caused by: java.lang.ClassNotFoundException: org.apache.fontbox.type1.DamagedFontException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 8 more

Error while reading bq table in Java eclipse - How do I get jar file for com/google/cloud/http/HttpTransportOptions package?

I am trying to read a sample table from bq to java eclipse(on prem). I am stuck on an error which says class not found - HttpTransportOptions.
I know i am missing some dependencies. Which is the jar file that would cover this package?
The code is below:
public class sample_bq_java {
public static void main(String... args) throws Exception {
BigQuery bigquery = BigQueryOptions.newBuilder().setProjectId("project_id")
.setCredentials(
ServiceAccountCredentials.fromStream(new FileInputStream("C:\\Users\\3401770\\Downloads\\key.json"))
).build().getService();
String datasetName = "hacker_news.comments";
// Fetches the dataset
Dataset dataset = bigquery.getDataset(datasetName);
System.out.printf("Dataset %s fetched.%n", dataset.getDatasetId().getDataset());
}
}
The error is:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/cloud/http/HttpTransportOptions
at com.google.cloud.bigquery.BigQueryOptions.getDefaultHttpTransportOptions(BigQueryOptions.java:114)
at com.google.cloud.bigquery.BigQueryOptions$BigQueryDefaults.getDefaultTransportOptions(BigQueryOptions.java:109)
at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:305)
at com.google.cloud.bigquery.BigQueryOptions.<init>(BigQueryOptions.java:91)
at com.google.cloud.bigquery.BigQueryOptions.<init>(BigQueryOptions.java:30)
at com.google.cloud.bigquery.BigQueryOptions$Builder.build(BigQueryOptions.java:86)
at frcst.apps.stof.sample_bq_java.main(sample_bq_java.java:47)
Caused by: java.lang.ClassNotFoundException: com.google.cloud.http.HttpTransportOptions
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Any help or suggestion is appreciated.
I presume that HttpTransportOptions class is a part of google-cloud-core-http package as for GCP Core http module implementation.
Just ensure that you've included google-cloud-core-http-1.93.x.jar into the project or add dependency in pom.xml file, fetching the package from the particular repository:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core-http</artifactId>
<version>1.93.7</version>
</dependency>

(java string concatenation)How come this is giving this exception?

this is my simple code.
class atmPin{
public static void main(String[] args) {
int x = 0;
System.out.println("hi there"+x);
}
}
When i run it i get this exception errors.
java atmPin
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
at atmPin.main(atmPin.java:6)
Caused by: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
... 1 more
Caused by: java.lang.ClassNotFoundException: java.lang.invoke.StringConcatFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
is this something to do with java version? i have no idea why is it happening. this is such a simple thing. :(
getting the same kind of exception even with strings.
eg.
String x = "";
x += "a";
java.lang.invoke.StringConcatFactory is a class which appeared in Java 9 in order to implement JEP 280 (Indify String Concatenation) which changes behaviour of javac compiler so that it uses invokedynamic instructon together with the given class for string concatentaion. So the reason for this error most probably is compiling using javac from JDK 9 or later while running this code under Java 8 or less (or, with much less chance, using custom java runtime).
In order to solve it another version of compiler might be used or another version may be specified to the compiler or another JRE should be used for running the compiled class(es).

Weka DiscriminantAnalysis NoClassDefFoundError

I'm trying to use MultiClassFLDA in discriminant analysis package but I always get an error on running the code and defining a new instance of the MultiClassFLDA class
Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Vector
at assignment2.face.tryLDA(face.java:141)
at assignment2.Assignment2.main(Assignment2.java:106)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Vector
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
It seems to be linked to some dynamic class loading in newer versions of Weka, presumably within the Weka Package Manager: that class is defined in the mtj.jar, which is bundled inside weka.jar. In that other question, an answer suggested to extract the mtj.jar and add it to your classpath.
As I didn't have this problem with other Filters, my guess is that MultiClassFLDA is not implemented correctly: I found out is that if you use another Filter before, that specific class will get loaded:
// Run a dummy Filter for correct initialization
Filter f = new Standardize();
f.setInputFormat(data);
Filter.useFilter(new Instances("", params, 0), f); // Dummy run on empty dataset
// Now run the MultiClassFLDA
f = new MultiClassFLDA();
f.setInputFormat(data);
data = Filter.useFilter(data, f);
N.B. that is a really ugly hack! I used it to be able to work. I'll edit my answer when I find the appropriate way to do it (other than extracting the jar from Weka itslef).

Java dom4j org/jaxen/NamespaceContext exception

I have downloaded dom4j-1.6.1 and added it to java's build path. I am also familiar with java.lang.NoClassDefFoundError: org/saxpath/SAXPathException but I keep getting an exception.
Enclosed a snippet:
public class Parser {
public static void parse(final String path) throws Exception {
final SAXReader reader = new SAXReader();
final Document document = reader.read(new File(path).toURI().toURL());
if (document == null) return;
List list = document.selectNodes("/");
for (Object o : list)
System.out.println(o);
}
}
When I run it, I get the following stack trace
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext
at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
at org.dom4j.tree.AbstractNode.selectNodes(AbstractNode.java:164)
at Parser.parse(Parser.java:15)
at Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.jaxen.NamespaceContext
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 5 more
Any clue what causes the error?
The Exception:
java.lang.ClassNotFoundException: org.jaxen.NamespaceContext
Maybe you forgot to include the jaxen.jar in your Java build's path.
For more specific instructions on using SAXReader to parse some XML and loop through the nodes:
https://stackoverflow.com/a/24959790/445131
Found out the solution. I had to download and include jaxen in java's build path.

Categories

Resources