1. Start Che
Use your SaaS account for the following, or if you have installed Che, open a terminal and use the Che startup script:
# Interactive help docker run -it eclipse/che-cli start # Or, full start syntax where <path> is a local directory docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v <path>:/data eclipse/che-cli start
When you execute this command, you’ll see the URL for the user dashboard.
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 Project button in the menu bar.
2. Create Console Java Project
From the Dashboard page click “Create Workspace”.
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.
Select Template (Code Sample)
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 are filtered based upon 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 upon a set of configurable parameters. This option is only available if there an appropriate project type available for the stack 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 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.
# 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:
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.
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 in 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
There is an Assistant menu that includes language specific capabilities. You can perform auto-complete by hitting
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
String into 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.
Put cursor on method, variable or field that you want to rename, and hit Shift + F6. If this hotkey is pressed once, the selected keyword will be highlighted which means it’s ready for refactoring. You can type a new name and press Enter.
If you press Shift + F6 twice, an advanced Rename mode is called out:
Preview button will open a side by side comparison window that will show changes that you are about to apply.
Choose any Java class you want to move and hit F6. It will call a Move item menu. Choose destination for your class and click OK.
It’s also possible to preview changes. Choose destination for your class and click Preview. It will show all Java classes and non-Java files (optional), that the replaced class is referenced in.
###Manage Maven Modules
Maven Plugin provides the ability to manage Maven modules in multi-module projects entirely through
Open any Java multi-module project and create a new folder with a simple Maven project in it. It will be seen as folder in the project tree first. Open your parent project POM and add your newly imported module there:
As a result, it will be automatically configured as a Maven module in your project tree. Maven plugin watches changes in
pom.xml and automatically imports changes (dependencies, configuration etc).
To enable/disable viewing the maven artifact ID in the project explorer, go to menu Profile > Preferences and select the ‘Maven’ page in the ‘Plug-ins’ tab:
Project explorer displays only maven artifact IDs that are different from their package name.
If you make changes to dependencies in POM, they will be automatically updated. You can also manually reimport the project: right click on your Maven project, choose
Maven > Reimport.
If you have errors in your POM or add some nonexistent dependency to your POM, the following error will be displayed in the editor:
It’s possible to view project dependencies at
Project > Configure Classpath. Dependencies in the classpath will be categorized as follows:
- JRE_CONTAINER - Java 1.8 jars;
- MAVEN2_CLASSPATH_CONFIGURATION - project dependencies.
Generate Effective POM
There is also a possibility to display POM that results from the application of interpolation, inheritance and active profiles. Just open your Maven project and go to
Assistant > Generate Effective Pom.