Exercise: Developing with CodeReady workspaces¶
In this exercise, you will learn how to use Red Hat CodeReady Workspace covering the following topics:
- Create a workspace from an existing Github repo using the Spring boot runtime.
- Explore the Che-Theia editor.
- Define and exectue commands from the workspace.
- Run the project in the debug mode.
- Push the code changes back in the Git repo.
- Customize workspace to meet your project requirements.
- Use of factory to share workspaces with your development team.
Create your CodeReady Workspace¶
Fork this Git repo into your priate account.
https://github.com/rojanjose/rhoar-backend
Note: This repository was created using the Red Hat Developer Launcher tool.
Access your CodeReady Workspace using the link provied by the instrcutor. You should see a screen as shown below:
Create a new workspace¶
Create a new workspace using the Springboot stack.
Enter the name of the your wortspace: userXX-springboot
Select Java Spring Boot
from the list of available stacks. Click the Remove
button to delete the default project.
Add or Import Project
, select the Git
tab and then add the repo URL you forked earlier.
https://github.com/<username>/rhoar-backend
Add
the project and Click CREATE & OPEN
. The workspace should open once its created: (takes about 2-5 minutes to startup)
TODO: show the pod that runs the workspace.
Explore Che-Theia editor¶
Click on the Explorer: /Projects
icon to view the files under spring-boot-http-booster
project. Navigate and open the java file:
src/main/java/dev/snowdrop/exmaple/service/ExampleApplication.java
Notice that the Che Theia editor has idenfitifed the project as a java project and the syntax highlighting is already in place. More about how to use the Theia workspace can be found here
To view the installed plugins select View > Plugins
and apply filter by selecting Show Installed Plugins
from the seach bar.
Define and exectue commands from the workspace¶
The Devfile defines the configuration of the workspace including the command definitions.
Note the commands are defined for build, run, debug, test, dependency-anaysis, deploy to OpenShift
.
Let's start with the build. Click in View > Workspace
to view the list of available runtime commands.
Click on build under User Runtimes > maven > build
Run the project by clicking run
from the workspace. Click Open link
when the dialog pops up asking confirmation to luanch the preview pane. Click on 8080/tcp
from the User Runtimes to open the application in a new tab.
Open the static resource file index.html file and update the text. Change the greetings by adding the text CodeReady workspaces
, save the file and refresh the preview page to see the changes.
src/main/resources/static/index.html
Run the project in the debug mode¶
Open the file ExampleApplication.java
src/main/java/dev/snowdrop/exmaple/service/ExampleApplication.java
Insert a print statement in the method jsonProvider() and set a breakpoint by click next to the line number as show in the picture below:
System.out.println("Testing break point...");
Open the Output
console by selecting View > Output
from the menu.
Start the application in debug mode by selecting debug
from the My Workspace
pane on the right.
Start the debugger by selecting Debug > Start Debugging
from the menu. This should open the Debug
view and flow will stop at the set break point.
Step over the code using the controls available in the debug page.
Open the link to launch the preview of the UI.
Push the code changes back in the Git repo¶
Commit changes
Push changes