问题描述
我正面临与WAS plugins文件夹中的jar相关的类路径问题.我的应用程序具有要使用com.ibm.ws.runtime jar进行编译的IBM特定代码,如下所述.
I am facing classpath issue related to jars in WAS plugins folder. My application had IBM specific code to get compiled using the com.ibm.ws.runtime jar as mentioned below.
位置:C:\ Program Files \ IBM \ Websphere \ AppServer \ Plugins
Location : C:\Program Files\IBM\Websphere\AppServer\Plugins
源代码:
对象obj =(( com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.getNativeConnection ((( com.ibm.ws.rsadapter.jdbc.WSJdbcConnection )connect )));
Object obj = ((com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.getNativeConnection((com.ibm.ws.rsadapter.jdbc.WSJdbcConnection)connect)));
两个类都可以在com.ibm.ws.runtime中找到
Both classes are available in com.ibm.ws.runtime
通过在构建过程的类路径中包含IBM runtime.jar进行了成功编译,但是在WAS中进行部署后,我得到了 ClassNotFoundException .能否让我知道,如何将插件文件夹包含在WAS的类路径中,这样我就不会得到ClassNotFoundException.我仅在JVM类路径中添加了runtime.jar,但由于它依赖于IBM的其他jar,因此会引发错误.
Compiled successfully by including IBM runtime.jar in classpath of build process but after the deployment in WAS, i am getting ClassNotFoundException. Could any one please let me know, how to include that plugins folder in classpath of WAS, so that i wont get ClassNotFoundException. I have added only runtime.jar in JVM classpath but it is throwing error as it is dependent on other jars of IBM.
错误:引起原因: java.lang.ClassNotFoundException:com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
已更新:当前,它可以与Jboss服务器完美配合.下面的代码.我的目的是为Webpshere提供相同的条款.
调用方法:
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());
}
}
推荐答案
获得底层连接的推荐方法是使用适当的JDBC API并将其解包,如下所示(不使用WebSphere internall类):
The recommended way to get underlaying connection is to use proper JDBC API and unwrap it, like this (not using WebSphere internall classes):
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.
}
有关更多详细信息,请检查 WebSphere Application Server和JDBC 4.0包装器模式
For more details check the WebSphere Application Server and the JDBC 4.0 Wrapper Pattern
更新
在回应评论.我不建议这样做,尽管它在WAS 8.5.5中可以很好地工作,所以请修复您的类路径,并删除在其中添加或与应用程序一起包装的与WebSphere相关的jar:
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:
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());
}
输出:
[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
这篇关于如何在WAS类路径中包含Websphere插件jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!