Writing a simple Neo4j server - getting runtime error - neo4j

I am a complete newbie to Neo4j. I am trying to write a simple Neo4j server that would listen on a port of my choice. The code I am using is exactly the same as in the file server.java at the following tutorial
http://hmkcode.com/first-time-neo4j/
The code compiles fine but when I try to run it I get an error (pasted below)
Any help would be appreciated. I am using jre7 and jdk1.8.0_11
For your convenience I have also cut and pasted the code below (exactly the same as in the above link)
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSetting;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.ServerConfigurator;
import org.neo4j.shell.ShellSettings;
public class neoserver {
public static void main(String args[]){
{
GraphDatabaseAPI graphdb = (GraphDatabaseAPI) new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder( "db/graphDB" )
.setConfig( ShellSettings.remote_shell_enabled, GraphDatabaseSetting.TRUE )
.newGraphDatabase();
ServerConfigurator config;
config = new ServerConfigurator( graphdb );
// let the server endpoint be on a custom port
config.configuration().setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, 7575 );
WrappingNeoServerBootstrapper srv;
srv = new WrappingNeoServerBootstrapper( graphdb, config );
srv.start();
}
}
}
ERROR that I get
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/text/StrLookup
at org.neo4j.server.configuration.ServerConfigurator.<init>(ServerConfigurator.java:52)
at jungpagerankserver.neoserver.main(neoserver.java:80)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.text.StrLookup
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

The tutorial you're referencing seems to use Eclipse and not a dedicated build system. Every serious project should not rely on and IDE for building, instead a tool like Maven or Gradle are a good choice.
Make sure you have all transitive dependencies of neo4j-server on your classpath. When using maven, add to your pom.xml with the dependencies section:
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>2.1.3</version>
</dependency>
In case of gradle, use inside dependencies:
compile 'org.neo4j.app:neo4j-server:2.1.3'

Related

DataFlow Runner Fails after upgrading to Beam 2.4.0

I have a simple dataflow job for testing that ran successfully with apache-beam 2.1.0, the code looks something like:
public static void main(String[] args) throws Exception {
DataflowPipelineOptions dataflowOptions = PipelineOptionsFactory.as(DataflowPipelineOptions.class);
dataflowOptions.setProject("MY_PROJECT_ID");
dataflowOptions.setStagingLocation("gs://MY_STAGING_LOC");
dataflowOptions.setTempLocation("gs://MY_TEMP_LOC");
dataflowOptions.setFilesToStage(Collections.singletonList("MY_LOCAL_JAR_FILE.jar"));
dataflowOptions.setRunner(DataflowRunner.class);
dataflowOptions.setNetwork("SOME_NETWORK");
dataflowOptions.setSubnetwork("regions/SOME_REGION/subnetworks/SOME_SUBNETWORK");
dataflowOptions.setZone("SOME_ZONE");
Pipeline p = Pipeline.create(dataflowOptions);
List<String> LINES = Arrays.asList("foobar");
p.apply(Create.of(LINES)).setCoder(StringUtf8Coder.of());
p.run().waitUntilFinish();
}
However, when I migrate to apache-beam 2.4.0, I immediately get the following error when trying to submit a dataflow job via the cli.
Exception in thread "main" java.lang.RuntimeException: Error while staging packages
at org.apache.beam.runners.dataflow.util.PackageUtil.stageClasspathElements(PackageUtil.java:396)
at org.apache.beam.runners.dataflow.util.PackageUtil.stageClasspathElements(PackageUtil.java:273)
at org.apache.beam.runners.dataflow.util.GcsStager.stageFiles(GcsStager.java:76)
at org.apache.beam.runners.dataflow.util.GcsStager.stageDefaultFiles(GcsStager.java:64)
at org.apache.beam.runners.dataflow.DataflowRunner.run(DataflowRunner.java:661)
at org.apache.beam.runners.dataflow.DataflowRunner.run(DataflowRunner.java:174)
at org.apache.beam.sdk.Pipeline.run(Pipeline.java:311)
at org.apache.beam.sdk.Pipeline.run(Pipeline.java:297)
at com.company.app.App.main(App.java:48)
Caused by: java.io.IOException: Error executing batch GCS request
at org.apache.beam.sdk.util.GcsUtil.executeBatches(GcsUtil.java:607)
at org.apache.beam.sdk.util.GcsUtil.getObjects(GcsUtil.java:339)
at org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystem.matchNonGlobs(GcsFileSystem.java:216)
at org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystem.match(GcsFileSystem.java:85)
at org.apache.beam.sdk.io.FileSystems.match(FileSystems.java:123)
at org.apache.beam.sdk.io.FileSystems.matchSingleFileSpec(FileSystems.java:188)
at org.apache.beam.runners.dataflow.util.PackageUtil.alreadyStaged(PackageUtil.java:160)
at org.apache.beam.runners.dataflow.util.PackageUtil.stagePackageSynchronously(PackageUtil.java:184)
at org.apache.beam.runners.dataflow.util.PackageUtil.lambda$stagePackage$1(PackageUtil.java:174)
at org.apache.beam.sdk.util.MoreFutures.lambda$supplyAsync$0(MoreFutures.java:101)
at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.ExecutionException: com.google.api.client.http.HttpResponseException: 404 Not Found
...
I haven't changed any configuration settings.
Further debugging the code, it is failing on a POST request to https://www.googleapis.com/null
Looks like it is a bug which was fixed in the dev branch on Feb 13. Hopefully the fix will be released soon:
Original Issue: https://github.com/google/google-api-java-client/issues/1073
Flawed Fix: https://github.com/google/google-api-java-client/pull/1087
Corrected Fix: https://github.com/google/google-api-java-client/pull/1096
You're hitting this issue: https://github.com/GoogleCloudPlatform/DataflowJavaSDK/issues/607
To fix, add the following if using Gradle:
compile (group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0') {
force = true
}
Or Maven:
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>[1.22.0]</version>
</dependency>

Grails 3.3.0 on Tomcat 7.0.57

We are trying to use response.outputStream in Grails 3.3.0 under Tomcat 7.0.57. However, when any bytes are written to the stream, we get this error:
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/WriteListener
This seems to come from the 3.1 Servlet spec? But Tomcat 7 doesn't support 3.1, only 3.0. However, we've targeted the Grails app to the Tomcat version we are deploying to by doing this in dependencies:
provided "org.springframework.boot:spring-boot-starter-tomcat"
And this, later in the build.gradle file:
war {
ext['tomcat.version'] = '7.0.57'
}
Anything else to try?
Turns out the problem was caused by Groovy introspection upon loading the class OnCommittedResponseWrapper, which has this:
public void setWriteListener(WriteListener writeListener) {
this.delegate.setWriteListener(writeListener);
}
Adding a #GrailsCompileStatic to the method(s) which use the response outputStream in ways like this:
response.outputStream << someBytes
will avoid the introspection which then makes it work on Tomcat 7.

Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean

I'm trying to deploy a simple webapp with an embedded instance of Jetty. My embedded test code is:
public static void main(String[] args) throws Exception{
Server server = new Server(8181);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/");
webAppContext.setWar(ContUtil.warPath + ContUtil.warName);
server.setHandler(webAppContext);
logger.info("starting jetty...");
server.start();
server.join();
}
but I got the following error:
Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/C:/Users/lingguo/AppData/Local/Temp/jetty-0.0.0.0-8181-MemCloud-Web-1.0-SNAPSHOT.war-_-any-6830790104248388668.dir/webapp/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:232)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:180)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
... 23 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/D:/Program%20Files%20(x86)/apache-maven-2.2.1/repo/org/apache/struts/struts2-core/2.2.1/struts2-core-2.2.1.jar!/struts-default.xml:29:72 - bean - jar:file:/C:/Users/lingguo/AppData/Local/Temp/jetty-0.0.0.0-8181-MemCloud-Web-1.0-SNAPSHOT.war-_-any-6830790104248388668.dir/webapp/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:216)
... 26 more
I've referenced many similar answers about this problems, for example: Struts2 Error when Deploying: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory; Most of the similar problems are caused by jar packages conflict of different versions. But my problem is a little different. I ensure that there is only one version of struts2-core (2.2.1) in my classpath.
I checked the error message, I think that jetty creates a tmp file, that is: /C:/Users/lingguo/AppData/Local/Temp/jetty-0.0.0.0-8181-MemCloud-Web-1.0-SNAPSHOT.war-_-any-6830790104248388668.dir,and the jar struts2-core-2.2.1 is confict with the jar in my local maven repository.
Could anybody know where is going wrong? Thanks in advance!

Loading beans from Grails Script

I'm running a grails script to load a bean from the grails application, however, it seems that I have a dependency problem. Here it's my code:
import grails.spring.BeanBuilder
import org.springframework.context.ApplicationContext
target(main: "Script to load location information into Solr") {
println "Hello script"
def bb = new BeanBuilder()
ApplicationContext appContext = bb.createApplicationContext()
def service = appContext.getBean("solrjService")
}
setDefaultTarget(main)
When I execute the script I get the following stacktrace:
main:
Hello script
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
at org.slf4j.LoggerFactory.staticInitialize(LoggerFactory.java:83)
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:73)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
at grails.spring.BeanBuilder.<clinit>(BeanBuilder.java:84)
Any ideas ??
Thanks for your time
If your read the call stack, it's obviously a problem with SLF4J.
See http://slf4j.org/faq.html#IllegalAccessError
It looks like you may be mixing versions of the SLF4J jars, and getting a conflict.
But, of course, Burt is correct - once you get past this, you will find that you've initialized you BeanBuilder's ApplicationContext with no beans.
I had to include the target _GrailsBootstrap to be able to load my beans http://grails.org/doc/latest/guide/commandLine.html#creatingGantScripts
includeTargets << grailsScript("_GrailsBootstrap")
target ('default': "Load Location Information to Solr Server") {
depends(configureProxy, packageApp, classpath, loadApp, configureApp)
def service = appCtx.getBean('solrjService')
println service.getLocationSuggestion("Barcelona")
}
I run script his way (that's why I had a classpath problem)
grails run-script scripts/Myscript.groovy
Then now, I run it this way
grails Myscript.groovy
and I don't have any classpath problems :D
thanks for your help

Grails - Selenium-RC plugin - Starting Selenium server

I am trying to set up Selenium in my Grails project via the Selenium-RC plugin.
I have then run the grails install-plugin selenium-rc command.
Then, I have run the grails create-selenium-test firstTest command, and added the following content to it:
import grails.plugins.selenium.*
import org.junit.*
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
#Mixin(SeleniumAware)
class FirstTestTests {
#Before void setUp() {
}
#After void tearDown() {
super.tearDown()
}
#Test void something() {
selenium.open "/"
assertTrue selenium.isTextPresent("Bem vindos")
}
}
When I run the test on Ubuntu 11.04, Grails starts the default firefox browser (version 8.0) but freezes here after printing this to the console output:
Server running. Browse to http://localhost:8080/
[groovyc] Compiling 1 source file to /home/alessandro/Documents/[...]/target/test-classes/selenium
Starting Selenium server on port 4444 ...
Starting Selenium session for http://www.mywebsite.com/ ...
When I interrupt the test via Ctrl + C, it throws the following error message:
Error running selenium tests: java.lang.RuntimeException: Could not contact Selenium Server; have you started it on 'localhost:4444' ?
Read more at http://seleniumhq.org/projects/remote-control/not-started.html
Connection refused
java.lang.RuntimeException: Could not contact Selenium Server; have you started it on 'localhost:4444' ?
Read more at http://seleniumhq.org/projects/remote-control/not-started.html
Connection refused
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:86)
at com.thoughtworks.selenium.Selenium$start$0.call(Unknown Source)
at grails.plugins.selenium.SeleniumWrapper.start(SeleniumWrapper.groovy:90)
at com.thoughtworks.selenium.Selenium$start.call(Unknown Source)
at grails.plugins.selenium.SeleniumRunner.startSelenium(SeleniumRunner.groovy:35)
at grails.plugins.selenium.SeleniumRunner$startSelenium.call(Unknown Source)
at _Selenium_groovy$_run_closure2.doCall(_Selenium_groovy:50)
at _Events$_run_closure3.doCall(_Events.groovy:32)
at _GrailsEvents_groovy$_run_closure5.doCall(_GrailsEvents_groovy:58)
at _GrailsEvents_groovy$_run_closure5.call(_GrailsEvents_groovy)
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:265)
at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174)
at TestApp$_run_closure1.doCall(TestApp.groovy:82)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
I have read the plugin doc, which says the server is started by the plugin, which is backed by the console output before the test freezes. I do not really know where to go from there.
I have browse the web but the only piece advice I have found was to add the selenium-server.jar to java path, which seems to be covered by the plugin already.
Any help greatly appreciated.
I had the same issue - you can see my question. the problem I guess is the firefox - I changed it to Chrome and it worked out of the box.
You just need to replace
browser = "*firefox"
with
browser = "*googlechrome"
in SeleniumConfig
Thank you very much. It worked as you said. For those who uses Chromium as well under Ubuntu, here is what I added to configure the SeleniumConfig file:
browser = "*googlechrome /usr/lib/chromium-browser/chromium-browser"
Now I get:
Stopping Selenium server ...
java.lang.RuntimeException: Can't start SslRelay: server is not started (perhaps it was just shut down?)
at org.openqa.selenium.server.ProxyHandler.getSslRelayOrCreateNew(ProxyHandler.java:656)
at org.openqa.selenium.server.ProxyHandler.handleConnect(ProxyHandler.java:589)
at org.openqa.selenium.server.ProxyHandler.handle(ProxyHandler.java:274)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:245)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
when after the test has passed.
I'll investigate on it. Thanks mkk

Resources