如何解决"无法实例化类:com.ibm.websphere.naming.WsnInitialContextFactory"在Java?

时间:2015-02-16 21:08:47

标签: java tomcat ejb websphere

添加ejb.jar后,我收到此错误

        javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:175)

但是如果我在Java控制台应用程序中运行相同的代码,它会被执行,我在控制台中获取值,但是当我通过将它与我的Web应用程序集成来运行相同的代码时,它会抛出我上面提到的错误。 / p>

          public  String process(String message, int start) {
          System.out.println("from process method");
          String result = "Unable to Process";
          String ejbClientUrl = DBPropertiesLoader.EJBCLIENT_URL;
            System.out.println("Connecting : " + ejbClientUrl);
          try {

         System.getProperties().put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
         System.getProperties().put("java.naming.provider.url", DBPropertiesLoader.TI_EJB_URL);


         System.getProperties().put("java.naming.provider.url", ejbClientUrl);

         Context ctx = new InitialContext();
         Object ejbObject = ctx.lookup("ejb/EnigmaServiceAccess");
         System.out.println("EJB Object : "+ejbObject);

这是我的QueryBuilder.java类。我只在我尝试加载上下文的地方调用此类的进程方法:

    int num = 0;
    int count = 0;
    while (resultSet.next()) {

        try {

            num++;
            count = resultSet.getInt("SNO");

            ArrayList<InvoiceCustomer> list = new ArrayList<InvoiceCustomer>();
            list.add((InvoiceCustomer) bp.toBean(resultSet, InvoiceCustomer.class));

            TFinvdtoHandler tfinv = new TFinvdtoHandler();
            sRequestItems.add(tfinv
                    .createTFinvdtoRequest(list));
            if (num % 1 == 0) {

                xmlToPost = MessageUtil.xmlServiceRequest(
                        sRequestItems, "TFINVNEW");
                logger.debug(xmlToPost);

                System.out
                        .println("**Sending data to TI Plus through EJB Client***"
                                + "\n");
                finalResult = TIPlusEJBClient.process(xmlToPost, count);

                if (!finalResult.equals("Unable to Process")) {

                    List<ServiceResponse> serviceResponses = MessageUtil
                            .processResponse(finalResult);
                    for (ServiceResponse serviceResponse : serviceResponses) {
                        // System.out.println("**Response Status***"
                        // +serviceResponse.getResponseHeader().getStatus());
                        // System.out.println("**Response CorrID***"
                        // +serviceResponse.getResponseHeader().getStatus());

                        MigrationUtil.updateMigrationDataStagingStatus(
                                table, serviceResponse
                                        .getResponseHeader()
                                        .getStatus(), serviceResponse
                                        .getResponseHeader()
                                        .getCorrelationId(),
                                serviceResponse.getResponseHeader()
                                        .getDetails().getError()
                                        .toString());
                    }

                }
                logger.debug("\n");
                sRequestItems = new ArrayList<ServiceRequest>();
                finalResult = "Unable to Process";
            }

        } catch (Exception e) {
            // TODO: handle exception
            logger.debug("Exception Occured ->" + e.getMessage());
            e.printStackTrace();
        }

    }

} catch (SQLException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();

    logger.debug("Exception Occured ->" + e1.getMessage());
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    logger.debug("Exception Occured ->" + e1.getMessage());
} catch (Exception e) {
    logger.debug("Exception Occured ->" + e.getMessage());
} finally {

    MigrationUtil.surrenderConnection(connection, resultSet,
            queryStatement);

}

/*
 * System.out.println("Remaining request count ->" +
 * sRequestItems.size()); if (sRequestItems.size() > 0) {
 * 
 * xmlToPost = MessageUtil .xmlServiceRequest(sRequestItems,
 * "TFILCDTO"); logger.debug(xmlToPost); finalResult =
 * TIPlusEJBClient.process(xmlToPost, count);
 * 
 * System.out
 * .println("**Sending remaining data to TI Plus through EJB Client***"
 * + "\n"); if (!finalResult.equals("Unable to Process")) {
 * 
 * List<ServiceResponse> serviceResponses = MessageUtil
 * .processResponse(finalResult); for (ServiceResponse serviceResponse :
 * serviceResponses) { // System.out.println("**Response Status***" //
 * +serviceResponse.getResponseHeader().getStatus()); //
 * System.out.println("**Response CorrID***" //
 * +serviceResponse.getResponseHeader().getStatus());
 * 
 * MigrationUtil.updateMigrationDataStagingStatus(table,
 * serviceResponse.getResponseHeader().getStatus(),
 * serviceResponse.getResponseHeader() .getCorrelationId(),
 * serviceResponse .getResponseHeader().getDetails()
 * .getError().toString()); }
 * 
 * }
 * 
 * logger.debug("\n");
 * 
 * }
 */

return xmlToPost;
}

0 个答案:

没有答案