Вы находитесь на странице: 1из 34

JDK-WildFly-NetBeans Setup Local

Overview @author R.L. Martinez, Ph.D.

In this tutorial, we download the three primary components required to establish


our Java EE programming environment. The Java Development Kit (JDK) contains
development tools and the Java Runtime Environment (JRE) required for
developing and running Java applications. The WildFly server (formerly JBoss)
will be used to host our web applications. NetBeans will be the Integrated
Development Environment (IDE) we use to construct the code files required by our
web applications.

When downloading the three components listed below, be sure to obtain the latest
stable version.

Contents at a Glance:
1. Download and install Java SE JDK
2. Download and install WildFly server
3. Download and install NetBeans
4. Add Wildfly server to NetBeans
5. Assign WildFly to a NetBeans Project
6. Create a Web Application Project in NetBeans
7. Run a Web Application in NetBeans
8. Creating Class Files and Packages in NetBeans
9. Alternative Method to Add WildFly (Plugin)

Download and Install Latest Stable JDK


Navigate to the link and download the latest stable JDK. The latest stable at the
time of this writing is 8u20 (version 8, update 20). It will likely be different when
you are downloading. The JRE is the Java Runtime Engine which is required to run
Java programs. It is included in the JDK. End users, not developers, will typically
only want/need the JRE. However, developers use the JDK. Note that Java EE
development requires the Java SE JDK (Java Developers Kit).

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-
2133151.html

Page 1 of 34
JDK-WildFly-NetBeans Setup Local

Accept the license aggreement and select jdk-8u20-windows-x64.exe.

Double-click the jdk-8u20-windows-x64.exe to install. I recommend installing to


the location C:\Java\jdk1.8.0_20\ as shown. However, I install to a flash drive (N:\)
to maintain multiple development environments. I do not recommend this unless
you are willing and have the time to work through configuration challenges as a
result of not developing from C:\, the local drive.

Select Next (Change is selected to show the non-standard setting for the JDK).

Page 2 of 34
JDK-WildFly-NetBeans Setup Local

This is what a non-standard installation location looks like (dont do this step):

The next step asks for the location of the JRE. It should also be installed to the C:\
drive as shown.

Page 3 of 34
JDK-WildFly-NetBeans Setup Local

TheSuccess dialog should appear after the installation. Select Next Steps.

Selecting Next Steps above opens a web page with the following diagram. You
will want to bookmark this page for future reference.

Page 4 of 34
JDK-WildFly-NetBeans Setup Local

The latest stable JDK, including the JRE, has been installed. We are now ready to
install WildFly and NetBeans.

Page 5 of 34
JDK-WildFly-NetBeans Setup Local

Download and Install Latest Stable WildFly (Local)

Download the WildFly .zip file from: http://wildfly.org/downloads/ .


Be sure to select the latest Final verison and NOT the Alpha version.

Move the .zip file wildfly-8.1.0.zip to the folder where you would like to install the
server. Right-click and select | Extract All. The current location will appear.
Unzipping can take a while. Note: I install to flash drives to maintain multiple
environments (hence the N:\). However, I highly recommend that development
tools be installed to the local C:\ drive.

After the extraction is complete, double-click wildfly-


8.1.0.Final\bin\standalone.bat and the command window opens.

Page 6 of 34
JDK-WildFly-NetBeans Setup Local

I get the error that the expected version of the JDK does not exist. I installed a later
version of the JDK and will need to make the adjustment to the JAVA_HOME
environment variable.

To update the JAVA_HOME environment variable, open the Control Panel |


System | Advanced system settings | Environment Variables | Edit |
JAVA_HOME and change to the appropriate version | OK .

Page 7 of 34
JDK-WildFly-NetBeans Setup Local

After the JAVA_HOME environment variable is set correctly, double-click


bin\standalone.bat again and the server running messages should appear in the
command window. To stop the server at any time, Ctrl-c in the comman window.

Open browser and type localhost:8080 in the browser URL address box. You
should see the message: Welcome to WildFly Your Wildfly is Running.

Page 8 of 34
JDK-WildFly-NetBeans Setup Local

Click Administration Console (but no users added yet to access admin). Add users
by running wildfly-8.1.0.Final\bin\add-user.bat (double-click to run). Choose
Management user (a), enter your username: myusername and your pw: mypasswd.
Just select enter for no group, yes for correct and no for slave process.

Page 9 of 34
JDK-WildFly-NetBeans Setup Local

Go back to localhost:8080, enter credentials.

The WildFly Admin page opens. We will come back to the local Admin page in
the tutorial MySQL in WildFly Setup Local. In that tutorial, we will register the
mysql...jar file with the WildFly server using the jboss-cli.bat tool. Then we will
use WildFly Admin to add the datasourse within WildFly. To take a glimpse or the
process to add a datasoure select Configuration.

That brings us to the JDBC Datasources page. The ExampleDS is a sample


datasource preinstalled with WildFly and should not be modified. In the MySQL
in WildFly Setup Local tutorial we will select Add in the JDBC Resources page
to add a resource for our database. This could be done now but it is preferrable to

Page 10 of 34
JDK-WildFly-NetBeans Setup Local

test the connection as we create it. To test the connection, we need MySQL
running and we need the database created in MySQL that is part of the datasource.

Page 11 of 34
JDK-WildFly-NetBeans Setup Local

Download and Install Latest NetBeans

Why NetBeans? While there are a number of other popular IDEs for Java EE
development such as IntelliJ IDEA and Eclipse, a Feb2014 Java.net survey
suggests that NetBeans remains the most popular Java IDE:

https://www.java.net/poll/i-do-most-my-coding-using

NetBeans releases are in sync with SE JDK and EE JDK releases. NetBeans is also
managed by Oracle, the same company that manages the Java updates.

Download NetBeans from: https://netbeans.org/downloads/

Select the Java EE package. Also, be sure to select the latest stable version (8.0.1 is
the latest stable at the time of this writing). If version 9.x is the latest stable,
download and install it.

Page 12 of 34
JDK-WildFly-NetBeans Setup Local

Move the netbeansexe to the location where you would like to install. I moved it
to N:\.

Double-click the netbeans-8.0.1-javaee-windows.exe file. Deselect the Glassfish


option since we will be using WildFly. Glassfish and/or Tomcat can be installed
later via Tools | Plugins if desired. That is the method we will use later to install
WildFly.

Page 13 of 34
JDK-WildFly-NetBeans Setup Local

Accept the defaults on the installation and JDK locations. Again, I am coding on
the edge by not developing from C:\. Not recommended. Select check for updates
in the next dialog and then Next. Installation begins.

After a few minutes NetBeans should install successfully. Select Finish.

Page 14 of 34
JDK-WildFly-NetBeans Setup Local

Add WildFly Server to NetBeans

In the Services pane, R-click Servers and select Add Server. See Plugin method
below if WildFly server does not appear in list of available servers.

Add Server to NetBeans

Select Wildfly Application Server. NOTE: If WildFly does not appear in the list of
available servers, perform the steps in the Alternative Method to Install WildFly
(via Plugin) at the end of this tutorial and then come back to Add Server above.

Enter appropriate Server location and Server Configuration.


Page 15 of 34
JDK-WildFly-NetBeans Setup Local

Enter appropriate Instance Properties and then select Finish.

Wildfly is configured in NetBeans after clicking Finish button. Start WildFly by R-


clicking on Servers | WildFly Application Server | Start. WildFly will also start
when selecting Run for an application that has WildFly assigned as its server.

Page 16 of 34
JDK-WildFly-NetBeans Setup Local

Assign WildFly Server to a NetBeans Project

Each web application requires an assigned server to run. To assign a server, or


resolve a Missing Server Problem, R-click the project. Select Properties to assign
a new server or change servers and select Resolve Missing Server Problem if a
previously existing server is no longer available.

Select WildFly Application Server (which is currently the only server recognized
by NetBeans on this machine). Select OK. Now WildFly is assigned as the
projects server and will start when the project is run (if the server is not already
running).

Page 17 of 34
JDK-WildFly-NetBeans Setup Local

Create a Web Application Project in NetBeans


We are now ready to create a new NetBeans project. Click the Create a New
project button. (Alternatively, File | New Project)

In the next dialog box make the following selections.

Set the name and location of your web application. Name the project ROOT. In the
tutorial WildFly Setup Remote we will use this project to create and upload the
home page for our remote web site. As previously mentioned, I recommend
installing development tools and projects on your C:\ drive. I place projects on my
RAID 1, mirrored G:\ drive which is a local logical drive.
Page 18 of 34
JDK-WildFly-NetBeans Setup Local

If this is the first time creating a web application in this installation of NetBeans,
you may receive a warning at the bottom of the next dialog box.

Click the Add button to register a WildFly server using the appropriate settings
previously covered in this tutorial.

Accept the default settings in the next window if like shown and select Next. No
frameworks are required for this project so none should be selected in the next
window. Select Finish.

Page 19 of 34
JDK-WildFly-NetBeans Setup Local

A starting index.html page is created like below. Close and delete that file (R-click
| Delete). We code the replacement next.

Create the file index.jsp by R-Clicking on the project name | New | JSP and name it
index.jsp. This will be the home page of our remote site. Code the content shown
and make the appropriate replacements on lines 6 and 12.

Page 20 of 34
JDK-WildFly-NetBeans Setup Local

With the Projects tab selected a logical view of the project is displayed.Your
project structure should look like the following.

Page 21 of 34
JDK-WildFly-NetBeans Setup Local

Run a Web Application Project in NetBeans


We can run most web application projects in NetBeans by selecting the Run
Project button in the top toolbar. Projects can also be run by R-clicking the
project name | Run. WildFly is automatically started when the run project button is
selected provided you have specified WildFly as the web server for your project
which was done above.

However, the ROOT project is a bit unique and needs to be started differently. If
we attempt to run the ROOT project like all others, we will see the following web
page due to the ROOT extension added to the URL.

Page 22 of 34
JDK-WildFly-NetBeans Setup Local

With the ROOT project, we need to start the WildFly server first, deploy the .war
file, and then access the ROOT project by localhost:8080 in the URL address
box (without the ROOT extension which is implied). Start the WildFly server by
Services | WildFly Application Server | Start.

The WildFly server can also be started by selecting the Run Server button in
the bottom Output panel.

If a web server has NOT been assigned to the project, R-click the project name in
the Project window to specify the server and select Specify Web Server at the
bottom of the menu or in Properties.

Page 23 of 34
JDK-WildFly-NetBeans Setup Local

The JDK installation includes a public and a private JRE. When the JRE is first run
from a new installation you may see the Windows Security Alert as shown below. I
strongly recommend that the Private networks option be selected for the
development environment to operate more securely. The Name: specified in the
dialog may be NetBeans IDE instead of Java as shown. In either case, select
Private networks and then Allow access.

Monitor the progress of WildFly starting in the Output WildFly Application


Server window. In my experience, WildFly starts much more quickly than
Glassfish which is another Java EE sever that ships with NetBeans. Usually it takes
less than seven seconds to start. After Wildfly is running, access the ROOT project
by localhost:8080 in the URL address box. A welcome page like that shown
should appear.

Page 24 of 34
JDK-WildFly-NetBeans Setup Local

We need to replace the default ROOT content with our own which we do by R-
clicking the project name | Deploy.

Now, our ROOT.war file is deployed to WildFly which can be verified with the
local WildFly Admin app (localhost:9990) | Runtime | Manage Deployments.

Page 25 of 34
JDK-WildFly-NetBeans Setup Local

After deployment, we are ready to test our ROOT project by localhost:8080 in


the URL address box. We should see the following.

NOTE: If localhost:8080 does not work, check the file


standalone/configuration/standalone-full.xml for the setting below and either
change the setting to 8080 or use the current setting.

<socket-binding name="http" port="${jboss.http.port:8080}"/>

Page 26 of 34
JDK-WildFly-NetBeans Setup Local

Navigate to your project dist folder. You will see the .ROOT.war file. This is the
file that will be published to your student website in the WildFly Setup Remote
tutorial.

Page 27 of 34
JDK-WildFly-NetBeans Setup Local

Creating Class Files and Packages in NetBeans


To add files to a project, select the Projects tab, R-click the project name (asg09 in
the example), select New, and then the new file type. The types highlighted are
those most often used in this course. If you do not see a selection that you need,
select Other at the bottom of the menu.

Creating packages: Packages provide a convenient means to organize Java classes


and namespaces. NetBeans simplifies the creation and use of packages. To create a
Page 28 of 34
JDK-WildFly-NetBeans Setup Local

package to contain Java class files, R-click on the project name, select New, and
then Java Package The dialog box below appears. We will use the name college.
Notice that NetBeans places the package in the standard location of
src\java\{packagename}.

The package is created in the location shown in the different views. Recall that the
Projects tab on the left shows a logical configuration of the project while the Files
tab displays the actual file and folder structure.

Page 29 of 34
JDK-WildFly-NetBeans Setup Local

Note: instead of creating a package first and then adding class files to the package,
you can create a package at the same time as a class file by selecting Java class
from the New menu.

After the package is created, you can add a Java class file to the package by R-
clicking the package name and selecting Java class The class file is named
Student in the example, placed in the college package, and in the path shown.

The college package now contains the Student.java class file. By the way, the
globe icon identifies asg09 as a web project.

Page 30 of 34
JDK-WildFly-NetBeans Setup Local

WildFly creates the following starter file Student.java from the .java template.

Recall from the ITSE 2317 course material that an import statement like that below
is used to import the package and its class files for use in a .jsp.

Page 31 of 34
JDK-WildFly-NetBeans Setup Local

After testing the project and when ready to upload to the student website, R-click
the project and select Clean and Build.

Page 32 of 34
JDK-WildFly-NetBeans Setup Local

With a successful Clean and Build, NetBeans automatically creates the dist (short
for distribution) folder and places the asg09.war file in the asg09/dist folder.

The asg09.war file contains all files, in their proper locations, required for a servlet
container to run the website. It is this file that should be uploaded to the student
website per the instructions in the WildFly Setup Remote tutorial. Reminder: this
version of asg09 is not the actual project assignment. See Bb for asg09 assignment
instructions.

You are now ready to code your projects asg09-asg12. Good luck with your efforts
and enjoy the process. Java EE is challenging but the rewards are worth the
commitment.

Page 33 of 34
JDK-WildFly-NetBeans Setup Local

Alternative Method to Install WildFly (via Plugin)

Only need to perform the steps in this section if the WildFly server did not appear
when selecting Add Server above. Open NetBeans and select Tools | Plugins..

Check for Updates on the Updates tab. Then, on the Available Plugins tab, check
the box next to the WildFly Server item and select Install. Note: WildFly
Application Server came off both lists of Available and Installed plugins after I
installed it. Also, if WildFly does not appear on the Available Plugins list then it
should appear on the Services | Server | Add Server menu.

Page 34 of 34

Вам также может понравиться