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.
Join the DZone community and get the full member experience.Join For Free
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:
# 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
This page proposes several options to create a Java console project.
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.
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:
- 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.
- 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.
- 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.
Ready-To-Go category and select the
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.
A template is a set of code, configuration, and commands that can be imported to operate within Che. There are two types of templates:
- 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.
- 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.
Ready-to-run project samples and select
console-java-simple those options should be preselected by default.
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.
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
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:
down arrowto navigate in the tree,
right arrowto expand/collapse folders and packages,
enterto open a file.
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
Key Bindings and scrolling to the category
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
Quick Documentation or
If you need more information about the symbol, you can also navigate to its definition with
Open Declaration or
String class will open in a new editor.
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.
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
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.
Che provides the ability to refactor your source code.
Published at DZone with permission of Tyler Jewell, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.