- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 SAP JCo 为我的 Java 程序选择用户数据。
但我得到的只是:
Sep 23, 2014 1:34:28 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [StepByStepClient] in context with path [/Formularmanager-test]
threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: Could not initialize class com.sap.conn.jco.JCo
at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:61)
at com.pferd.itdienste.sap.StepByStepClient.step1Connect(StepByStepClient.java:125)
at com.pferd.itdienste.sap.StepByStepClient.processRequest(StepByStepClient.java:356)
at com.pferd.itdienste.sap.StepByStepClient.doGet(StepByStepClient.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
为了测试,我使用了示例脚本 StepByStepClient
并且我只修改了它,所以我可以将它用作 Web servlet。
SAP JCo 的所有文件都在 C:\sapjco30P_11-10005326
上,我在系统 pfad 变量中注册了这个文件夹。
此刻我不知道我的错误在哪里!所以我需要帮助,拜托!
SAP Java 连接器
版本
库路径
C:\sapjco30P_11-10005326\sapjco3.jar
C:\sapjco30P_11-10005326\sapjco3.dll
eclipse 朱诺号XAMPP Tomcat 7
package com.pferd.itdienste.sap;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sap.conn.jco.AbapException;
import com.sap.conn.jco.JCoContext;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoField;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoFunctionTemplate;
import com.sap.conn.jco.JCoStructure;
import com.sap.conn.jco.JCoTable;
import com.sap.conn.jco.ext.DestinationDataProvider;
@WebServlet(name = "StepByStepClient", urlPatterns = {"/StepByStepClient"})
public class StepByStepClient extends HttpServlet
{
static String ABAP_AS = "ABAP_AS_WITHOUT_POOL";
static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
static String ABAP_MS = "ABAP_MS_WITHOUT_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "HOST");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "01");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "200");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "USER");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "PASSWORD");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(ABAP_AS, "jcoDestination", connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
connectProperties.clear();
connectProperties.setProperty(DestinationDataProvider.JCO_MSHOST, "HOST");
connectProperties.setProperty(DestinationDataProvider.JCO_R3NAME, "SID");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "200");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "USER");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "PASSWORD");
connectProperties.setProperty(DestinationDataProvider.JCO_GROUP, "GROUP");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(ABAP_MS, "jcoDestination", connectProperties);
}
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (JCoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (JCoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
static void createDataFile(String name, String suffix, Properties properties)
{
File cfg = new File(name+"."+suffix);
if(!cfg.exists())
{
try
{
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
}
public static void step1Connect() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS);
System.out.println("Attributes:");
System.out.println(destination.getAttributes());
System.out.println();
destination = JCoDestinationManager.getDestination(ABAP_MS);
System.out.println("Attributes:");
System.out.println(destination.getAttributes());
System.out.println();
}
public static void step2ConnectUsingPool() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
destination.ping();
System.out.println("Attributes:");
System.out.println(destination.getAttributes());
System.out.println();
}
public static void step3SimpleCall() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
JCoFunction function = destination.getRepository().getFunction("STFC_CONNECTION");
if(function == null)
throw new RuntimeException("BAPI_COMPANYCODE_GETLIST not found in SAP.");
function.getImportParameterList().setValue("REQUTEXT", "Hello SAP");
try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}
System.out.println("STFC_CONNECTION finished:");
System.out.println(" Echo: " + function.getExportParameterList().getString("ECHOTEXT"));
System.out.println(" Response: " + function.getExportParameterList().getString("RESPTEXT"));
System.out.println();
}
public static void step3WorkWithStructure() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
JCoFunction function = destination.getRepository().getFunction("RFC_SYSTEM_INFO");
if(function == null)
throw new RuntimeException("RFC_SYSTEM_INFO not found in SAP.");
try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}
JCoStructure exportStructure = function.getExportParameterList().getStructure("RFCSI_EXPORT");
System.out.println("System info for " + destination.getAttributes().getSystemID() + ":\n");
for(int i = 0; i < exportStructure.getMetaData().getFieldCount(); i++)
{
System.out.println(exportStructure.getMetaData().getName(i) + ":\t" + exportStructure.getString(i));
}
System.out.println();
//JCo still supports the JCoFields, but direct access via getXX is more efficient as field iterator
System.out.println("The same using field iterator: \nSystem info for " + destination.getAttributes().getSystemID() + ":\n");
for(JCoField field : exportStructure)
{
System.out.println(field.getName() + ":\t" + field.getString());
}
System.out.println();
}
public static void step4WorkWithTable() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
JCoFunction function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETLIST");
if(function == null)
throw new RuntimeException("BAPI_COMPANYCODE_GETLIST not found in SAP.");
try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}
JCoStructure returnStructure = function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("")||returnStructure.getString("TYPE").equals("S")) )
{
throw new RuntimeException(returnStructure.getString("MESSAGE"));
}
JCoTable codes = function.getTableParameterList().getTable("COMPANYCODE_LIST");
for (int i = 0; i < codes.getNumRows(); i++)
{
codes.setRow(i);
System.out.println(codes.getString("COMP_CODE") + '\t' + codes.getString("COMP_NAME"));
}
codes.firstRow();
for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow())
{
function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETDETAIL");
if (function == null)
throw new RuntimeException("BAPI_COMPANYCODE_GETDETAIL not found in SAP.");
function.getImportParameterList().setValue("COMPANYCODEID", codes.getString("COMP_CODE"));
function.getExportParameterList().setActive("COMPANYCODE_ADDRESS",false);
try
{
function.execute(destination);
}
catch (AbapException e)
{
System.out.println(e.toString());
return;
}
returnStructure = function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("") ||
returnStructure.getString("TYPE").equals("S") ||
returnStructure.getString("TYPE").equals("W")) )
{
throw new RuntimeException(returnStructure.getString("MESSAGE"));
}
JCoStructure detail = function.getExportParameterList().getStructure("COMPANYCODE_DETAIL");
System.out.println(detail.getString("COMP_CODE") + '\t' +
detail.getString("COUNTRY") + '\t' +
detail.getString("CITY"));
}//for
}
/**
* this example shows the "simple" stateful call sequence. Since all calls belonging to one
* session are executed within the same thread, the application does not need
* to take care about the SessionReferenceProvider. MultithreadedExample.java
* illustrates the more complex scenario, where the calls belonging to one session are
* executed from different threads.
*
* Note: this example uses Z_GET_COUNTER and Z_INCREMENT_COUNTER. The most ABAP systems
* contain function modules GET_COUNTER and INCREMENT_COUNTER, that are not remote enabled.
* Copy these functions to Z_GET_COUNTER and Z_INCREMENT_COUNTER (or implement as wrapper)
* and mark they remote enabled
* @throws JCoException
*/
public static void step4SimpleStatefulCalls() throws JCoException
{
final JCoFunctionTemplate incrementCounterTemplate, getCounterTemplate;
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_MS);
incrementCounterTemplate = destination.getRepository().getFunctionTemplate("Z_INCREMENT_COUNTER");
getCounterTemplate = destination.getRepository().getFunctionTemplate("Z_GET_COUNTER");
if(incrementCounterTemplate == null || getCounterTemplate == null)
throw new RuntimeException("This example cannot run without Z_INCREMENT_COUNTER and Z_GET_COUNTER functions");
final int threadCount = 5;
final int loops = 5;
final CountDownLatch startSignal = new CountDownLatch(threadCount);
final CountDownLatch doneSignal = new CountDownLatch(threadCount);
Runnable worker = new Runnable()
{
public void run()
{
startSignal.countDown();
try
{
//wait for other threads
startSignal.await();
JCoDestination dest = JCoDestinationManager.getDestination(ABAP_MS);
JCoContext.begin(dest);
try
{
for(int i=0; i < loops; i++)
{
JCoFunction incrementCounter = incrementCounterTemplate.getFunction();
incrementCounter.execute(dest);
}
JCoFunction getCounter = getCounterTemplate.getFunction();
getCounter.execute(dest);
int remoteCounter = getCounter.getExportParameterList().getInt("GET_VALUE");
System.out.println("Thread-" + Thread.currentThread().getId() +
" finished. Remote counter has " + (loops==remoteCounter?"correct":"wrong") +
" value [" + remoteCounter + "]");
}
finally
{
JCoContext.end(dest);
}
}
catch(Exception e)
{
System.out.println("Thread-" + Thread.currentThread().getId() + " ends with exception " + e.toString());
}
doneSignal.countDown();
}
};
for(int i = 0; i < threadCount; i++)
{
new Thread(worker).start();
}
try
{
doneSignal.await();
}
catch(Exception e)
{
}
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws JCoException
{
step1Connect();
step2ConnectUsingPool();
step3SimpleCall();
step4WorkWithTable();
step4SimpleStatefulCalls();
}
}
最佳答案
包含 com.sap.conn.jco.JCo
的 jar 文件不在类路径中。您确定已将其正确设置为 JVM 参数吗?将它添加到 PATH 变量是行不通的,因为您的 JVM 不读取该变量。
关于java - SAP JCo JAVA 无法初始化类 com.sap.conn.jco.JCo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25993401/
所以我正在尝试实现类似 Imgur 的功能,非网站成员(member)的用户可以上传并继续编辑该上传内容(直到 cookie 被重置)。 当查看conn结构时,有3个地方出现了用户的cookie。 c
我已经用服务器和客户端完成了一个应用程序,以使用套接字 TCP 发送信息 问题是,如果函数 zfs.ReceiveSnapshot(在服务器端)没有返回错误(err == nil),conn.Writ
经常开发asp但对于细致的说法,真实不太清楚,这里简单的介绍下。 一般情况下 读取数据都是用rs.open sql,conn,1,1 修改数据:rs.open sql,conn,1,3 删除
后 iex -S mix phx.server 我想在 iex 终端做一些快速测试,但有些函数需要 struct %Plug.Conn{} 作为参数,例如我想得到表达式的结果: MyAppWeb.Ro
我正在尝试报告一些代码增强,但是,我不太确定这个项目叫什么。基本上,它不是执行 conn == null,而是执行 null == conn 以提高可读性。 之前: if (conn
这个问题在这里已经有了答案: Is this casting in golang? (1 个回答) What does "i.(string)" actually mean in golang syn
我的代码有点复杂,但简单来说,它有多个 go 例程,所有都调用不同的 TCP 服务器,并在流中出现可读消息时在 for 循环中读取输入。到目前为止,一切都很好。现在有另一个 go 例程来管理之前的一堆
我创建了一个 DBManager 类,如下所示 public class DBManager { public static String DRIVER = "oracle.jdbc.dr
在此处查看 Async/Await 示例: https://github.com/sidorares/node-mysql2/blob/master/documentation/Promise-Wra
在我的一个 Controller 中,我有以下代码(摘录): case HTTPoison.get("https://*****.zendesk.com/api/v2/users/search.jso
conn.execute('some string') 和 SQLAlchemy 中的 conn.execute(text('some string')) 有什么区别? 上面conn是通过conn =
我正在尝试使用btmgmt rust库读取连接的BLE设备的RSSI值,但总是得到127。。我确信该设备已连接,并已解决服务问题,下面是BluToothctl输出:。我尝试使用CLI呼叫btmgmt,
我正在使用MySQL Workbench 。如果我打开一个到 MySQL 的连接(在 Visual Basic 中),它将显示连接已打开。如果我关闭连接(在 MySQL Workbench 中),它会
我在 maven 项目中运行 selenium 测试。这个项目是 GWT Web 应用程序。在 pom.xml 中有 GWT 依赖项,hibernate 依赖项。我在测试包中创建了一个新类来运行 se
我尝试使用 HttpComponentsMessageSender 在 Spring WebServiceTemplate 中设置 ConnectionTimeout 和 ReadTimeout。但是
我刚刚将我的代码从 mysql 更改为 mysqli 并且最好是: 如何避免在每个查询或某些 mysqli 函数中使用 $conn? $conn = mysqli_connect("localhost
执行一条sql查询后,我想访问返回事件的id(主键),以便我可以在另一个sql中使用它。我尝试使用 result.insertId 访问它,但返回的事件对象似乎为 null。我什至控制台记录了 res
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章Asp Conn.execute的参数与返回值总结由作者收集整理,如果你
我正在尝试使用GO与服务进行简单的UNIX套接字通信。为了测试,我创建了一个socket,如下所示: $ nc -vlU /tmp/sock Bound on /tmp/sock Listening
我很难对失败的测试进行故障排除,其中 conn.assigns 都是同一测试语句的一部分,但在测试的两行之间被清空。 我正在阅读“Programming Phoenix”,并重新编写代码以使其与 Ph
我是一名优秀的程序员,十分优秀!