REST Assured: missing class that's (apparently) not missing - java

Here's my simple code:
import static com.jayway.restassured.RestAssured.get;
public class testget {
public static void main(String[] args) {
Response countryName = get("http://maps.googleapis.com/maps/api/geocode/json?latlng=45.2542285874,30.2564857&sensor=false");
System.out.println(countryName);
System.exit(0);
}
}
When running, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jayway/restassured/mapper/factory/ObjectMapperFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.jayway.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:423)
at testeget.main(testeget.java:6)
Caused by: java.lang.ClassNotFoundException: com.jayway.restassured.mapper.factory.ObjectMapperFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
But the Rest Assured lib is loaded, otherwise the get method wouldn't even be called... What could it be?
I'm using Rest Assured 2.8.
Update:
I'm using Eclipse to run it, and the classpath has, besides the default Java/Eclipse content, the path to the .jar file of Rest Assured and it's dependencies, as listed on their website.
Dependencies list on the bottom of the page (all added to the classpath).
http://mvnrepository.com/artifact/com.jayway.restassured/rest-assured/2.8.0

Related

java protobuf run-time formal example not working

I am trying to run the official example for protobuf in java source from here,
followed the README.md
protoc generate the javasource code fine but I can not run the code by:
1- java AddPerson data
or
2- java -cp protobuf-java-3.5.1.jar AddPerson
1- Error for java AddPerson data is:
Exception in thread "main" java.lang.NoClassDefFoundError:
"com/google/protobuf/MessageOrBuilder
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at AddPerson.main(AddPerson.java:69)
Caused by: java.lang.ClassNotFoundException:
com.google.protobuf.MessageOrBuilder
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 25 more"
2- Error for: java -cp target/protobuf-java-3.5.1.jar AddPerson
Error: Could not find or load main class AddPerson
[enter image description here][2]
Try including the current directory in the classpath:
java -cp .:target/protobuf-java-3.5.1.jar AddPerson
The .: is to append classpath. For windows, it is ; instead of :.[1]
[1] https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser when using boilerpipe

I am very new to boilerpipe and I am trying out the following basic code:
package contentExtraction;
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
public class ContentExtractor {
public static void main(String[] args) throws Exception {
final URL url = new URL(
// "http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en"
"http://www.dn.se/nyheter/vetenskap/annu-godare-choklad-med-hjalp-av-dna-teknik"
);
System.out.println(ArticleExtractor.INSTANCE.getText(url));
}
}
But I am getting the following error when trying to run the above piece of code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at de.l3s.boilerpipe.sax.BoilerpipeSAXInput.getTextDocument(BoilerpipeSAXInput.java:51)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:69)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:87)
at contentExtraction.ContentExtractor.main(ContentExtractor.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more
I googled the error and came across this link. I thought that I was missing xercesImpl.jar in my dependencies. I included the same, still my code is giving the same error. What is the issue?
I figured the solution myself. The boilerpipe jar has further dependencies. I converted my project to maven project, included the dependency:
<dependency>
<groupId>com.syncthemall</groupId>
<artifactId>boilerpipe</artifactId>
<version>1.2.1</version>
</dependency>
When I build the above project, I can see there are actually 4 jars that are imported in Maven Dependencies folder:
boilerpipe-1.2.1.jar
nekohtml-1.9.18.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar

Getting java.lang.NoClassDefFoundError: org/apache/xerces/dom/ElementNSImpl with Apache ODF Toolkit

I am trying to read an ods file using Apache ODF Toolkit. I am getting java.lang.NoClassDefFoundError error while while trying to load the Spreadsheet using below code-
SpreadsheetDocument data = SpreadsheetDocument.loadDocument(file);
Below is the error trace-
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/dom/ElementNSImpl
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at test.read.ODSFile.ReadODS.main(ReadODS.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.dom.ElementNSImpl
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 25 more
Below is the project structure, which shows the classpath-
Is there any dependencies missing?
It seems your code can not find the class:
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.dom.ElementNSImpl
from ODF Toolkit
Note: ODFDOM requires Apache Xerces. The jar file xercesImpl.jar also must exist in a folder lib next to odfxsltrunner.jar file, or it must be in the classpath. The ODF XSLT Runner NetBeans projects includes a reference to xersesImpl.jar in the runtime classpath which has to be adapted after checking out the project.

Error running .class files

I wonder why the Game.class wont start. Here's he problem I got:
java.lang.NoClassDefFoundError: Game (wrong name: game/Game)`
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Exception in thread "main"
You will get similar error if you do mething like this:
package game;
class Game
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
without putting the compiled class file in a sub-folder called game and run it like java Game. So your Game class is in a package called game.
Please Check Your packaging structure and ensure that your class file is inside the package folder . Compile and Happy Execution ....

String encryption with Jasypt library

I want to encrypt a string, but the standard Java libraries are too complicated for me.
So I turned to Jasypt labriry. It's pretty simple to use and understan. However when I import the library to Eclipse 3.6 and when I try encrypt a string like "Hello" with the password "123", it always comes up with an error. I'm not sure what I'mm doing wrong but I think it also happens when I use other libraries in Eclipse.
Source:
import org.jasypt.util.text.BasicTextEncryptor;
public class Main {
static BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
public static void main(String[] args) {
System.out.println("Hello World");
textEncryptor.setPassword("123");
System.out.println(textEncryptor.encrypt("Hello World"));
}
}
The error message:
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.jasypt.util.text.BasicTextEncryptor.<init>(BasicTextEncryptor.java:67)
at eMain.<clinit>(eMain.java:4)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
The library you imported depends on another library containing org/apache/commons/lang/exception/NestableRuntimeException. This is located in the Apache Commons Lang library.
In fact, if you downloaded JASYPT from http://sourceforge.net/projects/jasypt/files/ you'll get a zip file containing a lib-folder with these files:
commons-codec-1.1.jar
commons-lang-2.1.jar
jasypt-1.6.jar
You should include all of these in your project.
I tried it and your little sample program works fine (and prints the following)
Hello World
v09l9j/BIeSoMkQXc2CY0VIJLlLAQTYq

Categories

Resources