The easiest way to run an example project in Eclipse Che is to go to the Eclipse Che website and provision a project using their handy web tools. Executing a Java example is as simple as importing a project using the project importer under the file menu. In my case, I used my fork of Paolo Castagna’s Apache Jena Examples project that I updated to handle dependencies better. Using the importer will create a full stack and workspace that is ready for this project, but it looks like it gets the default run configurations wrong.
The problems with the example in my repository may only be for me since it is a pretty basic set of examples. Read on for how we can fix it and execute Java examples from the terminal in Che.
If you are using my example, you can get it running from the command line. First, navigate to the pom.xml file and add the following in the build plugins section:
</plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.1</version> <configuration> <!-- put your configurations here --> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin>
This will create a “shaded” jar file when the mvn package target is executed so that the classes in this example easily using the jar as the complete class path. Next, go to the terminal, change directories into the jena-examples project, and execute the build command
mvn package
The final step is to execute the jar with one of the example classes specified, which can be done like so
java -cp jena-examples-0.1-SNAPSHOT.jar org.apache.jena.examples.ExampleIO_01
In this case the output should look like the following since this example is a simple Resource Description Framework (RDF) I/O example with Jena that translates between two formats:
---- Turtle ---- @prefix : . @prefix foaf: . :charlie foaf:knows :alice ; foaf:name "Charlie" . :alice a foaf:Person ; foaf:knows :snoopy , :charlie , :bob ; foaf:mbox ; foaf:name "Alice" . :bob foaf:knows :charlie ; foaf:name "Bob" . ---- RDF/XML ---- Charlie Alice Bob ---- RDF/XML Abbreviated ---- Bob Alice Charlie ---- N-Triples ---- . "Charlie" . . . . . "Alice" . . . "Bob" . ---- RDF/JSON ---- { "http://example.org/charlie" : { "http://xmlns.com/foaf/0.1/name" : [ { "type" : "literal" , "value" : "Charlie" } ] , "http://xmlns.com/foaf/0.1/knows" : [ { "type" : "uri" , "value" : "http://example.org/alice" } ] } , "http://example.org/alice" : { "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : [ { "type" : "uri" , "value" : "http://xmlns.com/foaf/0.1/Person" } ] , "http://xmlns.com/foaf/0.1/mbox" : [ { "type" : "uri" , "value" : "mailto:alice@example.org" } ] , "http://xmlns.com/foaf/0.1/name" : [ { "type" : "literal" , "value" : "Alice" } ] , "http://xmlns.com/foaf/0.1/knows" : [ { "type" : "uri" , "value" : "http://example.org/snoopy" } , { "type" : "uri" , "value" : "http://example.org/charlie" } , { "type" : "uri" , "value" : "http://example.org/bob" } ] } , "http://example.org/bob" : { "http://xmlns.com/foaf/0.1/name" : [ { "type" : "literal" , "value" : "Bob" } ] , "http://xmlns.com/foaf/0.1/knows" : [ { "type" : "uri" , "value" : "http://example.org/charlie" } ] } }
Here’s a screenshot of my Che setup, which is running on Openshift.io.
If you have questions or comments, feel free to reach out on Twitter to @jayjaybillings.
1 Comment
Comments are closed.