我下载并安装了GraphDB发行版" graphdb-free-8.5.0" (将GraphDB作为桌面安装运行)。在GraphDB文档中,在 Section 6.5 Programming with GraphDB 中讨论了两个例子,HelloWorld.java
和FamilyRelationsApp.java
。
在路径mvn install
中执行examples/maven-installer
后,如第6.5节所述,然后我尝试编译HelloWorld.java
,我收到以下错误:
HelloWorld.java:3: error: package com.ontotext.graphdb.example.util does not exist
import com.ontotext.graphdb.example.util.EmbeddedGraphDB;
^
HelloWorld.java:4: error: package org.eclipse.rdf4j.model does not exist
import org.eclipse.rdf4j.model.Value;
^
HelloWorld.java:5: error: package org.eclipse.rdf4j.query does not exist
import org.eclipse.rdf4j.query.*;
^
HelloWorld.java:6: error: package org.eclipse.rdf4j.repository does not exist
import org.eclipse.rdf4j.repository.RepositoryConnection;
^
HelloWorld.java:15: error: cannot find symbol
RepositoryConnection connection = EmbeddedGraphDB.openConnectionToTemporaryRepository("rdfs");
^
symbol: class RepositoryConnection
location: class HelloWorld
HelloWorld.java:15: error: cannot find symbol
RepositoryConnection connection = EmbeddedGraphDB.openConnectionToTemporaryRepository("rdfs");
^
symbol: variable EmbeddedGraphDB
location: class HelloWorld
HelloWorld.java:29: error: cannot find symbol
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL,
^
symbol: class TupleQuery
location: class HelloWorld
HelloWorld.java:29: error: cannot find symbol
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL,
^
symbol: variable QueryLanguage
location: class HelloWorld
HelloWorld.java:36: error: cannot find symbol
TupleQueryResult tupleQueryResult = tupleQuery.evaluate();
^
symbol: class TupleQueryResult
location: class HelloWorld
HelloWorld.java:39: error: cannot find symbol
BindingSet bindingSet = tupleQueryResult.next();
^
symbol: class BindingSet
location: class HelloWorld
HelloWorld.java:42: error: cannot find symbol
for (Binding binding : bindingSet) {
^
symbol: class Binding
location: class HelloWorld
HelloWorld.java:45: error: cannot find symbol
Value value = binding.getValue();
^
symbol: class Value
location: class HelloWorld
12 errors
pom.xml
文件如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ontotext.graphdb.examples</groupId>
<artifactId>maven-installer</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>Maven installer for GraphDB</name>
<description>
This simple pom file can be used to install the GraphDB runtime
dependency (of the form graphdb-[edition]-runtime-x.y.z.jar) into
the local Maven repository. Just run "mvn install".
</description>
<build>
<plugins>
<!-- Install the jar file from the lib directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
<execution>
<id>install-graphdb</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.basedir}/../../lib/graphdb-free-runtime-8.5.0.jar</file>
<pomFile>${project.basedir}/graphdb-free-runtime.pom</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
正如我所说,我做了mvn install
并且我成功了。但是,我不知道如何执行HelloWorld.java
。我必须遵循的流程是什么才能执行GraphDB发行版中包含的java文件&#34; graphdb-free-8.5.0&#34;?
答案 0 :(得分:0)
由于无法从Maven Central(公共Maven存储库)获得GraphDB,因此必须将GraphDB运行时jar安装到本地Maven存储库中。
为此,请转到发行版的examples / maven-installer子目录并运行:
mvn install
好的,所以您做到了……而且它一定有效。
(旁注:that documentation seems wrong. The runtime is in Maven Central)
现在,我建议您从喜爱的IDE(Eclipse,Intellij,Netbeans等)中打开示例,作为Maven项目,并尝试从那里运行HelloWorld。
您不一定需要了解Maven的工作原理,但这会有所帮助。首先,它有助于管理外部库并为您编译项目。基本上,javac HelloWorld.java
绝对不够。至少,您需要建立类路径(使用Maven安装的GraphDB JAR文件)和项目类的正确包名称。
答案 1 :(得分:-1)
在<build>
内的pom.xml
标记之后添加这些行:
<dependencies>
<dependency>
<groupId>com.ontotext.graphdb</groupId>
<artifactId>graphdb-free-runtime</artifactId>
<version>8.5.0</version>
</dependency>
</dependencies>
答案 2 :(得分:-2)
不知何故,你错过了依赖关系。您确定在graphdb-free-8.5.0
内声明了依赖项pom.xml
吗?