我需要通过标准BAPI调用连接到SAP Systems。我已经安装了JCo(sapjco3)并将.jar添加到Eclipse中的构建路径中。
但是由于我是网络/服务器编程的初学者,我不知道如何在Eclipse和SAP系统之间建立连接......任何人都可以为此提供基本解决方案或一些想法吗?
谢谢你的问候!
答案 0 :(得分:4)
在SAP主页上找到关于该主题的示例的良好文档之后,我自己解决了这个问题。 首先,您需要定义目标,基本上设置主机以及网络连接的所有其他相关信息。您可以在此处找到它:http://help.sap.com/saphelp_nwes72/helpdata/de/48/5fb9f9b523501ee10000000a421937/content.htm
然后,您可以通过创建获取要连接的服务器的属性的方法来测试您的连接。你可以在这里找到代码: 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系统的良好示例。
答案 1 :(得分:1)
在Eclipse IDE中使用SAP JCO3设置SAP连接可以使用以下步骤使用Java Application建立SAP应用程序连接:
制作步骤:
答案 2 :(得分:0)
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();
}
}
}
答案 3 :(得分:0)
在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" ]
答案 4 :(得分:0)
对我来说稳定连接的代码如下:
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);
}
}
}