Skip to Main Content
  • Questions
  • ORA-65040 when loading jar file into pluggable database with sys.dbms_java.loadjava or commandline tool loadjava


Question and Answer

Connor McDonald

Thanks for the question, Sigrid.

Asked: April 14, 2021 - 3:02 pm UTC

Last updated: April 19, 2021 - 5:33 am UTC

Version: 19.8

Viewed 100+ times

You Asked

I want to load a jar file into the database. First I loaded it into the root container.

loadjava -o -f -noverify -synonym -stdout -verbose -recursivejars -resolve -grant PUBLIC -user sys/password@CDB javax.mail.jar >\mail.log

This also works, but I don't have access to it in the PDB.

Trying to load the jarfile into the PDB fails with the error ORA-65040: operation not allowed from within a pluggable database. The same message comes when I use dbms_java.loadjava('-v -r -g PUBLIC /path/java/javax.mail.jar'); after switching into the PDB.

How can I load jarfiles into a PDB or make them available there?

Thanks for help


and we said...

Can you try this:

connect sys/syspwd@mypdb as sysdba
alter session set "_ORACLE_SCRIPT"=true;
call dbms_java.loadjava('-v -r -g PUBLIC /path/java/javax.mail.jar');

and see how that goes. But if you're looking at running mail from the database, I'd recommend using APEX_MAIL instead. Easier and more flexible.


  (2 ratings)


Sigrid, April 15, 2021 - 3:35 pm UTC

Thank you Connor for answering my question. I have tried the suggested method in two different PDB's from different container databases.

Case 1
CDB1: jar file was not loaded first in the root container.
PDB1 on CDB1: the jarfile was loaded into the PDB1 using the suggested method with no errors. It works fine.

Case 2
CDB2: jar file was loaded first in the root container without errors. All Java Sources are valid there.
PDB2 on CDB2: brings the following error when I try to import the jar file there with the suggested method.

SQL> connect sys/xxx@pdb2 as sysdba
SQL> show pdbs

---------- ------------------------------ ---------- ----------
SQL> alter session set "_ORACLE_SCRIPT"=true;
SQL> call dbms_java.loadjava('-v -r -g PUBLIC /home/oracle/downloads/java/javax.mail.jar');
call dbms_java.loadjava('-v -r -g PUBLIC /home/oracle/downloads/java/javax.mail.jar')
Error at Line 1:
ORA-00604: error occurred at recursive sql level 1
ORA-04020: deadlock detected while trying to lock object

How can I solve the problem for PDB2?
Connor McDonald
April 19, 2021 - 5:33 am UTC

That sounds like some sort of name clash, but you shouldn't be seeing 4020.

I think its time you need to get in touch with Support to potentially raise a bug.

Sigrid, April 19, 2021 - 8:34 am UTC

Thanks for the feedback. I have since run the call again with the -force option. This was executed without error message.
However, I had the problem that various public synonyms for the java sources were not created. I have now corrected this manually, so that it works at the moment.

More to Explore


More on PL/SQL routine DBMS_JAVA here