NoClassDefFoundError when executing a Neo4j Cypher query in Java - java

I tried the following basic example about executing Cypher queries from Java in embedded mode as is, but it shows the errors below:
Code:
package test;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
public class Test {
public static void main(String[] args) {
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase("D:/MI/Tools/neo4j-community-1.9.M02/test2");
// add some data first, keep id of node so we can refer to it
long id;
Transaction tx = db.beginTx();
try {
Node refNode = db.createNode();
id = refNode.getId();
refNode.setProperty("name", "reference node");
tx.success();
} finally {
tx.finish();
}
// let's execute a query now
ExecutionEngine engine = new ExecutionEngine(db);
ExecutionResult result = engine.execute("start n=node(" + id + ") return n, n.name");
System.out.println(result.toString());
}
}
Output:
Exception in thread "main" java.lang.NoClassDefFoundError: com/googlecode/concurrentlinkedhashmap/ConcurrentLinkedHashMap$Builder
at org.neo4j.cypher.internal.LRUCache.<init>(LRUCache.scala:30)
at org.neo4j.cypher.ExecutionEngine$$anon$1.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:54)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:44)
at test.Test.main(Test.java:27)
Caused by: java.lang.ClassNotFoundException: com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder
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)
... 6 more
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)
Is there any problem in the code?
(I use neo4j-community-1.9.M02 and NetBeans IDE 7.2.1)
Thanks.

The problem disappeared after adding the following Java library to the project
http://concurrentlinkedhashmap.googlecode.com/files/concurrentlinkedhashmap-lru-1.3.1.jar

Related

noClassDefFoundError with the Selenium webDriver

i just start using selenium and i've made this little test to try it.
Here the code :
package selenium.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class SeleniumTest {
static WebDriver driver;
static Wait<WebDriver> wait;
public static void main(String[] args) {
driver = new FirefoxDriver();
wait= new WebDriverWait(driver, 30);
driver.get("http://www.google.com/");
boolean result;
try {
driver.findElement(By.name("q"))
.sendKeys("J'aime bien les tests");
driver.findElement(By.name("btnG")).click();
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
System.out.println("Searching ....");
return webDriver
.findElement(By.id("resultStats")) != null;
}
});
result=driver.findElement(By.tagName("body"))
.getText()
.contains("https://en.wikipedia.org
/wiki/Software_testing");
} finally {
driver.close();
}
System.out.println("The test " +
(result ? "succed ! " : "failed"));
}
}
But when i try to run it i have this noClassDefFoundException :
Exception in thread "main" java.lang.NoClassDefFoundError:
org/open/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper
.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
I'm using eclispe mars, and i don't anderstand because i have added the jar to the buildpahth of the project. Here the jars i've added : selenium jars
I took the selenium-java-2.53.0.jar and the selenium-java-2.53.0-srcs.jar and all the jar in the libs directory.
To add the jars i've done:
Right click on the project
Build Path
Add external jars
Select all the jars mentioned above.
Apply
I can compile the class in eclipse and run it (only in eclipse) but when i want to do it with a terminal it's not working.
What am i doing wrong ?
EDIT :
I managed to compile the program by using the command :
javac -cp C:\selenium-2.53.0\*;C:\selenium-2.53.0\libs\* src\selenium\test\SeleniumTest.java
But then when i want to run it with the command :
java -cp C:\selenium-2.53.0\*;C:\selenium-2.53.0\libs\*;. selenium.test.SeleniumTest
It tells me that my class can't be found.

Use Solr to index my database

I don't know why my code java is not compiled.
I need to index my database with solr.
I launch my server with line commande .
>cd C:\Solr\solr-4.10.0\solr-4.10.0\example\solr
>java -jar start.jar
After that i create a new project that contain my class to index database with solr.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
//import org.apache.lucene.index.IndexWriter;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;// CommonsHttpSolrServer;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
public class IndexFiles {
public static void main(String[] args) {
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/");
// i use SolrServer but it generate same error like this from httpSolrServer
//SolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
/*
// TODO Auto-generated method stub
String urlString = "http://localhost:8989/solr";
if (args != null & args.length > 1) {
urlString = args[1];
}
SolrServer solr = new HttpSolrServer("http://localhost:8983/solr"); //CommonsHttpSolrServer(urlString);
try {
indexDocs(solr, new File(args[0]));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
}
}
I get this error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/NoHttpResponseException
at IndexFiles.main(IndexFiles.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.http.NoHttpResponseException
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)
... 1 more
How to resolve this problem?
Sounds like you haven't added the httpclient jar (from dist/solrj-lib) to your classpath.
See the Solrj wiki page topic about: Setting the Classpath

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException

I am new to Cassandra and i am trying to create a column and super-column family with the below program in Eclipse:
import java.util.Arrays;
import java.util.List;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ColumnIndexType;
import me.prettyprint.hector.api.ddl.ColumnType;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
public class HectorTutorial {
private static final String TEST_KEYSPACE = "TestKeyspace";
private static final String TEST_CF= "TestColumnFamily";
private static final String TEST_SUPER= "TestSuperColumn";
private static StringSerializer stringSerializer = StringSerializer.get();
public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
try {
if ( cluster.describeKeyspace(TEST_KEYSPACE ) != null ) {
cluster.dropKeyspace(TEST_KEYSPACE );
}
BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
columnDefinition.setName(stringSerializer.toByteBuffer("TestColumn"));
columnDefinition.setIndexName("TestColumn_idx ");
columnDefinition.setIndexType(ColumnIndexType.KEYS);
columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
columnFamilyDefinition.setKeyspaceName(TEST_KEYSPACE );
columnFamilyDefinition.setName(TEST_CF);
columnFamilyDefinition.addColumnDefinition(columnDefinition);
BasicColumnFamilyDefinition superCfDefinition = new BasicColumnFamilyDefinition();
superCfDefinition.setKeyspaceName(TEST_KEYSPACE );
superCfDefinition.setName(TEST_SUPER);
superCfDefinition.setColumnType(ColumnType.SUPER);
ColumnFamilyDefinition cfDefStandard = new ThriftCfDef(columnFamilyDefinition);
ColumnFamilyDefinition cfDefSuper = new ThriftCfDef(superCfDefinition);
KeyspaceDefinition keyspaceDefinition =
HFactory.createKeyspaceDefinition(TEST_KEYSPACE , "org.apache.cassandra.locator.SimpleStrategy",
1, Arrays.asList(cfDefStandard, cfDefSuper));
cluster.addKeyspace(keyspaceDefinition);
/* Below Code show your Keyspace Schema */
List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
for (KeyspaceDefinition kd : keyspaces) {
if ( kd.getName().equals(TEST_KEYSPACE ) ) {
System.out.println("Name: " +kd.getName());
System.out.println("RF: " +kd.getReplicationFactor());
System.out.println("strategy class: " +kd.getStrategyClass());
List<ColumnFamilyDefinition> cfDefs = kd.getCfDefs();
for (ColumnFamilyDefinition def : cfDefs) {
System.out.println(" CF Type: " +def.getColumnType());
System.out.println(" CF Name: " +def.getName());
System.out.println(" CF Metadata: " +def.getColumnMetadata());
}
}
}
} catch (HectorException he) {
he.printStackTrace();
}
cluster.getConnectionManager().shutdown();
}
}
When I try to execute the program I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException
at me.prettyprint.cassandra.connection.factory.HThriftClientFactoryImpl.createClient(HThriftClientFactoryImpl.java:28)
at me.prettyprint.cassandra.connection.ConcurrentHClientPool.createClient(ConcurrentHClientPool.java:147)
at me.prettyprint.cassandra.connection.ConcurrentHClientPool.<init>(ConcurrentHClientPool.java:53)
at me.prettyprint.cassandra.connection.RoundRobinBalancingPolicy.createConnection(RoundRobinBalancingPolicy.java:67)
at me.prettyprint.cassandra.connection.HConnectionManager.<init>(HConnectionManager.java:67)
at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:67)
at me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:21)
at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:197)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:144)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:133)
at HectorTutorial.main(HectorTutorial.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransportException
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
I have included all the Hector api jars in the classpath and I do not know what is causing this error. Can someone please explain the reason for the error?
It seems you're missing some 3rd party libraries (in this case, Thrift which I believe contains the TTransportException class). Add all required libraries to your classpath too, and let's see if that helps.
Check your "Run/Debug Configurations" under settings.
Ascertain the name of the "main class" you are using. Click to select the name of your current class. Apply. Ok.

NoClassDefFoundError error in crawljax

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import com.crawljax.browser.EmbeddedBrowser.BrowserType;
import com.crawljax.condition.NotXPathCondition;
import com.crawljax.core.CrawljaxRunner;
import com.crawljax.core.configuration.BrowserConfiguration;
import com.crawljax.core.configuration.CrawljaxConfiguration;
import com.crawljax.core.configuration.CrawljaxConfiguration.CrawljaxConfigurationBuilder;
import com.crawljax.core.configuration.Form;
import com.crawljax.core.configuration.InputSpecification;
/**
* Example of running Crawljax with the CrawlOverview plugin on a single-page web app. The crawl
* will produce output using the {#link CrawlOverview} plugin.
*/
class app {
private static final long WAIT_TIME_AFTER_EVENT = 200;
private static final long WAIT_TIME_AFTER_RELOAD = 20;
private static final String URL = "http://demo.crawljax.com";
/**
* Run this method to start the crawl.
*
* #throws IOException
* when the output folder cannot be created or emptied.
*/
public static void main(String[] args) throws IOException {
CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(URL);
builder.crawlRules().insertRandomDataInInputForms(false);
// click these elements
builder.crawlRules().clickDefaultElements();
builder.crawlRules().click("div");
builder.setMaximumStates(10);
builder.setMaximumDepth(3);
builder.crawlRules().clickElementsInRandomOrder(true);
// Set timeouts
builder.crawlRules().waitAfterReloadUrl(WAIT_TIME_AFTER_RELOAD, TimeUnit.MILLISECONDS);
builder.crawlRules().waitAfterEvent(WAIT_TIME_AFTER_EVENT, TimeUnit.MILLISECONDS);
// We want to use two browsers simultaneously.
builder.setBrowserConfig(new BrowserConfiguration(BrowserType.FIREFOX, 1));
CrawljaxRunner crawljax;
crawljax = new CrawljaxRunner(builder.build());
crawljax.call();
}
private static InputSpecification getInputSpecification() {
InputSpecification input = new InputSpecification();
Form contactForm = new Form();
contactForm.field("male").setValues(true, false);
contactForm.field("female").setValues(false, true);
contactForm.field("name").setValues("Bob", "Alice", "John");
contactForm.field("phone").setValues("1234567890", "1234888888", "");
contactForm.field("mobile").setValues("123", "3214321421");
contactForm.field("type").setValues("Student", "Teacher");
contactForm.field("active").setValues(true); input.setValuesInForm(contactForm).beforeClickElement("button").withText("Save");
return input;
}
}
this is a code for crawljax, it give me error at when i run it, error is
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableList
at com.crawljax.core.configuration.CrawljaxConfiguration$CrawljaxConfigurationBuilder.<init>(CrawljaxConfiguration.java:28)
at com.crawljax.core.configuration.CrawljaxConfiguration$CrawljaxConfigurationBuilder.<init>(CrawljaxConfiguration.java:26)
at com.crawljax.core.configuration.CrawljaxConfiguration.builderFor(CrawljaxConfiguration.java:217)
at app.main(NewClass.java:34)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableList
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 java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more
Download and add Guava library on to your classpath:
Guava Library download

Junit Error when trying to run unit test

I am getting this error:
Class not found com.apache.camel.example.tests.ReportIncidentRoutesTest
java.lang.ClassNotFoundException: com.apache.camel.example.tests.ReportIncidentRoutesTest
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)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
This is the updated stack trace for the new error that I am receiving. In the run configuration I do have it pointing to this class so I am not sure why I am still getting this error.
EDIT: -----------------------------------------------------------------------------------
Copy of my Test Class:
package com.apache.camel.example.tests;
import org.apache.camel.CamelContext;
import org.apache.camel.example.reportincident.InputReportIncident;
import org.apache.camel.example.reportincident.OutputReportIncident;
import org.apache.camel.example.reportincident.ReportIncidentEndpoint;
import org.apache.camel.example.reportincident.ReportIncidentRoutes;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.jvnet.mock_javamail.Mailbox;
import junit.framework.Test;
import junit.framework.TestCase;
/**
* Unit test of our routes
*/
public class ReportIncidentRoutesTest extends TestCase {
private CamelContext camel;
// should be the same address as we have in our route
private static String ADDRESS = "http://localhost:8080/part-five/webservices/incident";
protected void startCamel() throws Exception {
camel = new DefaultCamelContext();
camel.addRoutes(new ReportIncidentRoutes());
camel.start();
}
protected static ReportIncidentEndpoint createCXFClient() {
// we use CXF to create a client for us as its easier than JAXWS and works
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ReportIncidentEndpoint.class);
factory.setAddress(ADDRESS);
return (ReportIncidentEndpoint) factory.create();
}
public void testRendportIncident() throws Exception {
// start camel
startCamel();
// assert mailbox is empty before starting
Mailbox inbox = Mailbox.get("blah#blah.com");
assertEquals("Should not have mails", 0, inbox.size());
// create input parameter
InputReportIncident input = new InputReportIncident();
input.setIncidentId("123");
input.setIncidentDate("2008-08-18");
input.setGivenName("Patrick");
input.setFamilyName("joe");
input.setSummary("Blah");
input.setDetails("Blah blah");
input.setEmail("blah#blah.com");
input.setPhone("845 2962 7576");
// create the webservice client and send the request
ReportIncidentEndpoint client = createCXFClient();
OutputReportIncident out = client.reportIncident(input);
// assert we got a OK back
assertEquals("0", out.getCode());
// let some time pass to allow Camel to pickup the file and send it as an email
Thread.sleep(3000);
// assert mail box
assertEquals("Should have got 1 mail", 1, inbox.size());
// stop camel
camel.stop();
}
}
It seems junit 3 is in the classpath when compiling (assuming you don't get compile errors for any use of junit api) but not when running, so there is some classpath mismatch involved.
It seems you run the test through the eclipse test runner, is that configured to the same junit version as the tests are written for?

Categories

Resources