简体   繁体   English

如何在WAS类路径中包含Websphere插件jar

[英]How to include Websphere plugin jars in WAS classpath

I am facing classpath issue related to jars in WAS plugins folder. 我面临与WAS plugins文件夹中的jar相关的类路径问题。 My application had IBM specific code to get compiled using the com.ibm.ws.runtime jar as mentioned below. 我的应用程序具有IBM特定的代码,可以使用com.ibm.ws.runtime jar进行编译,如下所述。

Location : C:\\Program Files\\IBM\\Websphere\\AppServer\\Plugins 位置:C:\\ Program Files \\ IBM \\ Websphere \\ AppServer \\ Plugins

Source code: 源代码:

Object obj = (( com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.getNativeConnection (( com.ibm.ws.rsadapter.jdbc.WSJdbcConnection )connect))); 对象obj =(( com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.getNativeConnection (( com.ibm.ws.rsadapter.jdbc.WSJdbcConnection )connect))));

Both classes are available in com.ibm.ws.runtime 这两个类都在com.ibm.ws.runtime中可用

Compiled successfully by including IBM runtime.jar in classpath of build process but after the deployment in WAS, i am getting ClassNotFoundException . 通过在构建过程的类路径中包含IBM runtime.jar进行了成功编译,但是在WAS中进行部署后,我得到了ClassNotFoundException Could any one please let me know, how to include that plugins folder in classpath of WAS, so that i wont get ClassNotFoundException. 能否让我知道,如何将插件文件夹包含在WAS的类路径中,这样我就不会得到ClassNotFoundException。 I have added only runtime.jar in JVM classpath but it is throwing error as it is dependent on other jars of IBM. 我仅在JVM类路径中添加了runtime.jar,但由于它依赖于IBM的其他jar,因此会引发错误。

Error : Caused by: java.lang.ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection 错误:由以下原因引起: java.lang.ClassNotFoundException:com.ibm.ws.rsadapter.jdbc.WSJdbcConnection

Updated: Currently it is working perfectly with Jboss server. 更新: 目前,它与Jboss服务器完美配合。 Code below. 下面的代码。 My aim is to proivide the same provision with Webpshere. 我的目的是为Webpshere提供相同的条款。

Calling method: 调用方式:

Connection connect = null;
connect = mDataSrc.getConnection();
unlockJDBC(connect);

private void unlockJDBC(Connection connect)
{
//This bit is JBoss specific but we are trying to avoid importing JBoss JAR files so we use reflection instead.

if (connect.getClass().getName().equals("org.jboss.resource.adapter.jdbc.WrappedConnection") || connect.getClass().getSuperclass().getName().equals("org.jboss.resource.adapter.jdbc.WrappedConnection"))
{
Method method = null;
try{
    method = connect.getClass().getMethod("getUnderlyingConnection",null);
    Connection conn = (Connection)method.invoke(connect, null);
    if (conn != null){
        connect = conn;
    }
}
catch (InvocationTargetException e){
    mLogger.severe(e.getTargetException().getMessage());
}
catch (Exception e){
    mLogger.severe(e.toString());
}
}
if (connect instanceof ExtEmbeddedConnection){
ExtEmbeddedConnection embConnect = (ExtEmbeddedConnection)connect;
try{
    embConnect.unlock("unlock");
}
catch (Exception e){
    mLogger.severe(e.toString());
}
 }

The recommended way to get underlaying connection is to use proper JDBC API and unwrap it, like this (not using WebSphere internall classes): 推荐的获得底层连接的方法是使用适当的JDBC API并将其解包,如下所示(不使用WebSphere internall类):

Context ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup("jdbc/OracleDS");
Connection conn = ds.getConnection();

// Returns true if this either implements the interface argument
// or is directly or indirectly a wrapper for an object that does.
if (conn.isWrapperFor(oracle.jdbc.OracleConnection.class)) {
    // Returns an object that implements the given interface to
    // allow access to non-standard methods, or standard methods
    // not exposed by the proxy.
    oracle.jdbc.OracleConnection oraCon = conn.unwrap(oracle.jdbc.OracleConnection.class);
    // Do some Oracle-specific work here.
}

For more details check the WebSphere Application Server and the JDBC 4.0 Wrapper Pattern 有关更多详细信息,请检查WebSphere Application Server和JDBC 4.0包装器模式。

UPDATE 更新
In response to comments. 在回应评论。 I do not recommend this, although it works perfectly fine in WAS 8.5.5, so please fix your classpath and remove any WebSphere related jars you added there or packed with application: 我不建议这样做,尽管它在WAS 8.5.5中可以很好地工作,所以请修复您的类路径,并删除在其中添加或与应用程序一起包装的与WebSphere相关的jar:

        Connection connection = myDs.getConnection();
        System.out.println("connection: " + connection.getClass().getName());
        WSJdbcConnection conn = null;
        if(connection instanceof WSJdbcConnection) {
            System.out.println("WSJdbcConnection");
            conn = (WSJdbcConnection) connection;
            Object obj = WSJdbcUtil.getNativeConnection(conn);
            System.out.println("native: " + obj.getClass().getName());
        }

with output: 输出:

[8/11/15 16:55:10:165 CEST] 0000009a SystemOut     O connection: com.ibm.ws.rsadapter.jdbc.WSJccSQLJPDQConnection
[8/11/15 16:55:10:165 CEST] 0000009a SystemOut     O WSJdbcConnection
[8/11/15 16:55:10:165 CEST] 0000009a SystemOut     O native: com.ibm.db2.jcc.am.ef

Websphere uses OSGI to limit visibility of internal classes to applications. Websphere使用OSGI来限制内部类对应用程序的可见性。 That could be what's happening here. 那可能就是这里发生的事情。 OSGI probably wasn't in play when you compiled it, but it is when you try to run it. 编译时,OSGI可能没有发挥作用,但尝试运行它时却发挥了作用。 If I do this in a servlet in v7, 如果我在v7中的servlet中执行此操作,

ps.println("trying to new up a WSJdbcConnection");
Object o = com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.class.newInstance();
ps.println("got it")

I get an IllegalAccessException, so it's not visible. 我收到一个IllegalAccessException,所以它不可见。

As Gas said, if you can use something that's not an internal, you should be able to access it. 正如Gas所说,如果您可以使用非内部的内容,则应该可以访问它。 Generally, com.ibm.websphere - api, com.ibm.wsspi - spi, com.ibm.ws - internal 通常,com.ibm.websphere-api,com.ibm.wsspi-spi,com.ibm.ws-内部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM