How to Load JAR File in Oracle Database?

How to Load JAR File in Oracle Database?

In Oracle Database, use loadjava utility to load JAR file. The loadjava utility creates schema objects in Oracle database and then load JAR file contents into it. So, you must have CREATE TABLE AND CREATE PROCEDURE privileges to use loadjava utility. Also, you need some permissions on Java programs to execute it. In this tutorial, I am explaining how to load JAR file in Oracle Database.

Follow These Steps to Load JAR file in Oracle Database

  1. If you are loading JAR files the first time to execute Java programs, then run the following commands in Oracle by connecting with SYS credentials, else you can skip this step. Run the statements as shown below:

Note: Replace the USERNAME with the username to which you want to grant the permission.

sqlplus sys/syspsw@orcl as sysdba

call dbms_java.grant_permission('USERNAME', 'java.util.PropertyPermission','*', 'read,write');
execute dbms_java.grant_permission('USERNAME','java.util.PropertyPermission','*','read');
execute dbms_java.grant_permission( 'USERNAME', 'SYS:java.lang.RuntimePermission', 'getClassLoader', ' ' );
execute dbms_java.grant_permission( 'USERNAME', 'SYS:oracle.aurora.security.JServerPermission', 'Verifier', ' ' );
execute dbms_java.grant_permission( 'USERNAME', 'SYS:java.lang.RuntimePermission', 'accessClassInPackage.sun.util.calendar', ' ' ) ; 
execute dbms_java.grant_permission( 'USERNAME', 'java.net.SocketPermission', '*', 'connect,resolve' );
execute dbms_java.grant_permission( 'USERNAME', 'SYS:java.lang.RuntimePermission', 'createClassLoader', ' ');
  1. Now open the command prompt and change to the directory where your JAR files exist. For example, if you extracted JAR files at C:\javajars, then change the current folder to C:\javajars. Then run the loadjava command as following:

Note: Change the USERNAME, PASSWORD, and DBNAME with your user and database details. Also, change the activation.jar with your Jar file name.

loadjava -user USERNAME/PASSWORD@DBNAME -resolve -synonym activation.jar

If the above command execution completed without giving any message that means everything is ok. Your JAR files are loaded successfully.

See also:

This Post Has 5 Comments

  1. Linkan Roy

    How to call the JAR file using Oracle Apex

    1. Vinish Kapoor

      In Oracle Apex, if we will think to call .Jar file then only thing comes in mind is JavaScript , but it is not supported.

      I think you have to load .Jar file in Oracle Database then only you can use its functions.

    2. Linkan Roy

      Thanks, Can you make a details post to call .JAR file using pl/sql.

    3. Vinish Kapoor

      I think you can check the following post in which I have given a simple example of creating and using Java function in Oracle database:

      Java in Oracle Database

  2. Aj Tula

    Hi Vinish, thanks for the nice article. We tried the same using loadjava to load a Jar file. Created a PL/SQL wrapper function and called it. But it started complaining about few weblogic classes I guess "Cannot instantiate class: weblogic.jndi.WLInitialContextFactory". So using the same loadjava we loaded weblogic jar file. Tried again using PL/SQL function same error keeps coming. How do we load dependent Jars. Kindly share your wisdom. By the way you HelloWorld.java worked. Thanks Aj

Comments are closed.