Difference between revisions of "Lab: Getting started with Eclipse, Java and Jena"

From Info216
Line 5: Line 5:
  
 
==Preparations==
 
==Preparations==
For Ecplise, Vogella.com has a good, but loong, tutorial: [http://www.vogella.com/tutorials/Eclipse/article.html Eclipse IDE - Tutorial by Vogella.com]. A good start is to look at sections 1 and 5-7.
+
For Eclipse, Vogella.com has a good, but loong, tutorial: [http://www.vogella.com/tutorials/Eclipse/article.html Eclipse IDE - Tutorial by Vogella.com]. A good start is to look at sections 1 and 5-7.
  
 
For Jena, you can look at these pages from lecture 1, in particular:
 
For Jena, you can look at these pages from lecture 1, in particular:
 
* [http://jena.apache.org/documentation/rdf/index.html The core RDF API]  
 
* [http://jena.apache.org/documentation/rdf/index.html The core RDF API]  
 
* [http://jena.apache.org/tutorials/rdf_api.html An introduction to RDF and the Jena RDF API]  
 
* [http://jena.apache.org/tutorials/rdf_api.html An introduction to RDF and the Jena RDF API]  
* [https://jena.apache.org/documentation/javadoc/jena/ Package org.apache.jena.rdf.model]
 
  
 
==Relevant Jena classes/interfaces (and methods)==
 
==Relevant Jena classes/interfaces (and methods)==
 +
From [https://jena.apache.org/documentation/javadoc/jena/ Package org.apache.jena.rdf.model]:
 +
* ModelFactory (createDefaultModel),
 +
* Model (createResource, createProperty, write)
 +
* Resource (addLiteral)
 +
* Property
  
*ModelFactory (createDefaultModel),
+
(For example, click "All classes" in the upper-left frame.
*Model (createResource, createProperty, write)
 
*Resource (addLiteral)
 
*Property
 
 
 
(The JavaDoc is here: https://jena.apache.org/documentation/javadoc/jena/ .
 
For example, click "All classes" in the upper-left frame.
 
 
Then you can focus the lower-left frame with a browser click, and use
 
Then you can focus the lower-left frame with a browser click, and use
 
browser search (often Ctrl-F) to find the class or interface you want.)
 
browser search (often Ctrl-F) to find the class or interface you want.)
Line 31: Line 29:
 
http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk.
 
http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk.
 
(It is smart to download and unpack all the files into subfolders of the same folder, so you know where you have them.
 
(It is smart to download and unpack all the files into subfolders of the same folder, so you know where you have them.
On my Windows computer, I put everything under a folder called "C:\Programs". On Linux, I use the folder "/opt".
+
On my Windows computer, I put everything under a folder called "C:\Programs\Java". On Linux, I use the folder "/opt/Java".)
  
 
Download and unpack Eclipse Neon.2 IDE for Java Developers: go to
 
Download and unpack Eclipse Neon.2 IDE for Java Developers: go to
 
https://eclipse.org/downloads/ and Get Eclipse Neon for your computer and operating system.
 
https://eclipse.org/downloads/ and Get Eclipse Neon for your computer and operating system.
(There are many versions of Eclipse. You need one for Java Developers, but not anything with Enterprise.)
+
(There are many versions of Eclipse. You need one for "Java Developers", but not anything with "Enterprise" or "EE".)
  
Start Eclipse by going to the directory where you installed it and doubleclick the "eclipse" program.
+
Start Eclipse from the start menu (on Linux, go to the directory where you installed it and doubleclick the "eclipse" program).
 
If you want to, you can make a shortcut to the "eclipse" program from your desktop or program bar.
 
If you want to, you can make a shortcut to the "eclipse" program from your desktop or program bar.
  
Line 44: Line 42:
  
 
Download and unpack Jena 3.1.1, both the binary and the source distribution:
 
Download and unpack Jena 3.1.1, both the binary and the source distribution:
https://jena.apache.org/download/
+
https://jena.apache.org/download/ .
 +
(I use folders called "C:\Programs\Jena" and "/opt/Jena" for this.)
  
(While you are at it, you can just download and unpack Apache Jena Fuseki too.
+
While you are at it, you can just download and unpack Apache Jena Fuseki too.  
Take both the 2.4.1 and 1.4.1 distributions for now.)
+
Take both the 2.4.1 and 1.4.1 distributions for now. We will need at least one of them later.
  
 
Start Eclipse again and create an Eclipse project for Java (File -> New -> Java Project).
 
Start Eclipse again and create an Eclipse project for Java (File -> New -> Java Project).
Line 55: Line 54:
 
Write a Java program that creates a single triple and writes it out.
 
Write a Java program that creates a single triple and writes it out.
 
Use the Classes/interfaces and methods listed above.
 
Use the Classes/interfaces and methods listed above.
The simplest way to run the program is using the green "play" buttom in the top toolbar.
+
The simplest way to run the program is using the green "play" button in the top toolbar.
  
 
Go to the File Storage here in the portal and download the file log4j.properties from the Misc folder.
 
Go to the File Storage here in the portal and download the file log4j.properties from the Misc folder.

Revision as of 15:11, 12 January 2017

Lab 1: Getting started with Eclipse, Java and Jena

Topics

Installation of and introduction to Eclipse and Jena.

Preparations

For Eclipse, Vogella.com has a good, but loong, tutorial: Eclipse IDE - Tutorial by Vogella.com. A good start is to look at sections 1 and 5-7.

For Jena, you can look at these pages from lecture 1, in particular:

Relevant Jena classes/interfaces (and methods)

From Package org.apache.jena.rdf.model:

  • ModelFactory (createDefaultModel),
  • Model (createResource, createProperty, write)
  • Resource (addLiteral)
  • Property

(For example, click "All classes" in the upper-left frame. Then you can focus the lower-left frame with a browser click, and use browser search (often Ctrl-F) to find the class or interface you want.)

Tasks

Download and install a Java Runtime Environment (JRE) if you do not have it, for example Java 8 update 111: https://www.java.com/en/download/

Download and unpack Java SE Development Kit (JDK) 8 (e.g. update 111/112): http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk. (It is smart to download and unpack all the files into subfolders of the same folder, so you know where you have them. On my Windows computer, I put everything under a folder called "C:\Programs\Java". On Linux, I use the folder "/opt/Java".)

Download and unpack Eclipse Neon.2 IDE for Java Developers: go to https://eclipse.org/downloads/ and Get Eclipse Neon for your computer and operating system. (There are many versions of Eclipse. You need one for "Java Developers", but not anything with "Enterprise" or "EE".)

Start Eclipse from the start menu (on Linux, go to the directory where you installed it and doubleclick the "eclipse" program). If you want to, you can make a shortcut to the "eclipse" program from your desktop or program bar.

Tell Eclipse that you are going to use the JDK 8 you just downloaded. Help -> Preferences -> Java -> Installed JREs -> Add...

Download and unpack Jena 3.1.1, both the binary and the source distribution: https://jena.apache.org/download/ . (I use folders called "C:\Programs\Jena" and "/opt/Jena" for this.)

While you are at it, you can just download and unpack Apache Jena Fuseki too. Take both the 2.4.1 and 1.4.1 distributions for now. We will need at least one of them later.

Start Eclipse again and create an Eclipse project for Java (File -> New -> Java Project). Copy or link the Jena JAR-files into the project: .../apache-jena-3.1.1/lib/*.jar .

Write a Java program that creates a single triple and writes it out. Use the Classes/interfaces and methods listed above. The simplest way to run the program is using the green "play" button in the top toolbar.

Go to the File Storage here in the portal and download the file log4j.properties from the Misc folder. You can get rid of the "log4j warnings" by copying the log4j.properties file into exactly the same directory as your Java-files.

Honour tasks

(For some of the later labs we will also suggest more advanced tasks for those of you who are more experienced.)