NETBEANS

foreheadsobstinacyΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 4 χρόνια και 10 μήνες)

261 εμφανίσεις

N
ET
B
EANS

D
EPLOYING WEB
-
APPLICATIONS

We have created a web
-
application. Our Java Application server is GlassFish server.
We now want to deploy it on this server. .How should we proceed?

a.

Clean and Build you project. Carry WAR file and MySQL Java connector fi
le to
place where application is to be installed.

b.

At remote site, install GlassFish server and NetBeans.

c.

Use NetBeans to create a GlassFish domain in the user
-
account of your choice.

d.

Copy MySQL connector jar file to lib folder of domain.

e.

Start GlassFish se
rver and open Admin Console.

f.

Create desired Connection Pool and JDBC resource on GlassFish server to access
database server.

g.

Restart GlassFish

h.

Deploy application WAR

We explain these simple steps below.

C
OLLECTING DISTRIBUTA
BLE FILES

Right click on the pr
oject in
Projects

window and in the context menu, click
Clean

and

Build
.


F
IG
.

1
:

C
LEAN AND
B
UILD
P
ROJECT

Cleaning process deletes the folders where compiled classes were deposited and
Build recreates the folders and deposits again

the recompiled results.
The
project
folder structure
is in
Fig.
2
.


F
IG
.

2
:

N
ET
B
EANS PROJECT

FOLDER STRUCTURE

The ‘dist’ folder contains a WAR (Web Archive) file. In our case this file is:
dataProject.war.

This file along with MySQL Java connector file, mysql
-
connector
-
java
-
5.1.5
-
bin.jar are to be distributed to the site where the Project is to be
installed. Also note at this time MySQL connection related information available in
sun
-
resources.xml

file unde
r
Server

Resources

(
Fig.
3

and
Fig.
4
).


F
IG
.

3
:

S
ERVER
R
ESOURCES NODE IN DAT
A
P
ROJECT

Note in
Fig.
4
, the jndi
-
name (
jdbc/expt_MySQL
) and connection pool
-
name,
mysqlPool
,

and associated connection particulars such as
serverName
,
portNumber

etc. We will need them at the site we are going to install the project.


F
IG
.

4
:

SUN
-
RESOURCES
.
XML FILE UNDER
S
ERVER
R
ESOURCES
.

R
EAD THE FIRST LIN
E AFTER
<
RESOURCES
>

TAG

G
LASS
F
ISH CONFIGURATION

D
OMAIN CREATION

You have installed on a remote Linux machine NetBeans with GlassFish, Java
Application Server. Your project is to be installed there. Decide first the user on
whose account and home space, the

GlassFish domain will be created. Log on as
that user. Domain creation is easy with NetBeans. Start NetBeans, and on start the
first thing it does is to look for the GlassFish domain. And if it is not there, creates
one by name of
personalDomain

under the

folder

.
personalDomain
. Here is what
appears under output window.

Please, wait while the domain is being created...

Using port
9237

for Admin.

Using port
12469

for HTTP Instance.

Using port 12065 for JMS.

Using port 8089 for IIOP.

Using port
12570

for HTT
P_SSL.

Using port 8209 for IIOP_SSL.

Using port 8309 for IIOP_MUTUALAUTH.

Using port 13075 for JMX_ADMIN.

Domain being created with profile:developer, as specified by
variable AS_ADMIN_PROFILE in configuration file.

Security Store uses: JKS

Domain personal
Domain created.

Note the port related information. The GlassFish Admin console will be available at
port 9237 (http://localhost:9237), the web
-
site will be available at port 12469
(http://localhost:12469/dataProject) and web
-
site with SSL protection will b
e
available at port 12570 (https://localhost:12570/dataProject). Do not worry if you
did not note down this information at the time personal domain was created. In
NetBeans, under
Servers

node, right
-
click
GlassFish

and in the context menu click
Properties

(
Fig.
5
)

to know the location of
Admin

console.


F
IG
.

5
:

L
OCATION OF
A
DMIN
C
ONSOLE AT PORT
9237

You can also get this information by peeping into the log files and looking for lines
with words ‘Starting’.
Or, from the command line issue command as:

[moh
ammed
@gnu ~]$ cat
.
personalDomain/personalDomain/logs/server.log | grep Starting

S
TARTING
G
LASS
F
ISH
S
ERVER

When
personalDomain

is created, two script files are also deposited in its ‘bin’
folder (
Fig.
6
).


F
IG
.

6
:

F
OLDER STRUCTURE OF P
ERSONAL
D
OMAIN

In the terminal window, change directory to ‘bin’ folder and issue
startserv

command (
Fig.
7
). You will need to supply admin username, his

password and
master password. The master password is used to secure the SSL key
-
store of the
domain
.
It is not used for authentication
.



F
IG
.

7
:

S
TARTING
G
LASS
F
ISH SERVER
.

N
OTE THE DEFAULT MAST
ER PASSWORD

The server can be stopped

by another script in the ‘bin’ folder as:

[
mohammed
@
gnu

bin]./stopserv

GlassFish server can also be started from NetBeans. Right click the GlassFish node
(
Fig.
5
)

and in the context menu, click
Start
.

A
DDING
D
ATABASE
D
RIVER

It is

time that we add MySQL database driver’s JAR file to enable the server to
connect to MySQL server. Copy the file
mysql
-
connector
-
java
-
5.x
-
bin.jar

to lib folder (
Fig.
6
) of
personalDomain
. This will do.

C
REATING CONNECTION P
OOL F
OR
M
Y
SQL

SERVER

GlassFish application server uses Connection Pooling mechanism to speed
-
up server
response time. Creating a new connection to database server for each client request
takes a long time. Connection pooling is a mechanism to have a ready conne
ction
available and to assign it to a client as soon as a request is made. When the client
releases the connection, it returns to pool to be made available to another client.
You can view existing Connection pools in NetBeans by expanding GlassFish node
wh
en started.

Note from
Fig.
4

that our application expects a connection pool by name (
pool
-
name
=
) of mysqlPool. To create this connection pool, start GlassFish server and
access Admin console. In our case, we will access it as http
://localhost:9237. In the
Admin console, login as user admin and password adminadmin. Server Admin
Console opens (
Fig.
8
).


F
IG
.

8
:

S
UN
J
AVA
S
YSTEM
A
PPLICATION
S
ERVER
A
DMIN
C
ONSOLE

In the Server Admin Conso
le, in the tree on the left, expand
Resources
-
>JDBC

nodes
to see existing connection pools (
Fig.
9
).


F
IG
.

9
:

G
LASS
F
ISH IS STARTED
.

P
RESENTLY THREE DEFAU
LT CONNECTION POOLS
EXIST

Under
Common

Tasks

(
Fig.
10
)
, click
Create New JDBC Connection Pool
.


F
IG
.

10
:

C
REATING NEW JDBC CON
NECTION POOL

Page as in
Fig.
11

opens. Fill it up as done here and click
Next
.


F
IG
.

11
:

C
REATING CONNECTION P
OOL

In the Next page there is lot of information. Do not bother with it except the
Additional

Properties

section down below that page (
Fig.
12
).


F
IG
.

12
:

F
ILLING IN CONNECTION

R
ELATED INFORMATION

Fill up only relevant fields with usual information and click
Finish

to create the
connection pool. We now have to create a JDBC resource by name of
jdbc/expt_MySQL

on top of this connection pool. Please note that this resource is
known
by name of jndi
-
name in
Fig.
4
. Presently as you can see

in
Fig.
9
, this JDBC
resource is not available.


F
IG
.

13
:

E
XISTING
JDBC

R
ESOURCES

In
Fig.
9
, cli
ck on the JDBC Resources link to open JDBC Resources page (
Fig.
13
).
Here, click on
New

button. It takes you to
Fig.
14
. Fill in the simple details and click
OK.


F
IG
.

14
:

C
REATING

NEW
JDBC

RESOURCE

The necessary resource has been created. Restart GlassFish server.

D
EPLOYING YOUR APPLIC
ATION

To deploy our application, copy the project WAR file (that was in dist folder of
project,
Fig.
2
) to
autodeploy

fold
er (
Fig.
6
) of
personalDomain
. The server will
explode and install the file. Access the application as:
http://localhost:
12469
/dataProject/
. You can also deploy the application through
Admin Console. In
Fig.
8
, click on
Deploy Web Application (WAR)

to open page as in
Fig.
15
.


F
IG
.

15
:

D
EPLOYING APPLICATION

THROUGH
A
DMIN
C
ONSOLE

Here Browse to your WAR file location and click OK. The WAR file is deployed.

*
**************