Development and debugging in Java
Introduction
Basic knowledge in Java is required before you start this tutorial.
In this tutorial we will cover:
- Initial configuration
- Creation of a simple service
- Running the server in normal mode
- Running the server in debug mode
In this example we will use the IntelliJ IDEA Community Edition IDE and Java JDK 1.8.
Initial Configuration
The first step will be to create a new project in _IntelliJ IDEA_
. To do so, follow the steps below:
First Step
Choose the "Create new project" option.
Second Step
Choose Java from the left menu [1] and later configure the version of Java JDK [2], if you haven't done it initially, click on "New" and indicate its installation directory.
Third Step
Click in " Next" until a screen similar to the following shows and then define the name of the project, indicate the Netuno directory and click in "Finish"
Fourth Step
Create a new classes
folder within the directory
netuno/web/WEB-INF/
Right click on the project folder and choose "Open module settings" [1].
Then click on the "Paths" tab, choose the "Use module compile output path" [2] and indicate in both the netuno/web/WEB-INF/classes/
directory [3].
Finally go to the "Dependencies" tab and click on the "+" icon, choose "JARs or directories" and indicate the file netuno.jar
[4] and then the directory netuno/web/WEB-INF/lib
[5]
Fifth Step
Configure the local server to run Netuno, start by choosing "Application". Insert the main class org.netuno.cli.Main
[1], insert as argument server
[2] and indicate the project directory [3], finally just click on "Aplly" and "Ok"
Building a Simple Service
When expanding the project folder, access the src
folder, create a new package, and then create a class.
In this example we have called the package org.netuno.tritao
and the class Test
as shown in the following image:
Finally we add the following code that causes the data to be output from the service in json format.
package org.netuno.tritao;
import org.netuno.proteu.Proteu;
import org.netuno.proteu.ProteuException;
import org.netuno.psamata.Values;
import org.netuno.tritao.config.Hili;
import java.io.IOException;
public class Test {
public static void _main(Proteu proteu, Hili hili)
throws IOException, ProteuException {
proteu.outputJSON(
new Values()
.set("message", "Hello World")
.set("description", "Debugging from Java...")
.set("id", 1)
.set("result", true)
);
}
}
Note that depending on your web browser and the input data the result may differ from this example
Running the server in normal mode
Run the local server through the triangle shaped icon [1] and if it is well configured the tab called "Run" will expand resembling the second image:
Accessing the service
To access the service created previously, login to Netuno and access the service, in this example the link will be http://localhost:9000/Test.netuno.
A screen like the following will show if everything is set correctly:
Running the server in debug mode
To use this mode, start the server through the icon that resembles an insect [1] and put some breakpoints in the code to see their values [2] as represented in the following images:
If you have any questions, please do not hesitate to contact us.
All the best!