Hands-on: Configure & Run Plain Java Apps in Che

Tyler Jewell
Eclipse Che Blog
Published in
5 min readJul 27, 2016

This post will demonstrate how to develop and run standard Java applications in Eclipse Che. We’ll start by creating and running a simple “Hello World” example using one of the Che template apps. Then we’ll clone a plain Java project from git, configure the classpath, add a library to classpath and run the application.

Create an Empty Java Workspace

In the user dashboard select “Workspaces” from the left nav and hit the “+” in the upper-right corner to create a new workspace. Then select Java and hit the “Create Workspace” button at the bottom:

You’ll be taken to the workspace details screen where you can hit the ‘Run’ button to start the workspace and, when it completes, hit the ‘Open’ button in the top right to open the IDE.

Create a Java Application from a Template

After creating and running your workspace, open the IDE. You’ll see the image below.

plain_a2 (1)

In the Che IDE menu, select Workspace > Create Project.

plain_b2

In the ‘Create New Project’ pop-up, select “Java” from the language chooser and type the name of the project, then click the ‘Create’ button.

plain_a3

Expand the project and open the Main.java class. The Java file contains a main method and the project is pre-configured for compiling and running.

plain_a4

To run the application we’ll need to create a command for it using the interactive menu in the Che IDE. Go to Run > Edit Commands.

plain_a01

In the ‘Commands’ pop-up, we need to select ‘Java type’ and click the ‘+’ button.

This creates a new Java command. Replace the default name with something more appropriate like ‘start app’. The command defaults will work for our plain Java app, so we can simply hit Save.

The new command appears on the the toolbar panel in the Che IDE. Click on the icon arrow to run the application.

plain_a8

In the console panel you will see a new entry for your command and in the console output will be the command that was run (in green at the top) and “Hello World!” output. Congratulations!

Because we consistently sync content from the container file system and the project explorer, if you open folder ‘bin’ you’ll see the compiled Main.class java file.

Configure and run an application cloned from GitHub

In the Che IDE menu select Workspace -> Import Project -> Git and type the repository url (e.g. https://github.com/artaleks9/plain-java-project.git). You can do this in the same workspace because Che workspaces allow multiple projects inside.

After importing the project the Project Configuration pop-up will appear. Select type Java and press the Next button. Hit ‘Browse’ beside the Source Folder entry and select the project’s src folder.

plain_g3

In our example, the project already includes folder store with a library (mockito jar), so we also can add it to classpath by hitting Browse next to the Library Folder entry. The jar will be automatically added to project classpath during compilation and runtime and made available in the code-assistant when you hit ctrl+space. Click Save.

plain_g5

We can expand the project and make sure that it is configured (if it is you’ll see the package indicator on the com.codenvy package entry (if com and codenvy appear as separate, normal folders something is misconfigured).

We can easily change configuration of a project late to add / replace the source folder, or add / delete the library JAR.

plain_g7 (1)

To try this let’s upload a new JAR to the project. First download junit-4.4.jar from https://sourceforge.net/projects/junit/files/junit/4.4/junit-4.4.jar/download.

Next select the ‘store’ folder in the Project Explorer. Then hit Project > Upload File to add the JUnit JAR to that directory. Now choose Project > Configure Classpath. Select Add JAR and choose the desired JAR in the Select Path widget.

plain_g8

You can add folder test to project classpath as source folder.

As you see, we added folder to project classpath

We can also easily add or unmark a folder to the project classpath as source using context menu in project explorer.

plain_g12

Now that we’ve made some changes to the project, we need a new Command to run this project (because the command we created previously will look for the Main.java in the source folder, not in a package).

Choose Run > Edit Commands. Create a new Java command. The best practice when you have multiple projects is to name each command with either of the following styles:

{project.name} : {command name}
{project.nickname} : {command name}

In this case let’s call the command “pjp : run”. Now select Browse beside the Main Class entry box — select your Main class.

Hit “Save.”

When we try to start the application and the running fails because in our project is not present the folder bin.

Let’s create the folder bin and try to run again.

plain_g17

Well done! The application has successfully started.

We’ve now seen how to harness Che for plain Java projects. Good luck, and enjoy coding with Che!

--

--

Tyler Jewell
Eclipse Che Blog

MD @ Dell Tech Capital. BOD @ NS1, Orion Labs. Prev: CEO @ WSO2, CEO @ Codenvy (acq. by RHT). Invest @ Sauce Labs, Cloudant, ZeroTurnaround, InfoQ, Sourcegraph.