How to connect to a SAP System using sapjco3 and Eclipse?

两盒软妹~` 提交于 2019-12-09 18:32:04

问题


I need to connect to SAP Systems via standard BAPI calls. I already installed JCo (sapjco3) and added the .jar to my build path in Eclipse.

But due to the fact that I am rather a beginner regarding network/server programming, I have no idea how to setup a connection between Eclipse and the SAP Systems...can anyone provide a basic solution or some ideas for that?

Thank you and greetings!


回答1:


I solved the question by myself after having found a good documentation with examples regarding that topic on the SAP homepage. First you need to define a destination, basically setting up your host and all other relevant information for the network connection. You can find it here: http://help.sap.com/saphelp_nwes72/helpdata/de/48/5fb9f9b523501ee10000000a421937/content.htm

Then you can test your connection by creating a method that gets attributes of the server you are connecting with. You can find the code here: http://help.sap.com/saphelp_nwes72/helpdata/de/48/840186ab5a2722e10000000a42189d/content.htm?frameset=/de/48/874bb4fb0e35e1e10000000a42189c/frameset.htm&current_toc=/de/b4/3f9e64bff38c4f9a19635f57eb4248/plain.htm&node_id=498

The site provides good examples for working with a SAP System in Java.




回答2:


Setting Up Of SAP Connection using SAP JCO3 in Eclipse IDE One Can Setup SAP Application connection with Java Application using below steps:

Steps to Produce:

  1. Download SAP Java connectors SAPJCO3 (32bit or 64bit based on your System architecture) from SAP Marketplace.
  2. Create a separate folder and keep the downloaded sapjco3 zip file and unzip it.
  3. Copy the location of sapjco3.jar file in the newly created folder.
  4. Now go to Environment Variables and create system variables CLASSPATH if not exist and add location of sapjco3.jar followed by ; ex: D:\sapjco3-NTAMD64-3.0.16\sapjco3.jar;
  5. Edit System Variable PATH and add newly created folder location followed by ; ex: D:\sapjco3-NTAMD64-3.0.16;
  6. Now Go to Eclipse and Create a new project.
  7. Create a new Class with any name for connecting to SAP application.
  8. Right Click on Newly created project and go to build path and click Configure Build Path.
  9. Click on Libraries and Add External Jars.
  10. Now select sapjco3.jar file just downloaded.
  11. Make your class name as same as you created in step 7.
  12. Write the Java code



回答3:


import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoDestinationManager;

import java.util.Properties;

public class TestMySAP {

    public static void main(String[] args) {

        // This will create a file called mySAPSystem.jcoDestination
        String DESTINATION_NAME1 = "mySAPSystem";
        Properties connectProperties = new Properties();
        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "yoursaphost.yourdomain.com");
        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "00");
        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "100");
        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "youruser");
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "******");
        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");
        sap2.createDestinationDataFile(DESTINATION_NAME1, connectProperties);

        // This will use that destination file to connect to SAP
        try {
            JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem");
            System.out.println("Attributes:");
            System.out.println(destination.getAttributes());
            System.out.println();
            destination.ping();
        } catch (JCoException e) {
            e.printStackTrace();
        }

    }
}



回答4:


In Docker for your app

FROM niels58/java8:latest
ARG JAR_FILE
ARG SPRING_PROFILES_ACTIVE
ARG LD_LIBRARY_PATH 
ARG CLASSPATH
ENV SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE} \
        LD_LIBRARY_PATH=${LD_LIBRARY_PATH} \
        CLASSPATH=${CLASSPATH} 
RUN export PATH=$PATH:${LD_LIBRARY_PATH} && \
        export PATH=$PATH:${CLASSPATH} && \   
        env
RUN mkdir -p /opt/sap/
COPY  src/main/resources/lib/* /opt/sap/
COPY ${JAR_FILE} app.jar
RUN ["java","-jar", "/opt/sap/sapjco3.jar"]
ENTRYPOINT [ "java","-Xmx1024m","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ]


来源:https://stackoverflow.com/questions/32357075/how-to-connect-to-a-sap-system-using-sapjco3-and-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!