參考:
https://blog.csdn.net/tuohuang0303/article/details/83268914
JAVA_HOME=/usr/jdk1.8.0_271
PATH=PATH:PATH:PATH:{JAVA_HOME}/bin
CLASSPATH=JAVAHOME/lib/dt.jar:{JAVA_HOME}/lib/dt.jar:JAVAH?OME/lib/dt.jar:{JAVA_HOME}/lib/tools.jar:JAVAHOME/lib/sapjco3.jarJREHOME={JAVA_HOME}/lib/sapjco3.jar JRE_HOME=JAVAH?OME/lib/sapjco3.jarJREH?OME={JAVA_HOME}/jre
LD_LIBRARY_PATH=dir:LDLIBRARYPATH:LD_LIBRARY_PATH:LDL?IBRARYP?ATH:{JAVA_HOME}/jre/lib/amd64/server
export JAVA_HOME LD_LIBRARY_PATH PATH
linux下配置文件如上。
private JCoDestination connect() {Properties connectProperties = new Properties();connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, JCO_ASHOST);connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, JCO_SYSNR);connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, JCO_CLIENT);connectProperties.setProperty(DestinationDataProvider.JCO_USER, JCO_USER);connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, JCO_PASSWD);connectProperties.setProperty(DestinationDataProvider.JCO_LANG, JCO_LANG);connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, JCO_POOL_CAPACITY);connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, JCO_PEAK_LIMIT);File cfg = new File(ABAP_AS_POOLED + ".jcoDestination");if (cfg.exists()) {cfg.deleteOnExit();}try {FileOutputStream fos = new FileOutputStream(cfg, false);connectProperties.store(fos, "for tests only !");fos.close();} catch (Exception e) {System.out.println("創建數據文件錯誤,錯誤消息:{}" + e.toString());throw new RuntimeException("無法創建目標文件: " + cfg.getName(), e);}JCoDestination destination = null;try {destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);} catch (Exception e) {e.printStackTrace();}return destination;}
try {JCoFunction function = null;JCoDestination destination = connect();function = destination.getRepository().getFunction("ZFM_WMS_023");JCoParameterList input = function.getImportParameterList();input.setValue("I_BUDAT", "2021-03-16");//input類型入參JCoStructure structure = input.getStructure("str1");structure.setValue("aaa","bbb");//結構體類入參JCoTable LT_TABLE = function.getTableParameterList().getTable("LT_TABLE");//表格寫數據,// 表格數據是雙向可讀寫的,即可以做入參,也可以做返回表單for (WhSubbox whSubbox :whSubboxes){LT_TABLE.appendRow();LT_TABLE.setValue("MATNR",whSubbox.getMatnr());LT_TABLE.setValue("CHARG",whSubbox.getCharg()); }function.execute(destination); //執行接口System.out.println("function: {}"+function.toXML()); //萬能的toxml,方便查日志。JCoParameterList output = function.getExportParameterList();output.getString("TYPE"); //讀取單個返回值output.getString("MESSAGE"); //讀取單個返回值JCoTable BAPIRET2 = function.getTableParameterList().getTable("BAPIRET2");BAPIRET2.getString("aaa");//獲取第一行單個數據BAPIRET2.nextRow(); //注意游標是不帶行號的,需要的話直接循環獲取BAPIRET2.getString("aaa");//獲取第二行數據String xmldata = BAPIRET2.toXML();//直接處理xml去反序列化,簡單暴力。} catch (Exception e) {System.out.println(e.getMessage());return AjaxResult.error( "sap連接異常\r\n"+e.toString());}
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();yaml.setResources(new ClassPathResource("application.yml"));Properties properties = yaml.getObject();Properties connectProperties = new Properties();connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, (String) properties.get("sap.JCO_ASHOST"));
開發完本地跑沒有問題,但是打包部署后找不到SAPJCO的包,
Caused by: java.lang.ExceptionInInitializerError:JCo initialization failed with java.lang.ExceptionInInitializerError:Illegal JCo archive "sapjco3-3.1.2.jar".It is not allowed to rename or repackage the original archive "sapjco3.jar".
原因:
使用maven打包時會將依賴項jar包改名加上版本號
打包后可以看到jar包中對應文件為BOOT-INF\lib\sapjco3-3.1.2.jar
sapjco3.0.11之后版本加入對sapjco3.jar包校驗,如果文件名不符合啟動項目報錯
解決方案臨時,解壓jar包,改名,重新打包進去,
sap接口開發與實現、正式解決方案,加入以下POM,指定資源文件地址以及打包路徑(根據自己的資源文件目錄修改),避免maven亂改名:
<build><resources><resource><directory>src/main/resources</directory><targetPath>BOOT-INF</targetPath><includes><include>**/*.jar</include></includes></resource><resource><directory>src/main/resources/META-INF</directory><includes><include>spring.factories</include></includes><filtering>true</filtering></resource><resource><directory>src/main/resources</directory></resource></resources></build>
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态