Difference between revisions of "Glassfish"
(Created page with "=Requirements= * Glassfish 4 required '''Java 7'''. The version 4.0 is NOT compatible with Java 8, but the version 4.1 will be. * It's better to use the official '''ORACLE ...") |
|||
Line 39: | Line 39: | ||
This solution is NOT recommended, it can generate a massive security leak! | This solution is NOT recommended, it can generate a massive security leak! | ||
− | + | ||
+ | Anyway, if you're sure you can add the following line: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
grant codeBase "file:${java.home}}/../db/lib/*" { | grant codeBase "file:${java.home}}/../db/lib/*" { | ||
Line 79: | Line 80: | ||
* Then, click the ''enable ping'' option and fill up the connection details. | * Then, click the ''enable ping'' option and fill up the connection details. | ||
− | + | ||
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | ! Setting !! Value | |
− | + | |- | |
− | + | | User || myApp | |
+ | |- | ||
+ | | ServerName || localhost | ||
+ | |- | ||
+ | | DatabaseName || myApp | ||
+ | |- | ||
+ | | Password || myAppPwd | ||
+ | |- | ||
+ | | Url || jdbc:mysql://localhost:3306/myApp | ||
+ | |- | ||
+ | | URL || jdbc:mysql://localhost:3306/myApp | ||
+ | |} | ||
+ | |||
====Create JDBC resource==== | ====Create JDBC resource==== | ||
Line 92: | Line 105: | ||
* Create a new connection using: | * Create a new connection using: | ||
− | + | ||
− | + | {| class="wikitable" | |
+ | |- | ||
+ | ! Setting !! Value | ||
+ | |- | ||
+ | | JNDI name || '''jdbc/'''myApp | ||
+ | |- | ||
+ | | Pool name || myPoolName | ||
+ | |} | ||
Now you can use that connection in your application with '''jdbc/myApp''' | Now you can use that connection in your application with '''jdbc/myApp''' |
Revision as of 10:16, 17 April 2014
Contents
Requirements
- Glassfish 4 required Java 7. The version 4.0 is NOT compatible with Java 8, but the version 4.1 will be.
- It's better to use the official ORACLE JDK as Glassfish is an Oracle product too.
Installation
- Download the latest glassfish version from the official website: https://glassfish.java.net/
- Register the server into your IDE (Netbeans, Eclipse, IntelliJ).
Issues
SocketPermission, port 1527
If you have the following error: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
Then you have to adjust your security policy.
cd $JAVA_HOME/jre/lib/security
vim java.policy
- Only open the required port
Add the following line:
grant {
permission java.net.SocketPermission "localhost:1527", "listen";
};
=> just add the "permission..." around line 25
- Open everything
This solution is NOT recommended, it can generate a massive security leak!
Anyway, if you're sure you can add the following line:
grant codeBase "file:${java.home}}/../db/lib/*" {
permission java.security.AllPermission;
};
Datasource management
Database
MySQL
Requirements
You have to setup your MySQL server:
- Allow remote access
- Create dedicated database in UTF8-bin
- Create dedicated user for the application
Driver installation
- Download the latest MySQL JDBC driver from: https://dev.mysql.com/downloads/connector/j/
- Extract and copy the mysql-connector-java-XXX-bin.jar into:
- $GLASSFISH/glassfish/lib
- $GLASSFISH/glassfish/domains/domain1/lib/databases
- Restart Glassfish
Create JDBC connection pool
- Go to Glassfish administrator page: http://localhost:4848
- Under resources / jdbc, create a new JDBC connection pool
- Name: myPoolName
- Type: javax.sql.datasource
- Db vendor: MySQL
- On the next page, Datasource Classname must have been update automatically in: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
- Then, click the enable ping option and fill up the connection details.
Setting | Value |
---|---|
User | myApp |
ServerName | localhost |
DatabaseName | myApp |
Password | myAppPwd |
Url | jdbc:mysql://localhost:3306/myApp |
URL | jdbc:mysql://localhost:3306/myApp |
Create JDBC resource
A JDBC resource = JNDI datasource
- Under resources / jdbc, create a new JDBC resources
- Create a new connection using:
Setting | Value |
---|---|
JNDI name | jdbc/myApp |
Pool name | myPoolName |
Now you can use that connection in your application with jdbc/myApp
JMS
ActiveMQ
Requirements
You have to setup your ActiveMQ server:
- The broker should listen on all interfaces
- Enable the web-console to improve debugging