Oracle从plsql调用java时如何导入缺少的java类 [英] Oracle how to import missing java classes when calling java from plsql

查看:1244
本文介绍了Oracle从plsql调用java时如何导入缺少的java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试逐步编写一个java函数,该函数可以使用Oracle XML(BI)发布者报告(不是商业智能中使用的BI Publisher,而是Oracle Applications使用的XML Publisher)功能,并将报告的输出提供为一个clob。所以基本上我想要一个报告定义和模板输出一个税务文件,然后将税务文件返回到一个clob,然后我可以使用PLSQL进一步操作。如果有人知道可以执行此操作的现有函数,请告诉我。

I am trying to gradually write a java function that can take the Oracle XML (BI) Publisher Report (not BI Publisher as used in Business Intelligence but rather XML Publisher used by Oracle Applications) functionality and provide the output of the report as a clob. So basically I would like to take a report definition and template that outputs a tax file and instead return the tax file into a clob that I can then manipulate further using PLSQL. If anyone knows of an existing function that can do this please let me know.

对Java不太了解我采用了这个 Stack Overflow从PL / SQL调用Java 问题并尝试启动并扩展它。

Not knowing much about Java I took this Stack Overflow Calling Java from PL/SQL question and tried to start and expand on it.

但是我无法将某些类导入Java程序。

However I cannot import some classes into the Java program.

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Hello" AS
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import oracle.apps.xdo.oa.schema.server.TemplateHelper;
public class Hello
{
   public static String world()
   {
      return "Hello world";
   }
};
/

如果我尝试导入oracle.apps.xdo。 oa.schema.server.TemplateHelper; Java编译失败,

If I try import oracle.apps.xdo.oa.schema.server.TemplateHelper; the Java compile fails with

JAVA SOURCE的错误Hello:

Errors for JAVA SOURCE Hello:

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      Hello:13: cannot find symbol
0/0      symbol  : class TemplateHelper
0/0      1 error
0/0      import oracle.apps.xdo.oa.schema.server.TemplateHelper;
0/0      ^
0/0      location: package oracle.apps.xdo.oa.schema.server

类TemplateHelper位于服务器上的$ JAVA_TOP / oracle / apps / xdo / oa / schema / server / TemplateHelper.class下,其中$ JAVA_TOP包含在CLASSPATH中。

The class TemplateHelper is under $JAVA_TOP/oracle/apps/xdo/oa/schema/server/TemplateHelper.class on the server where $JAVA_TOP is included in the CLASSPATH.

我也试过

loadjava -user apps ./oracle/apps/xdo/oa/schema/server/TemplateHelper.class

但由于某种原因,这将返回

but for some reason this returns

SQL Error while connecting with oci8 driver to default database: Closed Connection
exiting  : could not open connection

即使所有其他程序在连接中都能正常工作。

even though all other programs work fine with the connection.

有谁知道如何导入班级?

Does anyone know how I can import the class?

推荐答案

你可以试试 CREATE JAVA CLASS

You can try CREATE JAVA CLASS:

CREATE OR REPLACE DIRECTORY xml_template_dir
  AS '/path/to/oracle/apps/xdo/oa/schema/server/';
/

CREATE JAVA CLASS USING BFILE (xml_template_dir, 'TemplateHelper.class' )
/

然而,虽然这可能会加载类,但它几乎肯定会有其他依赖项,并且当您尝试使用该类时将失败,然后您将需要加载这些依赖项然后依赖项依赖项等等...

However, while this might load the class it will almost certainly have other dependencies and will fail when you try to use that class and you will then need to load those dependencies and then the dependencies dependencies and so on...

你最好找一个包含整个包的 JAR (或创建从你现有的目录结构中打包自己)并使用 loadjava

You would be better to find a JAR containing the entire package (or create the package yourself from your existing directory structure) and use loadjava:

loadjava -user APPS/password@sid -resolve XML_Publisher.jar

(如果需要覆盖如果现有的类无法加载,那么您可能还需要 -force 选项。)

(If you need to overwrite existing classes that failed to load then you may need the -force option as well.)

然后,您可以使用以下方法测试是否有任何内容无法加载:

You can then test to see if anything has failed to load using:

SELECT object_name
FROM   user_objects
WHERE  object_type = 'JAVA CLASS'
AND    status != 'VALID';

另请注意,仅仅因为成功加载类并不意味着它不会在您生成运行时异常时调用该类。

Also note, just because the class loaded successfully does not mean that it will not generate runtime exceptions when you invoke the class.

这篇关于Oracle从plsql调用java时如何导入缺少的java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆