Tutorial - Develop A Java EE Application - Help - IntelliJ IDEA
Tutorial - Develop A Java EE Application - Help - IntelliJ IDEA
IntelliJ IDEA 2020.1
The application that we are going to develop will be a minimal one. It'll be a one JSP page Java web
application. However, the IntelliJ IDEA features shown here are applicable to Java EE applications of any
complexity.
• GlassFish Server, version 3.0.1 or later. Download GlassFish. (You can use any other Java EE-enabled
application server. GlassFish is used here just as an example.)
• A web browser.
Creating a project
1. Click Create New Project on the Welcome screen, or select File | New | Project. The New Project
wizard opens.
3. From the Project SDK list, select the JDK that you want to use in your project.
[X]
If the JDK is installed on your computer, but not defined in the IDE, select Add JDK and specify the path Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
to the JDK home directory. experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 1/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
If you don't have the necessary JDK on your computer, select Download JDK.
If GlassFish is not defined in IntelliJ IDEA yet, click New to the right of the Application Server field and
select Glassfish Server.
In the Glassfish Server dialog, specify the GlassFish Server installation directory.
5. Under Additional Libraries and Frameworks, select the Web Application checkbox.
Click Next.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 2/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Click Finish and wait while IntelliJ IDEA is creating the project.
• JavaEEHelloWorld is a module folder (which in this case coincides with the project folder). The .idea
folder and the file JavaEEHelloWorld.iml contain configuration data for your project and module
respectively. The folder src is for your Java source code. The folder web is for the web part of your
application. At the moment this folder contains the deployment descriptor WEB-INF/web.xml and the
file index.jsp intended as a starting page of your application.
• External Libraries include your JDK and the JAR files for working with GlassFish.
[X]
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 3/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Our application will be a single JSP page application. Its only function will be to output the text Hello,
World!
1. Open index.jsp for editing: select the file in the Project tool window and press F4 .
IntelliJ IDEA compiles your source code and builds an application artifact.
After that, the Run tool window opens. IntelliJ IDEA starts the server and deploys the artifact onto it.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 4/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Finally, your default web browser starts and you see the application output Hello, World! there.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 5/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
3. In the Update dialog, select Update resources and click OK. (For more information, see Application
update options.)
4. Switch to the web browser and reload the page to see the changes.
[X]
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 6/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
When creating the project, we specified GlassFish as an application server. As a result, IntelliJ IDEA created
a run configuration for GlassFish.
When we performed the Run command , we started that run configuration. Now let's take a look at the
run configuration and see how its settings map onto the events that we've just observed.
The Run/Debug Configurations dialog opens and the settings for the GlassFish run configuration are
shown.
The Before launch task list (in the lower part of the dialog) specifies that the application code should be
compiled and the corresponding artifact should be built prior to executing the run configuration.
2. Select the Startup/Connection tab to see how the server is started in the run, debug and code coverage
modes.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 7/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
3. Select the Deployment tab to see which artifacts are deployed after the server is started.
The settings under Open browser specify that after launch (i.e. after the server is started and the
artifacts are deployed onto it) the default web browser should start and go to the specified URL
http://localhost:8080/JavaEEHelloWorld_war_exploded .
The settings to the right of On 'Update' action specify that on clicking in the Run tool window the
Update dialog should be shown and the Update resources option should be used by default. (The last
used update option becomes the default one).
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 8/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
5. Click OK.
The available artifact configurations are shown in the pane to the right under and . (There's only
one configuration at the moment.)
The artifact settings are shown in the right-hand part of the dialog. [X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 9/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Type. The artifact type is Web Application: Exploded. This is a decompressed web application archive
(WAR), a directory structure that is ready for deployment onto a web server.
Output Layout. The artifact structure is shown in the left-hand pane of the Output Layout tab.
The <output root> corresponds to the output directory. Other elements have the following meanings:
• 'JavaEEHelloWorld' compile output represents compiled Java classes whose sources are located in
the src directory. These are placed into WEB-INF/classes in the output directory.
1. Click , point to Web Application: Archive and select For 'JavaEEHelloWorld: war exploded'.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 10/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
A new artifact configuration is created and its settings are shown in the right-hand part of the dialog.
2. Create a manifest file for your archive: click Create Manifest and agree to the location suggested by
IntelliJ IDEA web/META-INF/MANIFEST.MF .
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 11/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Now if you look at the out/artifacts/JavaEEHelloWorld_war folder, you'll see the archive there.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 12/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Sometimes you need to deploy your app onto a running server. This section provides a how-to example.
Server run configurations that don't start a server are called remote. Such run configurations can be used,
for example, for deploying applications to servers that are already running. (See Local and remote run
configurations.)
Let's create a run configuration for deploying our WAR artifact to the running server and see how it works.
(By now, the server has been started by the run configuration discussed earlier.)
3. Change the run configuration name Unnamed to something more sensible (e.g. GlassFishRemote).
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 13/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
4. Specify the artifact to be deployed to the server: select the Deployment tab, click and select Artifact.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 14/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
After a while, a new tab in your web browser opens, and you see the application output there.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 15/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
As we are about to see, IntelliJ IDEA performs most of these tasks for you as part of its Java EE Application
support:
1. In the Project tool window, right-click your module folder and select Add Framework Support.
2. In the dialog that opens, select the JavaEE Application checkbox and click OK.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 16/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 17/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Currently only JavaEE Application facet resources META-INF/application.xml are included in the
artifact.
5. Let's add a copy of the exploded WAR artifact to the EAR artifact structure. To do that, under Available
Elements, expand the Artifacts node and double-click the exploded WAR artifact. Here is the result.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 18/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
(An alternative way of getting the same result would be | Artifact | JavaEEHelloWorld: war
exploded.)
6. Note the message Web facet isn't registered in application.xml. Click Fix. (A bit later, we'll look at the
changes made to application.xml by this quick fix.)
8. To create a manifest file, click Create Manifest and agree to the default file location
<project_folder>/META-INF/MANIFEST.MF .
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 19/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
See that your application.xml has changed. This is the result of applying the quick fix.
Let's now create a run configuration for building and deploying the EAR artifact.
10. Click the run configuration selector and select Edit Configurations. Then, in the Run/Debug
Configurations dialog, select | GlassFish Server | Remote.
[X]
Cookies and IP addresses allow us to deliver and improve our
11. Specify a descriptive name for your run configuration, e.g. GlassFishRemoteEAR. web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 20/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
12. Include the EAR artifact in the deployment list: switch onto the Deployment tab and select | Artifact
| JavaEEHelloWorld:ear.
Note that the Build 'JavaEEHelloWorld:ear' artifact task is included in the Before launch task list
automatically.
13. Switch to the Server tab and check the URL in the Open browser section. The part that follows
http://localhost:8080/ should correspond to the <context-root> element in your
application.xml .
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
14. Click OK in the Run/Debug Configurations dialog. experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 21/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
As before, another tab opens in the Run tool window showing the run configuration output.
Now if you look at the Project tool window, you'll see your archive in the
out/artifacts/JavaEEHelloWorld_ear folder.
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 22/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Tool windows. To open the tool windows, you can, for example, select View | Tool Windows | Web or
View | Tool Windows | JavaEE:App.
[X]
Very briefly, the Web and JavaEE:App tool windows provide the functions similar to those of the Project Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
tool window but only for your Web and Java EE Application facet resources respectively. For more info, experience. Our website uses cookies and collects your IP
see: address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 23/24
06/05/2020 Tutorial: Develop a Java EE application - Help | IntelliJ IDEA
Facets. To view or edit the facet settings, open the Project Structure dialog, select Modules, and then
select Web or javaEEApplication under the module node. For more info, see:
[X]
Cookies and IP addresses allow us to deliver and improve our
web content and to provide you with a personalized
experience. Our website uses cookies and collects your IP
address for these purposes.
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-ee-application.html 24/24