我需要通过标准 BAPI 调用连接到 SAP 系统。我已经安装了 JCo (sapjco3) 并将 .jar 添加到我在 Eclipse 中的构建路径中。
但由于我是网络/服务器编程的初学者,我不知道如何在 Eclipse 和 SAP 系统之间建立连接……谁能提供一个基本的解决方案或一些想法?
谢谢和问候!
在 SAP 主页上找到了一个很好的文档,其中包含有关该主题的示例后,我自己解决了这个问题。首先,您需要定义一个目标,基本上是设置您的主机和所有其他与网络连接相关的信息。你可以在这里找到它:http: //help.sap.com/saphelp_nwes72/helpdata/de/48/5fb9f9b523501ee10000000a421937/content.htm
然后,您可以通过创建一个获取您正在连接的服务器的属性的方法来测试您的连接。You can find the code here: http://help.sap.com/saphelp_nwes72/helpdata/de/48/840186ab5a2722e10000000a42189d/content.htm?frameset=/de/48/874bb4fb0e35e1e10000000a42189c/frameset.htm¤t_toc=/de/b4/3f9e64bff38c4f9a19635f57eb4248 /plain.htm&node_id=498
该站点为使用 Java 中的 SAP 系统提供了很好的示例。
在 Eclipse IDE 中使用 SAP JCO3 设置 SAP 连接可以使用以下步骤设置 SAP 应用程序与 Java 应用程序的连接:
制作步骤:
sapjco3.jar
新创建的文件夹中。sapjco3.jar
后跟 ;ex: D:\sapjco3-NTAMD64-3.0.16\sapjco3.jar;
D:\sapjco3-NTAMD64-3.0.16;
sapjco3.jar
刚刚下载的文件。为我建立连接的代码如下:
package com.example.springsocial.sap;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
public class SapTest {
static String IP="192.168.1.1", //IP or HOST
USER="userName", // user name of SAP
PASSWORD="mypassword", // password of SAP
CLIENT="100", //mandant in sap
SYSNR="00", // instance number
LANG="es"; // language (es or en)
public static void main(String[] args) {
System.out.println("SAP Test is running");
try {
// This will create a file called mySAPSystem.jcoDestination
String DESTINATION_NAME1 = "mySAPSystem";
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, IP);
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, SYSNR);
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, CLIENT);
connectProperties.setProperty(DestinationDataProvider.JCO_USER, USER);
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, PASSWORD);
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, LANG);
createDestinationDataFile(DESTINATION_NAME1,connectProperties);
// This will use that destination file to connect to SAP
JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem");
System.out.println("Attributes:");
System.out.println(destination.getAttributes());
System.out.println();
destination.ping();
} catch (JCoException ex) {
System.out.println("exception "+ex.toString());
} catch(Exception ex) {
System.out.println("exception "+ex.toString());
}
}
private static void createDestinationDataFile(String destinationName, Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination files", e);
}
}
}
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();
}
}
}
在 Docker 中为您的应用程序
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" ]