Payara application server was derivative from Glashfish, with all the goodness from Glashfish and there is more and more interesting stuff added by Payara team nowadays Payara is become a popular application server that can be compete with Wildfly, Websphere, TomEE and many other Java EE application server. Today I would like to share about how to configure datasource configuration especially using PostgreSQL database on Payara version 4.1 (171).
I will skip about how to install and use Payara and how to install and use PostgreSQL database which is I assume most of you that visit this tutorial already know the basic knowledge about Payara and PostgreSQL database. Actually, you don’t need specific to use PostgreSQL because I believe this can be apply to MySQL or MariaDB too. So, the first thing you need to prepare is Payara application server, database with username and password on PostgreSQL.
To make sure Payara can communicate with PostgreSQL you need to add PostgreSQL JDBC driver. After download the jdbc driver copy that jar file into your
/domain/lib directory, so just copy your file into
PAYARA_HOME/glashfish/domains/YOUR_DOMAIN/lib in this case use payara domain. Make sure you know where you put Payara application server, as Linux user usually Payara was on
Payara JDBC Configuration
Let’s move to configure datasource JNDI, in order to do that start your Payara application server and make sure the domain that you run is already have PostgreSQL JDBC driver on
/domain/lib. In Payara administration console (you can reach this on http://localhost:4848) go to menu Resources » JDBC.
JDBC Connection Pools
On JDBC connection pools menu click New button to create your new connections pools.
- Create your Connection Pools, for example TestPool.
- Choose resources type with javax.sql.ConnectionPoolDataSource.
- Select Database Driver Vendor with postgresql.
- Press Next button.
- Make sure your datasource classname is org.postgresql.ds.PGConnectionPoolDataSource.
- Go to Additional Property and make sure to fill username, password, databaseName, and url.
- Click Finish.
Now try ping your connection pools, click on your new connection pools and you will find this Ping button. Make sure to see success message when you perform Ping.
On JDBC Resources menu click New button, this is the last and easiest part because you just need naming your JNDI for example jdbc/test and don’t forget to choose Pool Name with your connection pools when everything is done click Finish button.
I never use Glashfish before, but since Payara is just started to fork Glashfish not long a go, as you can see Payara configuration is still identically like Glashfish. I believe as Glashfish user you will be like in home when using Payara and won’t find any difficulty on Payara configuration.
I really like and keep amaze about how easy to administering Java EE application server (I also use Wildfly, and it’s so easy to configure the datasource) this make Java EE developer more focus on business code.