castagna / jena-examples Goto Github PK
View Code? Open in Web Editor NEWA collection of ready to use, small and self contained examples on how to use Apache Jena
License: Apache License 2.0
A collection of ready to use, small and self contained examples on how to use Apache Jena
License: Apache License 2.0
Apache Jena - Examples ====================== This is a collection of small and simple examples on how to use Apache Jena to handle RDF data. How examples are organised -------------------------- Examples are grouped by name: ExampleX_NN.java and are progressively numbered from the simplest to the slightly more advanced ones. A good learning path is to start from the ExampleIO_NN.java which show how to use Apache Jena to read (i.e. parse) or write (i.e. serialize) RDF data in various format. Apache Jena supports RDF/XML, N3, Turtle, N-Triples, etc. RIOT is a new parsing subsystem for Jena, if you are interested you can look at the ExampleRIOT_NN.java files. The examples named ExampleAPI_NN.java show how to use the Jena Model APIs to create or manipulate RDF data. SPARQL is the query language used for data in RDF stores and ARQ is the query engine included in Jena. The examples named ExampleARQ_NN.java show how to run SPARQL queries and iterate through the results. An extension for ARQ to run free text searches is called LARQ (i.e. Lucene + ARQ), if you are interested, you can look at ExampleLARQ_NN.java files. TDB is the native store included in Apache Jena. The examples named ExampleTDB_NN.java files show how to load data into TDB and run SPARQL queries. If you are interested in ontologies and inference look at ExampleONT_NN.java and ExampleINF_NN.java. Requirements ------------ The only requirements are a Java JDK 1.8 and Apache Maven. Instructions on how to install Maven are here: http://maven.apache.org/download.html#Installation If you use Eclipse, it is recommended to set M2_REPO in Eclipse (once): mvn -Declipse.workspace=/path/to/your/workspace eclipse:add-maven-repo Once you have Maven installed, verify with: mvn -version Then run (once) this to download all the necessary dependencies: cd jena-example mvn package You can import the project in Eclipse via File > Import... > Existing Projects into Workspace You can run mvn eclipse:eclipse to re-generate Eclipse .project and .classpath files automatically from your pom.xml file. You can run mvn dependency:copy-dependencies to copy all the *.jar files in the target/dependency/ directory. You can run mvn dependency:tree to visualize a tree of all the dependency and understand which jar is required by other jar files. Have fun!
When excecute ...\main\java\org\apache\jena\examples\javac ExampleIO_01.java
7 errors in total
Runtime exception, when run example org.apache.jena.examples.ExampleAPI_01
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.jena.rdf.model.impl.IO_Ctl.callByRefection(IO_Ctl.java:64)
at org.apache.jena.rdf.model.impl.IO_Ctl.init(IO_Ctl.java:36)
at org.apache.jena.util.FileManager.(FileManager.java:86)
at org.apache.jena.examples.ExampleAPI_01.main(ExampleAPI_01.java:31)
Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
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)
at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at sun.util.xml.PlatformXmlPropertiesProvider.getLoadingDoc(PlatformXmlPropertiesProvider.java:106)
at sun.util.xml.PlatformXmlPropertiesProvider.load(PlatformXmlPropertiesProvider.java:78)
at java.util.Properties$XmlSupport.load(Properties.java:1201)
at java.util.Properties.loadFromXML(Properties.java:881)
at org.apache.jena.util.Metadata.read(Metadata.java:75)
at org.apache.jena.util.Metadata.addMetadata(Metadata.java:53)
at org.apache.jena.util.Metadata.(Metadata.java:47)
at org.apache.jena.JenaRuntime.(JenaRuntime.java:89)
at org.apache.jena.riot.system.stream.JenaIOEnvironment.getGlobalConfigPath(JenaIOEnvironment.java:69)
at org.apache.jena.riot.system.stream.JenaIOEnvironment.getLocationMapper(JenaIOEnvironment.java:45)
at org.apache.jena.riot.system.stream.StreamManager.makeDefaultStreamManager(StreamManager.java:73)
at org.apache.jena.riot.system.stream.StreamManager.(StreamManager.java:85)
at org.apache.jena.riot.adapters.AdapterFileManager.makeGlobal(AdapterFileManager.java:147)
at org.apache.jena.riot.adapters.AdapterFileManager.get(AdapterFileManager.java:106)
at org.apache.jena.riot.IO_Jena.wireIntoJena(IO_Jena.java:35)
at org.apache.jena.riot.RIOT.init(RIOT.java:66)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
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)
... 45 more
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.jena.JenaRuntime
at org.apache.jena.util.LocationMapper.getGlobalConfigPath(LocationMapper.java:241)
at org.apache.jena.util.LocationMapper.get(LocationMapper.java:69)
at org.apache.jena.util.FileManager.makeGlobal(FileManager.java:129)
at org.apache.jena.util.FileManager.get(FileManager.java:95)
at org.apache.jena.examples.ExampleAPI_01.main(ExampleAPI_01.java:31)
Later, added following dependency in pom.xml to solve this issue.
xml-apis
xml-apis
1.4.01
“If you are interested in ontologies and inference look at ExampleONT_NN.java
and ExampleINF_NN.java.” - README.txt
I look for java file "ExampleINF_NN.java" in "jena-examples/src/main/java", but I can't find any file named after "ExampleINF", no matter github online or local download.
I am following closely the instructions provided in setting up jena-examples. However, after I executed "mvn package" command, I received the following error in Maven:
[ERROR] Failed to execute goal on project jena-examples: Could not resolve dependencies for project org.apache.jena:jena-example
s:jar:0.1-SNAPSHOT: The following artifacts could not be resolved: org.apache.jena:jena-core:jar:2.7.4-SNAPSHOT, org.apache.jena
:jena-iri🫙0.9.4-SNAPSHOT, org.apache.jena:jena-arq🫙2.9.4-SNAPSHOT, org.apache.jena:jena-tdb🫙0.9.4-SNAPSHOT: Could no
t find artifact org.apache.jena:jena-core:jar:2.7.4-SNAPSHOT in apache-snapshots-repo (https://repository.apache.org/content/rep
ositories/snapshots/) -> [Help 1]
Is there anything I didn't setup probably? Or Was it because the Jena respository for Maven is not updated?
Please use another resource in ExampleIO_02.
mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Jena Examples 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.070s
[INFO] Finished at: Fri Dec 13 15:16:28 EST 2013
[INFO] Final Memory: 7M/239M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project jena-examples: Could not resolve dependencies for project org.apache.jena:jena-examples:jar:0.1-SNAPSHOT: The following artifacts could not be resolved: org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT, org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT, org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT: Failure to find org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-snapshots-repo has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
With -e switch ..
mvn package -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Jena Examples 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.050s
[INFO] Finished at: Fri Dec 13 15:31:35 EST 2013
[INFO] Final Memory: 7M/239M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project jena-examples: Could not resolve dependencies for project org.apache.jena:jena-examples:jar:0.1-SNAPSHOT: The following artifacts could not be resolved: org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT, org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT, org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT: Failure to find org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-snapshots-repo has elapsed or updates are forced -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project jena-examples: Could not resolve dependencies for project org.apache.jena:jena-examples:jar:0.1-SNAPSHOT: The following artifacts could not be resolved: org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT, org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT, org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT: Failure to find org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-snapshots-repo has elapsed or updates are forced
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:210)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:117)
at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:258)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:201)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project org.apache.jena:jena-examples:jar:0.1-SNAPSHOT: The following artifacts could not be resolved: org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT, org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT, org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT: Failure to find org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-snapshots-repo has elapsed or updates are forced
at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:189)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:185)
... 22 more
Caused by: org.sonatype.aether.resolution.DependencyResolutionException: The following artifacts could not be resolved: org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT, org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT, org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT: Failure to find org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-snapshots-repo has elapsed or updates are forced
at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:375)
at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:183)
... 23 more
Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: The following artifacts could not be resolved: org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-iri:jar:0.9.5-SNAPSHOT, org.apache.jena:jena-arq:jar:2.10.0-SNAPSHOT, org.apache.jena:jena-tdb:jar:0.10.0-SNAPSHOT, org.apache.jena:jena-larq:jar:1.0.1-SNAPSHOT: Failure to find org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-snapshots-repo has elapsed or updates are forced
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:538)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:358)
... 24 more
Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Failure to find org.apache.jena:jena-core:jar:2.10.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-snapshots-repo has elapsed or updates are forced
at org.sonatype.aether.impl.internal.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:230)
at org.sonatype.aether.impl.internal.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:204)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:427)
... 26 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
It seems that the endpoint
'http://api.kasabi.com/dataset/italy/apis/sparql'
which is used in several cases of SPARQL tutorials, is not working any more. Running the code will throw
java.lang.Long cannot be cast to java.lang.Integer
exception, can anybody provide an option to this or if there exists already some solutions that I didn't follow ?
Great that you have examples in place.
But isn't the first thing to have for every example a description?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.