在Oracle中运行的Java – 导入的jar

我试图将一个小的java类加载到Oracle 11g中,这样我就可以运行它并从PL / SQL中调用它.我在eclipse中编写并编译了我的本地机器上的类,它编译得很好.我将它打包到一个jar中(与jar中依赖的其他jar文件).他们尝试将我的j...

我试图将一个小的java类加载到Oracle 11g中,这样我就可以运行它并从PL / SQL中调用它.我在eclipse中编写并编译了我的本地机器上的类,它编译得很好.我将它打包到一个jar中(与jar中依赖的其他jar文件).他们尝试将我的jar加载到Oracle 11g中.所有东西加载,不幸的是当它加载我的自定义java类时,它保持无效,当我尝试在Oracle中编译它时,它说它找不到对类的引用(我在我的jar中打包的类).

我需要配置其他类型的设置吗?

这是我的自定义类代码:

import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.*;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
import javax.xml.rpc.ServiceException;
import java.net.URL;
import java.rmi.RemoteException;
import org.apache.log4j.Logger;
import java.net.MalformedURLException;

public class AssetExtractor {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

}


   static Logger LOG;
   static AuthToken authToken = null;

   static FlashlineRegistry repository = null;
   static URL repoURL;


    public static FlashlineRegistry getRepository()
    {
        if(repository == null)
            try
            {
                try{
                    repoURL = new URL("https://myserver/oer/services/FlashlineRegistry");
                }catch(MalformedURLException mue)
                {
                    LOG.error(mue);
                }

                repository = (new FlashlineRegistryServiceLocator()).getFlashlineRegistry(repoURL);
                LOG.debug((new StringBuilder()).append("Created repository at URL=").append(repoURL.toString()).toString());
            }
            catch(ServiceException e)
            {
                LOG.error(e, e);
            }
        return repository;
    }

    public static AuthToken getAuthToken()
    {
        if(authToken == null)
            try
            {
                authToken = getRepository().authTokenCreate("user", "password");
                LOG.debug("Created auth token.");
            }
            catch(OpenAPIException e)
            {
                LOG.error(e, e);
            }
            catch(RemoteException e)
            {
                LOG.error(e, e);
            }
        else
            try
            {
                getRepository().authTokenValidate(authToken);
            }
            catch(OpenAPIException e)
            {
                LOG.info("Auth token was invalid.  Recreating auth token");
                authToken = null;
                return getAuthToken();
            }
            catch(RemoteException re)
            {
                LOG.error("Remote exception occured during creation of suth token after determined to be invalid", re);
                re.printStackTrace();
                authToken = null;
            }
        return authToken;
    }

    public static String getAssetXML(String strAssetID)
    {
        String strAsset = null;
        try
        {
            strAsset = getRepository().assetReadXml(getAuthToken(), Long.parseLong(strAssetID));
        }
        catch(OpenAPIException e)
        {
            e.printStackTrace();
        }
        catch(RemoteException e)
        {
            e.printStackTrace();
        }
        return strAsset;
    }

}

并且导入的所有* .jar文件都在我的AssetExtractor.jar中

我用来将jar加载到oracle的命令是:

loadjava -v -f -resolve -resolver "((* OER) (* PUBLIC))" -user oer/***** AssetExtractor.jar

任何想法都会有所帮助!

解决方法:

所以看来如果我做以下几乎解决了我所有的问题:

编辑Oracle用户的.profile以使用正确的路径设置和导出CLASSPATH,PATH,LD_LIBRARY_PATH,ORACLE_HOME,JAVA_HOME

SQLPlus as sys as sysdba

EXEC dbms_java.grant_permission( 'OER', 'SYS:java.util.PropertyPermission', 'java.class.path', 'write' );

OS命令行作为oracle用户:

loadjava –v –grant PUBLIC <jar> -user oer/****** for all jars

SQLPlus作为OER用户

DECLARE
   v_classpath VARCHAR2(4000);
   v_path VARCHAR2(4000);
BEGIN
   v_classpath := DBMS_JAVA.set_property('java.class.path',    '/opt/oracle/102/jdk/lib:/mnt/hgfs/vmshare/rex_lib/aler-axis-   1.2.1.jar:/mnt/hgfs/vmshare/rex_lib/aler-axis-jaxrpc-1.2.1.jar:/mnt/hgfs/vmshare/rex_lib/client.rex-   11.1.1.5.0.jar:/mnt/hgfs/vmshare/rex_lib/commons-httpclient-3.0rc2-   flashline.jar:/mnt/hgfs/vmshare/rex_lib/log4j-1.2.8.jar');
   v_path := DBMS_JAVA.set_property('java.path', '/opt/oracle/102/jdk/bin');
END;
/

alter java source "AssetExtractor" compile;
show errors

唯一突出的问题是,由于某种原因,它仍然无法找到/解决一些Oracle OER类(它们都应该在client.rex * .jar中,我打开并在那里看到它们.如果我可以解决这个部分那我很高兴.

本文标题为:在Oracle中运行的Java – 导入的jar

基础教程推荐