{"id":18429193,"url":"https://github.com/openliberty/draft-guide-intellij","last_synced_at":"2025-04-13T21:18:09.609Z","repository":{"id":71351431,"uuid":"228679590","full_name":"OpenLiberty/draft-guide-intellij","owner":"OpenLiberty","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-28T19:05:40.000Z","size":269,"stargazers_count":2,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"draft","last_synced_at":"2025-04-13T21:18:06.075Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenLiberty.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-17T18:40:06.000Z","updated_at":"2023-11-25T19:32:59.000Z","dependencies_parsed_at":"2023-05-06T05:16:38.257Z","dependency_job_id":null,"html_url":"https://github.com/OpenLiberty/draft-guide-intellij","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenLiberty%2Fdraft-guide-intellij","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenLiberty%2Fdraft-guide-intellij/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenLiberty%2Fdraft-guide-intellij/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenLiberty%2Fdraft-guide-intellij/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenLiberty","download_url":"https://codeload.github.com/OpenLiberty/draft-guide-intellij/tar.gz/refs/heads/draft","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782257,"owners_count":21160717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T05:16:11.348Z","updated_at":"2025-04-13T21:18:09.589Z","avatar_url":"https://github.com/OpenLiberty.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"//  Copyright (c) 2020 IBM Corporation and others.\n// Licensed under Creative Commons Attribution-NoDerivatives\n// 4.0 International (CC BY-ND 4.0)\n//   https://creativecommons.org/licenses/by-nd/4.0/\n//\n// Contributors:\n//     IBM Corporation\n//\n:projectid: intellij\n:page-layout: guide-multipane\n:page-duration: 30 minutes\n:page-releasedate: 2020-02-23\n:page-description: Learn how to use the IntelliJ IDEA to develop a microservice with Open Liberty.\n:page-seo-title: Using IntelliJ IDEA to develop a RESTful Java microservice\n:page-seo-description: A getting started tutorial with examples on how to use IntelliJ IDEA to develop a RESTful Java microservice with Open Liberty\n:guide-author: Open Liberty\n:page-tags: ['MicroProfile', 'Java EE', 'Jakarta EE', 'Maven']\n:page-related-guides: ['rest-client-java', 'rest-client-angularjs', 'rest-intro']\n:page-permalink: /guides/{projectid}\n:repo-description: Go to the https://openliberty.io/guides/{projectid}.html[website] for the rendered version of the guide.\n:common-includes: https://raw.githubusercontent.com/OpenLiberty/guides-common/master\n= Using IntelliJ IDEA to develop a microservice\n\n[.hidden]\nNOTE: This repository contains the guide documentation source. To view the guide in published form, view it on the https://openliberty.io/guides/{projectid}.html[Open Liberty website].\n\nLearn how to use the IntelliJ IDEA to develop a microservice with Open Liberty.\n\n== What you'll learn\n\nIntelliJ IDEA is a popular integrated development environment (IDE) created by JetBrains, used primarily for developing programs for the Java Virtual Machine (JVM).\n\nYou'll learn how to get started with IntelliJ IDEA by building and testing a simple REST service.\nThis service will display the JVM's system properties. The REST service will respond to `GET` requests made to the\n`\\http://localhost:9080/LibertyProject/System/properties` URL.\n\nTo learn more about how to create a REST service, see https://openliberty.io/guides/rest-intro.html[Creating a RESTful\n web service^].\n\n== Additional prerequisite\n\n- *IntelliJ IDEA:* Install IntelliJ IDEA if you did not. For installation instructions of IntelliJ IDEA, refer to the official https://www.jetbrains.com/idea/download/[IntelliJ IDEA download documentation^].\n\n== Getting started\n\nThe fastest way to work through this guide is to clone the Git repository and use the projects that are provided inside: \n\n[role='command']\n```\ngit clone https://github.com/OpenLiberty/guide-intellij.git\n\ncd guide-intellij\n```\n\nMake a note of the directory path that the project is being cloned to.\n\nStart IntelliJ IDEA, select `Import Project`. Navigate to the directory where the project was saved and click `Open`. On the `Import Project` dialog box, choose `Import project from external model` and select `Maven` and click `Finish`.\n\nIf the directory is not automatically open, click `Open` on the welcome screen and navigate to the directory mentioned previously and select `Open`. Select `View` in the menu bar and navigate to `Tool Windows` and click `Project` to display the `Project Tool Window` at top left side. Expand the `guide-{projectid}` project. If there is no guide directory showed up in the top left side, try to reopen the IntelliJ IDEA.\n\nThe `start` directory contains the starting project that you will build upon.\n\nThe `finish` directory contains the finished project that you will build.\n\nAt the lower left of the IDE, click `Terminal` to open the console if needed. By default, it should start\nin the `guide-{projectid}` directory.\n\n== Configure the build project\n\nFrom the menu bar, select `Run` and click `Edit Configurations`.\n\nClick the `+` button at the upper left in the `Run/Debug Configurations` pop up window. \nSelect `Maven` under `Add new configuration`.\n\n* In the `Name` field, put `Run finish`.\n* For the `Working directory` field, navigate to the `finish` directory.\n* In the `Command line` field, put `liberty:run`.\n\nNext, repeat the above steps using the following values in the corresponding fields:\n\n* `Name` field: `Stop finish`\n* `Working directory` field: navigate to the `finish` directory\n* `Command line` field: `liberty:stop`.\n\nRun through the steps again using the following values in the corresponding fields:\n\n* `Name` field: `Develop start`\n* `Working directory` field: navigate to the `start` directory\n* `Command line` field: `liberty:dev`.\n\nRepeat one last time, using the following values in the corresponding fields:\n\n* `Name` field: `Stop start`\n* `Working directory` field: navigate to the `start` directory\n* `Command line` field: `liberty:stop`.\n\nOnce the configurations are set up, the drop down menu in the topscreen toolbar can be used to quickly select different configurations to run.\n\n=== Setting up the SDK\n\nThe `SDK` should be configured for both the `start` and `finish` projects.\n\nFrom the menu bar, select `File` and click `Project Structure`. On the panel on the left, locate the `Project Settings` section and select `Project`.\n\nIn the `Project SDK` section, click `New`, choose `JDK` and specify the path to the JDK set up on your machine.\n\nClick `OK` to save changes.\n\n== Try what you'll build\n\nThe `finish` directory in the root of this guide contains the finished application. Give it a try before you proceed.\n\nTo try out the application, you can select `Run` in the menu bar and click `Run...`. Select `Run finish`\nin the pop up window and deploy it to Open Liberty.\n\nThe tool window will be activated by default, displaying a console which allows you to follow the progress of the build.\n\nLook at the console out for the `Run finish` command. If the following statement `\"CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 6.228 seconds.\"` shows in the console, check out the service at the\nhttp://localhost:9080/LibertyProject/System/properties[^] URL.\n\nYou are expected to see the system properties displayed in JSON format.\n\nTo stop the application, select `Run` in the menu bar and click `Run...` and then select `Stop finish` in the pop up window.\n\n== Developing the microserivce\n\nSelect `Run` in the menu bar and click `Run...`. Select `Develop start` in the pop up window which will start the\nOpen Liberty server in development mode and will listen for file changes.\n\nCheck out the service at the\nhttp://localhost:9080/LibertyProject/System/properties[^] URL.\n\nYou are expected to see `Context Root Not Found`.\n\n== Configuring the server\n\nIf the `Project Tool Window` is not currently displayed, select `View` in the menu bar and navigate to `Tool Windows` and click `Project` to display the `Project Tool Window` at top left side. Expand the `guide-{projectid}` project and navigate to the `start` directory to begin. If there is no guide directory showed up in the top left side, try to reopen the IntelliJ IDEA.\n\nTo get the service running, the Open Liberty server needs to be correctly configured.\n\n[role=\"code_command hotspot\", subs=\"quotes\"]\n----\n#Replace the server configuration file.#\n`src/main/liberty/config/server.xml`\n----\n\nserver.xml\n[source,xml,linenums,role=\"code_column\"]\n----\ninclude::finish/src/main/liberty/config/server.xml[]\n----\n\npom.xml\n[source,xml,linenums,role=\"code_column\"]\n----\ninclude::finish/pom.xml[]\n----\n\n[hotspot=httpEndpoint file=0]`\u003cHttpEndpoint/\u003e` and [hotspot=webApplication file=0]`contextRoot` is added in the replaced file to connect to the liberty server.\n\nThe context root value [hotspot=appContextRoot file=1]`context root` is defined at the `pom.xml`.\n\nThe Open Liberty server was started in development mode in the previous section and all the\nchanges were automatically picked up.\n\nCheck out the service at the\nhttp://localhost:9080/LibertyProject/System/properties[^] URL.\n\nYou are expected to see the system properties displayed in JSON format.\n\n== Debugging the microservice\n\nYou may want to debug the program. After you run `Develop start` you can attach the IntelliJ IDEA debugger to the Open Liberty\nprocess.\n\nFrom the menu bar, select `Run` and click `Edit Configurations`. Click the `+` button at the upper left in the\n`Run/Debug Configurations` pop up window. Select `Remote` in `Add new configuration`. Type `Check` in the `Name` field and `7777` into the `Port` field. Click `OK` to save the changes. Select `Run` from the menu bar and click `Debug...`. Select `Check` in the pop-up window to start the debugger.\n\nPropertiesResource.java\n[source, Java, linenums, role=\"code_column hide_tags=comment\"]\n----\ninclude::start/src/main/java/io/openliberty/guides/rest/PropertiesResource.java[]\n----\n\nIn the editor open the class `PropertiesResource` which is located in the `start/src/main/java/io/openliberty/guides/rest` directory. \nClick in the margin on line [hotspot=getProperty file=0]`35`. This action will set a breakpoint on that line.\n\nNow refresh the browser at the http://localhost:9080/LibertyProject/System/properties[^] URL. The server will stop at\nthe breakpoint you set and you can examine the state of your JVM. Select `Run` in the menu bar and click `Resume Program` to continue testing your application.\n\nRemove the breakpoint you set after debugging.\n\n== Testing the microservice\n\nYou can test this service manually by starting a server and pointing a web browser at the\nhttp://localhost:9080/LibertyProject/System/properties[^] URL. Automated tests are a much better\napproach because they trigger a failure if a change introduces a bug. JUnit and the JAX-RS Client\nAPI provide a simple environment to test the application.\n\nYou can write tests for the individual units of code outside of a running application server, or they\ncan be written to call the application server directly.\n\nEndpointIT.java\n[source, Java, linenums, role=\"code_column hide_tags=comment\"]\n----\ninclude::finish/src/test/java/it/io/openliberty/guides/rest/EndpointIT.java[]\n----\n\nThe test [hotspot=endpointTest file=0]`EndpointIT` class is already provided for you to test the REST service. This test class has more lines of code than the resource implementation. This situation is common.\nThe test method is indicated with the [hotspot=test file=0]`@Test` annotation.\n\n=== Running the tests\n\nSince you started Open Liberty in development mode earlier in the guide, you will be able to run tests with the `enter/return` key. To navigate back to the terminal where development mode is running, select the `Run` tab in the bottom left corner of the IDE, and then select the `Develop start` tab at the top of the terminal window. Press the `enter/return` key to run the tests. You will see the following output:\n\n[source,role=\"no_copy\"]\n----\n-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning it.io.openliberty.guides.rest.EndpointIT\nTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.884 sec - in it.io.openliberty.guides.rest.EndpointIT\n\nResults :\n\nTests run: 1, Failures: 0, Errors: 0, Skipped: 0\n----\n\nTo see whether the tests detect a failure, add an assertion that you know fails, or change the existing [hotspot=assertosname file=0]`assertion` to a constant value that doesn't match the `os.name` system property.\n\nWhen you are done checking out the service, exit development mode by selecting `Run` in the menu bar and clicking\n`Run...` and then selecting `Stop start` in the pop up window. Alternatively, type `q` in the terminal where development mode is running and then press the `enter/return` key.\n\n== Great work! You're done!\n\nYou developed a REST service in Open Liberty using IntelliJ IDEA.\n\n== Related Links\n\nLearn more about MicroProfile.\n\nhttps://microprofile.io/[See the MicroProfile specs^]\n\nhttps://openliberty.io/docs/ref/microprofile[View the MicroProfile API^]\n\n\ninclude::{common-includes}/attribution.adoc[subs=\"attributes\"]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenliberty%2Fdraft-guide-intellij","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenliberty%2Fdraft-guide-intellij","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenliberty%2Fdraft-guide-intellij/lists"}