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', '', 'Verifier', ' ' );
execute dbms_java.grant_permission( 'USERNAME', 'SYS:java.lang.RuntimePermission', 'accessClassInPackage.sun.util.calendar', ' ' ) ; 
execute dbms_java.grant_permission( 'USERNAME', '', '*', '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:

5 thoughts on “How to Load JAR File in Oracle Database?”

    • 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.

  1. 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 worked. Thanks Aj


Leave a Comment