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

From Info216
Line 29: Line 29:
  
 
'''Here is a smart thing to do from the start:'''  
 
'''Here is a smart thing to do from the start:'''  
Decide on a folder that you always use for downloading, unpacking and installing your own software packages. Different software, like Java, Jena and Eclipse will go to separate subfolder of this folder. This way you will always 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". ''It is smart to use folder names with about blank characters (spaces) in them, because they cause problems for some software packages.''
+
Decide on a folder that you always use for downloading, unpacking and installing your own software. Different software packages you install - like Java, Jena and Eclipse - will go into separate subfolders of this folder. This way you will always 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". ''It is good practice to use folder names without blank characters (spaces) in them, because they can cause problems for some software packages.''
  
 
Download and unpack the Eclipse Oxygen IDE for Java Developers: go to https://eclipse.org/downloads/ and Get Eclipse Oxygen for your computer and operating system. This will download an installer program.  
 
Download and unpack the Eclipse Oxygen IDE for Java Developers: go to https://eclipse.org/downloads/ and Get Eclipse Oxygen for your computer and operating system. This will download an installer program.  
Line 36: Line 36:
 
(I use folders called "C:\Programs\Eclipse-oxygen" and "/opt/Eclipse-oxygen" for this.)
 
(I use folders called "C:\Programs\Eclipse-oxygen" and "/opt/Eclipse-oxygen" for this.)
  
Start Eclipse from the start menu (on Linux, go to the folder where you installed it and start the "eclipse" program). If you want to, you can make a shortcut to the "eclipse" program from your desktop or program bar.
+
Start Eclipse from the start menu (on Linux, go to the folder where you installed it and start the "eclipse" program). If you want to, you can make a shortcut to the "eclipse" program from your desktop or task bar.
  
Tell Eclipse that you are going to use the JDK 8 you just downloaded.
+
Tell Eclipse that you are going to use the JDK 8 you just downloaded: Window -> Preferences -> Java -> Installed JREs -> Add...
Window -> Preferences -> Java -> Installed JREs -> Add...
 
  
 
Download and unpack Jena 3.6.0: https://jena.apache.org/download/ . (I use folders called "C:\Programs\Jena" and "/opt/Jena" for this.)
 
Download and unpack Jena 3.6.0: https://jena.apache.org/download/ . (I use folders called "C:\Programs\Jena" and "/opt/Jena" for this.)

Revision as of 18:02, 10 January 2018

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 the most recent update of Java 8 (such as u151): https://www.java.com/en/download/ . Java 9 is also out now, and you can try it out if you want. But because Java 9 is so new, we will stay with Java 8 this spring.

Download and unpack a Java SE Development Kit (JDK) 8 (the most recent update, such as u151/152): http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk .

Here is a smart thing to do from the start: Decide on a folder that you always use for downloading, unpacking and installing your own software. Different software packages you install - like Java, Jena and Eclipse - will go into separate subfolders of this folder. This way you will always 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". It is good practice to use folder names without blank characters (spaces) in them, because they can cause problems for some software packages.

Download and unpack the Eclipse Oxygen IDE for Java Developers: go to https://eclipse.org/downloads/ and Get Eclipse Oxygen for your computer and operating system. This will download an installer program.

Start the installer program (on Linux, you go to the folder where you installed it and start the "eclipse-inst" program). Choose "Eclipse IDE for Java Developers" and choose an installation folder. (I use folders called "C:\Programs\Eclipse-oxygen" and "/opt/Eclipse-oxygen" for this.)

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

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

Download and unpack Jena 3.6.0: https://jena.apache.org/download/ . (I use folders called "C:\Programs\Jena" and "/opt/Jena" for this.)

While you are at it, you can download and unpack Apache Jena Fuseki too. You will need it later.

Re-start Eclipse 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 Eclipse toolbar.

Go to the "INFO216 Wiki" page in this wiki and download the file log4j.properties . You can get rid of all the "log4j warnings" by copying the log4j.properties file into exactly the same directory as your Java-files.

If you have more time...

If you have more time you can continue extending your graph with some of the stuff from lab 2: "Cade Tracy lives in 1516 Henry Street, Berkeley, California 94709, USA. He has a B.Sc. in biology from the University of California, Berkeley from 2011. His interests include birds, ecology, the environment, photography and travelling. He has visited Canada and France." Try to use as many different methods as possible to create the triples.