Java dom4j org/jaxen/NamespaceContext exception - java

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.

Related

java.lang.ClassNotFoundException Error when trying to inject into running VM

I am trying to inject a .jar file in a running VM.
I've added tools.jar in the build path in eclipse, but when I try to run the injector, this error pops up. How should I add tools.jar to the project?
Full error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
at src.testinjector.MainClass.main(MainClass.java:13)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
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)
... 1 more
you may try:
Give the path to tools.jar instead of being dependent on JAVA_HOME.
Note: JAVA_HOME/path to jdk/bin/ should not have any space.
By default, the "tools.jar" classes are not loaded, your options are to either use a jdk that does load it, include tools.jar in your jar, or forcefully load it with the method below, (note: this might not work on certain jdk/jvm's)
private static void prepareAttach() throws NoSuchMethodException, MalformedURLException, InvocationTargetException, IllegalAccessException {
String binPath = System.getProperty("sun.boot.library.path");
// remove jre/bin, replace with lib
String libPath = binPath.substring(0, binPath.length() - 7) + "lib";
URLClassLoader loader = (URLClassLoader) [This Class].class.getClassLoader();
Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURLMethod.setAccessible(true);
File toolsJar = new File(libPath + "/tools.jar");
if (!toolsJar.exists()) throw new RuntimeException(toolsJar.getAbsolutePath() + " does not exist");
addURLMethod.invoke(loader, new File(libPath + "/tools.jar").toURI().toURL());
}

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

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

Java code throws exception after adding Selenium-java-2.31.0 library in Maven

I am working on Netbeans. I added a library selenium-java-2.31.0. But it shows exception.
I added all the libraries on which this library is dependent.
I follow this link to add library in netbeans.
My code :-
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public static void main(String[] args) throws IOException, URISyntaxException {
String url1 = "http://www.jabong.com/giordano-P6868-Black-Analog-Watch-183702.html";
Document doc1 = Jsoup.connect(url1).get();
WebDriver driver = new FirefoxDriver();
driver.get(url1);
Elements tag_list = doc1.getAllElements();
for( Element tag1 : tag_list ) {
Point point=driver.findElement(By.id(tag1.id())).getLocation();
System.out.println("X Position : " + point.x);
System.out.println("Y Position : " + point.y);
}
}
Exception
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
at template_matching.Template_matching.main(Template_matching.java:275)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
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)
... 1 more
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
Help me in solving this problem. Why this exception throws?
Edit No. 1
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:89)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:79)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:67)
at org.openqa.selenium.firefox.FirefoxDriver.getProfile(FirefoxDriver.java:260)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at template_matching.Template_matching.main(Template_matching.java:275)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
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)
... 11 more
Java Result: 1
Edit no.2
Now I moved to maven, by thinking it downloads all the dependent libraries. But now it shows diffrerent error.
Edit No. 3
As it shows some problem with firefox, I replaced firefox with Chrome.
This time previous error is removed. But a new comes in picture. Please see this.
Edit no. 4
Edit No. 5
Now I shifted to firefox again, and gets given page, but it stucks then. Why ?
Below is the error snapshot that I got.
I believe the problem you are seeing at this point is due to you passing in driver.get("url1");
I think you mean to be passing in driver.get(url1); (Notice no quotation marks)
To expand on it a little bit, the reason it is throwing the malformed uri exception is that the uri being passed in (url1) does not contain any protocol (http/https).
I think you could have created a maven project which will solve your dependency problem related to the selenium.

Opening Excel using Jexcel

Hi Guys I am trying to display An excel sheet page in JFrame using this code
JFrame frame = new JFrame();
Container cp = frame.getContentPane();
cp.setLayout(new BorderLayout());
File workbookFile = new File("C:\\Workbook.xls");
//Opening the specified file in the JWorkbook component
JWorkbook jWorkbook = new JWorkbook(workbookFile);
cp.add(jWorkbook);
But I am getting the Error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jniwrapper/win32/automation/OleContainer
at excel.open.ExcelOpen.main(ExcelOpen.java:29)
Caused by: java.lang.ClassNotFoundException: com.jniwrapper.win32.automation.OleContainer
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)
... 1 more
Java Result: 1
I Have the following Jar in My ClassPath: jexcel-1.5.23878.jar. Please help.
Need to add ComfyJ to your classpath as well and it will get beyond this error.
You should add comfyj-x.x.jar to the classpath as well.

Unable to create a model class in Jena Library for Parsing or Extratcting URIS from RDF?XML page

I have wriitten following code using the Jena Library to print the URIs on a web page but it is showing a error. The code is
public static void test(String url)
{
try
{
System.out.println("to go");
Model read = ModelFactory.createDefaultModel().read(url);
System.out.println("to go");
StmtIterator si=read.listStatements();
System.out.println("to go");
while(si.hasNext())
{
Statement s=si.nextStatement();
Resource r=s.getSubject();
Property p=s.getPredicate();
RDFNode o=s.getObject();
System.out.println(r.getURI());
System.out.println(p.getURI());
System.out.println(o.asResource().getURI());
}
}
catch(JenaException | NoSuchElementException c)
{ }
}
Can anyone help me further with this problem???
It is not able to create a model read object. The URL is a web address of a xml page.
the following error occurs:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.hp.hpl.jena.util.Metadata.<clinit>(Metadata.java:39)
at com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:37)
at com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.<clinit>(RDFReaderFImpl.java:74)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.<clinit>(ModelCom.java:54)
at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:142)
at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:136)
at web.crawler.WebCrawler.test(WebCrawler.java:52)
at web.crawler.WebCrawler.main(WebCrawler.java:98)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
Add all the jars in the lib/ directory of the distribution. You can use the lib/* form for the classpath.
if you then still get missing org.w3c.dom.ElementTraversal (which is in xml-apis), it's because you have an older version of Xerces and old xml-apis.
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
the library slf4j*.jar is missing from your classpath.
Following are the libraries I had to add more:
import org.slf4j.*;
import org.apache.xerces.util.XMLChar;
import org.w3c.dom.ElementTraversal;
import org.apache.jena.iri.IRIFactory;
I solved it adding all the libraries availables at jena lib dir.
I gess Jena need another lib or jar file, but I dont know the especific .jar, so I add all of them.
Then it works!

Categories

Resources