- A Linux-based operating system
- Root access to the server
- Oracle Autonomous Database
Step 1: Download WildFly
Step 2: Extract WildFly
Step 3: Extract Autonomous Wallet
- Download the wallet from your Oracle Cloud account.
- Log in to your Oracle Cloud account and navigate to your Autonomous Database instance.
- Click the DB Connection button to open the Download Client Credentials dialog.
- Choose the Wallet option and click Download.
- Save the wallet zip file to a directory of your choice, for example, /opt/oracle/wallet.
- Extract the contents of the wallet zip file to a directory of your choice, for example, /opt/oracle/wallet.
- Set the appropriate file permissions on the wallet directory and files, for example:
- Download the ojdbc8-full version from Oracle. The full version downloads companion jars, which include oraclepki.jar, osdt_core.jar, and osdt_cert.jar. These files are required to connect to an Autonomous database with the wallet.
- Create a new directory named oracle in the WildFly module directory and copy the Oracle JDBC driver jar file. Use the following commands to achieve this:
mkdir -p $WILDFLY_HOME/modules/system/layers/base/com/oracle/main/
cd $WILDFLY_HOME/modules/system/layers/base/com/oracle/main/
sudo cp /path/to/ojdbc8-full.jar .
Step 5: Create a module.xml file
<resources> <resource-root path="ojdbc8.jar"/>
<resource-root path="oraclepki.jar"/>
<resource-root path="osdt_cert.jar"/>
<resource-root path="osdt_core.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
<driver name="oracle" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
Step 7: Create a Datasource configuration file
Edit file $WILDFLY_HOME/standalone/configuration/standalone.xml
and add the following within the tag <datasources>...</datasources>
.
php<datasource jndi-name="java:jboss/datasources/oracleDS_mtls2" pool-name="MTLS2" enabled="true" use-java-context="true" statistics-enabled="true">
<connection-url>jdbc:oracle:thin:@orcl_mtls_low?TNS_ADMIN=/opt/oracle/wallet</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver>oracle</driver>
<pool>
<initial-pool-size>0</initial-pool-size>
<max-pool-size>25</max-pool-size>
<fair>false</fair>
<flush-strategy>AllIdleConnections</flush-strategy>
</pool>
<security>
<user-name>USERNAME</user-name>
<password>YOURPASSWORD</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
<background-validation>true</background-validation>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
</validation>
</datasource>
Replace the USERNAME
and YOURPASSWORD
with your schema username and password.
Note: if you are familiar with the WildFly command line, add the lines using the following jboss-cli.sh
.
Step 7: Test Connection
After configuring the data source, you can test the connection.
Example:
ruby[root@wildfly-adb ~]# /opt/wildfly/bin/jboss-cli.sh --connect
/subsystem=datasources/datasource=MTLS2:test-connection-in-pool()
{
"outcome" => "success",
"result" => [true]
}
Step 8: Deploy Your Application
After configuring the data source, you can deploy your Java application to WildFly. You can do this by copying your application WAR file to the WildFly deployments directory or from the WildFly admin console.
Conclusion
In this Blog, we have gone through the steps involved in installing the latest version of WildFly on Linux and connecting it to the Oracle Autonomous Database. Following these steps, you can run your Java applications on WildFly and use Oracle Autonomous Database as your data source.
No comments:
Post a Comment
Feedback welcome