- 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/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!