Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Note
iconfalse

This tutorial describes how to create, configure, deploy and debug Java EE 7 application using GlassFish 4.0 and IntelliJ IDEA 13.

Wiki Markup
{redirect:https://www.jetbrains.com/idea/help/developing-a-java-ee-application.html|delay=0}

1. Create

...

new project

Create a Java application via

Wiki Markup
{span:class=shortcut}New Project Wizard{span}
.

Image Added

2. Select application server

Before you configure libraries, you need to select an application server to which you'll be deploying your application. If there is no application yet, click

Wiki Markup
{span:class=shortcut}New{span}
to configure one.

Image Added

If you're going to deploy your application to multiple application servers, you can configure them later via

Wiki Markup
{span:class=shortcut}Run{span}
Wiki Markup
{span:class=shortcut}Edit Configurations{span}
.

3. Select JSF library

If the application is using the JSF library, select the corresponding item in the list. By default IntelliJ IDEA uses libraries provided by the selected application server.

Image Added

Library you selected is automatically downloaded and configured (if required), by IntelliJ IDEA.

4. Configure other libraries

Now you can select other libraries for use with your application: Bean Validation, CDI, JSON Processing, WebSockets, RESTful Web Services (JAX-RS), WebSockets, you name it.

Image Added

After you click

Wiki Markup
{span:class=shortcut}Finish{span}
, IntelliJ IDEA creates the project.

Image Added

6. Check module dependencies

To make sure that libraries are properly configured, go to the

Wiki Markup
{span:class=shortcut}Project Structure{span}
Wiki Markup
{span:class=shortcut}Modules{span}
Wiki Markup
{span:class=shortcut}Project Dependencies{span}
. There you can review and modify the list of libraries as you see fit.

Image Added

7. Check web settings

To check the Web descriptor and resources directory configuration, go to

Wiki Markup
{span:class=shortcut}Project Structure{span}
Wiki Markup
{span:class=shortcut}Facets{span}
and configure descriptors (e.g. application server specific), or change Web resource directories.

Image Added

These settings will be used to build artifacts.

8. Check configured artifacts

An artifact is what IntelliJ IDEA deploys to application server when you run your application. To make sure that artifacts are properly configured, go to

Wiki Markup
{span:class=shortcut}Project Structure{span}
Wiki Markup
{span:class=shortcut}Artifacts{span}
.
Image Added

This dialog lets you change existing artifacts, or add new ones.

9. Check run configuration

One last step before running the application is to make sure that its Run Configuration is all right. For that, see

Wiki Markup
{span:class=shortcut}Run{span}
Wiki Markup
{span:class=shortcut}Edit Configurations{span}
.

Run Configuration defines how application server is configured and controls application deployment.

Image Added

10. Check artifacts to deploy

Wiki Markup
{span:class=shortcut}Deployment{span}
tab lets you choose what artifacts to deploy, update or remove from application server when you run this configuration.

Image Added

11. Run application

Assuming that everything is set right, we can try running our application.

Image Added

When application is deployed to selected server, IntelliJ IDEA opens it start page (can also be changed in Run Configuration settings.)

Image Added

12. Live edit

In addition to the server-side debugging toolsб IntelliJ IDEA provides the

Wiki Markup
{span:class=shortcut}Live edit{span}
feature, which helps you debug applications directly in your Web browser. This is very simple, really: after you installed (browser helper plugin), just use the
Wiki Markup
{span:class=shortcut}Debug in Browser{span}
from the browser context menu.

Image Added

IntelliJ IDEA opens application page in your Web browser and warns that it's now available for live editing.

Image Added

Now you can see the DOM structure of application page directly in IntelliJ IDEA, and, which is what's so cool about Live Edit, deploy them to the server as you type, so everything is synced without a single restart.

Image Added

Try to make some changes on the page, and you'll see that browser displays them immediately.

Image Added

13. Create a named bean

Now let's create some server code and try debugging it.

Image Added

14. Update application

When application is running, we can use the

Wiki Markup
{span:class=shortcut}Update{span}
action via
Wiki Markup
{span:class=shortcut}F10{span}
to choose how to redeploy it.

Image Added

15. Debug application

In debug mode IntelliJ IDEA stops at breakpoints (well, what else would it do, right?)

Image Added

15. Update resources on frame deactivation

Note that you can specify application redeployment settings on the

Wiki Markup
{span:class=shortcut}Update{span}
tab, which is available in the
Wiki Markup
{span:class=shortcut}Run configuration{span}
dialog.

One more useful option here is

Wiki Markup
{span:class=shortcut}On frame deactivation{span}
, which controls what happens when IntelliJ IDEA window loses focus. If you choose to redeploy resources at that moment, then, for example, switching from IntelliJ IDEA to Web browser would trigger this action, and by the time you hit Refresh, the application will already have been updated on server, allowing you to see all the changes you made in action much quicker than otherwise.

Image Added

16. Configure application servers

In this tutorial we used GlassFish 4.0. Of course, you can easily configure any other application server of your choice via

Wiki Markup
{span:class=shortcut}Settings{span}
Wiki Markup
{span:class=shortcut}Application Servers{span}
.

Image Added

As we hope you could see, development of Java EE applications with IntelliJ IDEA is easy as pie. And fun, too!