Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Getting Started With Java in Eclipse Che

DZone's Guide to

Getting Started With Java in Eclipse Che

Eclipse Che was developed specifically for Java devs. Here's how to get toing with Java using Eclipse Che, from starting Che to developing in the IDE.

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

Eclipse Che was built with Java developers in mind. The most recent release boasts rich java features including IntelliSense, key bindings, and refactoring that make adopting Che a seamless process. In this post we will walk you through:

  • Setting up Che
  • Configuring a java project
  • Navigating the IDE

1. Start Che

Open a terminal where you have installed Che and use the Che startup script:

Shell

# Launch Che
bin/che run

# Che will be available at: 
http://localhost:8080

When you execute this command, the startup script will ensure all dependencies for Che are properly installed and configured. The Usage docs will help you resolve any startup issues.

The Che dashboard will open. It is where you manage your projects and workspaces. If you do not have any projects in Che, you'll be asked to create a new project. If you already have projects in Che, click on New Projectbutton in the menu bar.

2. Create Console Java Project

Image title

This page proposes several options to create a Java console project.

Select Source



This informs Che where the source code for your project is going to come from. It is possible to start a new blank, template, sample project or import one from another location. Choosing the first option will present you with a set of samples that are preconfigured. If you already have a project at a valid URL, choose the second option. Che gives you choices on how to source the project from Git, GitHub, ZIP, etc..

We will create a project from a provided template.

Select Stack



Your project will be inserted into a workspace, which has a provided Docker runtime. Stacks are the recipes or images used to define the runtime environment for the workspace where your project will be placed. There are three ways to choose a stack:

  1. Ready-To-Go Stacks. Environments that have a large variety of tools already installed optimized for projects of a particular type. For this example, we will select the Java stack which will create a container with Ubuntu git, java-jdk, maven, tomcat installed.
  2. Stack Library. Offers finer grained stacks that can be used to create specific technology layers needed for a project. Ubuntu and Debian stacks, for example, are minimal stacks with only an operating system and Che tools installed.
  3. Custom Stack. You can provide your own custom stack. You'll have the ability to upload a recipe (dockerfile) or directly edit it from there.

Choose the Ready-To-Go category and select the JAVA stack.

Configure Workspace



Provide a name to your workspace and configure its RAM. RAM will be the memory limit applied to the machines running your workspace environment. For this tutorial, create a new workspace with name tutorial-java and set its RAM to 1GB.

Select Template



A template is a set of code, configuration, and commands that can be imported to operate within Che. There are two types of templates:

  1. Ready-to-run project samples. These samples have a compilable source tree and embedded commands. The list of templates available is filtered based on the stack chosen.
  2. Wizard-driven project configuration. This creates a blank project and then opens the IDE's project configuration wizard to let you scaffold a new project based on a set of configurable parameters. This option is only available if there an appropriate project type available for the stack was chosen.

Choose Ready-to-run project samples and select console-java-simple those options should be preselected by default.

Project Metadata



You can set a name and description of your project. The name is what will appear as the root node in the project explorer in the IDE. Keep the default values.

Create the Project



Hit the button Create Project at the bottom of the flow. The project construction will start.



The project construction process goes through a number of steps including creating a new workspace, downloading an image to use for the workspace environment, instantiating that environment, installing Che services into the workspace, and then creating your project.

Click the Open in IDE button to open your project in the IDE.

3. Develop in the IDE

The project created is a Maven project. Once you open it in the IDE, you'll see the dependencies updated from the pom.xml file.












Project Explorer

On the left side of the IDE, a panel is displaying the project explorer which allow you to browse the sources of your project. You can use your mouse to expand/collapse the folders and packages, but you are also able to navigate in the project explorer using your keyboard. Use:

  • up arrow and down arrow to navigate in the tree,
  • left arrow and right arrow to expand/collapse folders and packages,
  • enter to open a file.

Editor Overview

Open the file HelloWorld.java in the package org.eclipse.che.examples. The file is displayed with syntax coloration.

The editor is structured in a common way:

  • at the top: the list of all opened files,
  • on the left: line number, breakpoints and error marks,
  • on the right: the file's minimap and the cursor position bar to navigate to the file,
  • at the bottom: file information (cursor exact position, encoding and file's type).

If you have error in your files, the editor will display error and warning marks:

You can use your keyboard to navigate in the file content, but also between files. You can get the complete list of all keyboard shortcut by going into the menu Assistant > Key Bindings and scrolling to the category Editor









Java Intellisense

– auto-complete

Jump to Definition

While you are editing your Java code, you may want a documentation lookup for a particular symbol (class, attribute or method). Get quick documentation by Assistant > Quick Documentation or ^j.



If you need more information about the symbol, you can also navigate to its definition with Assistant > Open Declaration or F4. The String class will open in a new editor. 




Search

Che editor provides various ways to search your projects and workspace.

Search with Editor

Use the editor search to find and replace in a particular file via CTRL+f keyboard shortcut. You can also use regular expressions.






Find Usages

This will find all references of a particular class, method, field or attribute and search for its usage in your various project's files. Do this with Assistant > Find Usages. A new panel will open and list all references for Stringinto your project. If you select one of the occurrence and double-click on it, the editor will open the file to the position of the found reference.



Refactoring

Che provides the ability to refactor your source code.

To download Che, find more technical documentation or to learn more about the all-new Eclipse Che and how Che works, please visit eclipse.org/che.
Download | Contribute | Docs | Features

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:
cloud ,java ,eclipse ,che ,ide

Published at DZone with permission of Tyler Jewell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}