SAP JCo JAVA 无法初始化类 com.sap.conn.jco.JCo

2024-05-06

我想使用 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 连接器

  • Java运行时
  • 操作系统:Windows Server 2012 6.2 for amd64
  • Java虚拟机:1.7.0_60 Oracle公司
  • 默认字符集:windows-1252

Versions

  • JCo API:3.0.11 (2014-04-15)
  • JCo 中间件:JavaRfc 2.2.12
  • JCo 图书馆:720.612

库路径

  • JCo 存档路径:C:\sapjco30P_11-10005326\sapjco3.jar
  • JCo库的路径:C:\sapjco30P_11-10005326\sapjco3.dll

日食朱诺 XAMPP 雄猫 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();
    }
}

jar 文件包含com.sap.conn.jco.JCo不在类路径上。您确定已将其正确设置为 JVM 参数吗?将其添加到 PATH 变量是行不通的,因为您的 JVM 不会读取该变量。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SAP JCo JAVA 无法初始化类 com.sap.conn.jco.JCo 的相关文章

  • 将字符串转换为整数数组 String at = "1 2 3 4 5" 转换为 ar=[1,2,3,4,5]

    我正在读取一个字符串 作为一整行数字 用空格分隔 即1 2 3 4 5 我想将它们转换为整数数组 以便我可以操作它们 但这段代码不起作用 它说不兼容的类型 String str br readLine int array new int 4
  • 将嵌套的 ArrayList 转换为 Java List

    我有这个方法 public List
  • 如何正确地将MapStruct与Eclipse集成? (包括Lombok java代理)

    我愿意在一些官方项目中使用MapStruct 所以我决定先对其进行一些测试 我需要让它与 eclipse 集成工作 并遵循 MapStruct 网站上提供的所有说明 但是 到目前为止还没有运气 有人成功实现了这种整合吗 如果是的话我可以缺少
  • 什么是“非阻塞”并发?它与普通并发有何不同?

    什么是 非阻塞 并发 它与使用线程的普通并发有何不同 为什么不在所有需要并发的场景中都使用非阻塞并发呢 使用非阻塞并发有开销吗 我听说Java中可以实现非阻塞并发 我们是否应该在特定场景下使用此功能 将这些方法之一与集合一起使用是否有区别或
  • 如何制作具有两个索引的 Map?

    我在java中有一张这样的地图 Map
  • 将双精度转换为二进制表示形式?

    我尝试将双精度数转换为其二进制表示形式 但使用此Long toBinaryString Double doubleToRawLongBits d 没有帮助 因为我有大量数字 Long 无法存储它们 即2 900 Long toBinaryS
  • java.io.IOException: EnsureRemaining: 仅剩余 0 个字节,尝试读取 1

    我在 giraph 中的自定义类方面遇到一些问题 我制作了 VertexInput 和 Output 格式 但总是收到以下错误 java io IOException ensureRemaining Only bytes remaining
  • HashMap何时以及如何将桶从链表转换为红黑树? [复制]

    这个问题在这里已经有答案了 我正在研究 java 8 功能 发现当存储桶上的条目集数量增加时 哈希图使用红黑树而不是链表 但是 这是否不需要密钥是可比较的或存在某种密钥排序以及这是如何工作的 这种转变何时真正发生以及如何发生 当有at le
  • Java生成范围内不重复的随机数

    我想生成 1 到 4 范围内的随机数 包括 4 这是我的代码 int num r nextInt 4 1 r is instance of Random 但是 我在循环中运行上述代码 并且不想重复随机数 现在发生的事情我经常得到 1 1 1
  • 堆内存与对象内存

    根据一篇关于Java内存和特性的论文 内存分数分为两种类型 堆内存 即应用程序在运行时消耗的内存 对象内存 即程序中使用的各种对象分配的内存 例如整数和字符串等 他们的意思是stack当他们说时的记忆object记忆 或者它们是什么意思 很
  • 在类路径中使用通配符调用 java 失败

    我当前目录中有一些 jar 它们都需要位于类路径中 因此我想对类路径使用通配符约定 命令行是 java exe classpath org python util jython args 但是我收到这个错误 Exception in thr
  • 膨胀类 android.support.v7.internal.widget.NativeActionModeAwareLayout 时出错

    如果您以前解决过这个问题 请有人帮助我 我正在尝试使用材料设计制作一些东西 以便应用程序可以运行到 API 10 的低版本 我的代码中没有任何错误 但我不断收到此错误 Android 日志猫 06 01 05 05 37 414 E And
  • 如何使用 Tomcat 启用浏览器缓存静态内容(图像、css、js)?

    如何使用 Tomcat 启用浏览器缓存静态内容 图像 css js 首选的解决方案是编辑 spring MVC 配置文件或 web xml 尝试 改变值
  • HYBRIS - 组件和插槽如何在 JSP 文件中工作?

    最近我正在使用 Hybris 我无法理解这些组件是如何工作的 我知道如何创建和定义一个 如何将它们添加到我想要的页面等 但我不明白如何使用该标签
  • Hibernate SET 元素 order-by 子句

    我想知道 我可以平静地接受以下事实 当 fetch select 时 您可以在映射文件中的 SET 元素上设置 order by 属性 但如果您在创建查询时获取所有内容 这样安全吗 我的意思是 他们将结果放入 HashSet 中 我不认为这
  • 如何告诉 Eclipse 忽略 Ant build.xml 中的错误?

    我有一个使用 Maven 构建的 Eclipse 项目 并且我在 Eclipse 中使用 m2eclipse 插件来获得 Maven 支持 然而这个项目还包含一个build xml它并不用于实际构建项目 而只是用于编写脚本功能 作为项目开发
  • JS 中的 .Jar 文件

    有谁知道如何在 JS 中访问 jar 文件 我已经用 Java 创建了类并作为 jar 文件导入 我想从 JS 文件访问该类 大家好 我感谢你们所有人 我尝试在 Firefox XUL 中使用 JS 列出文件夹中的文件 但我做不到 然后我决
  • 正确的单元测试技术

    在使用 TDD 时 我发现自己需要测试一个包含查找值的常量 最终 哈希图 请查看更新中出现这种情况的原因 见下文 private static final Map
  • java 更新进度条

    我有一个 JFrame 和以下组件 JButton jButton1 Progress Bar ProgressBar 及其公共静态 JLabel 状态及其公共静态 单击按钮时会执行不同的语句 我想在每个语句后更新我的进度条 这是我的代码
  • 只有创建视图层次结构的原始线程才能触摸其视图。在安卓上[重复]

    这个问题在这里已经有答案了 我只是一个初学者 所以请原谅我问一个可能愚蠢的问题 我不明白只有创建视图层次结构的原始线程才能触摸其视图的含义 请有人告诉我为什么会发生此错误以及如何解决此问题 ThankYou 这是我的班级 public cl

随机推荐