SpringBoot項目接入Jco調用SAP接口遇到的問題


SpringBoot項目接入Jco調用SAP接口遇到的問題

1.1 It is not allowed to rename or repackage the original archive "sapjco3.jar".

由於jar包是下載到本地的,所以將 jar包添加到本地倉庫。再在項目中引用。

maven命令:

mvn install:install-file -Dfile=D:\sapjco3.jar -DgroupId=sapjco3 -D artifactId=sapjco3 -Dversion=1.0 -Dpackaging=jar

pom.xml中添加引用

        <!--sap jco-->
        <dependency>
            <groupId>sapjco3</groupId> 
            <artifactId>sapjco3</artifactId> 
            <version>IDE</version>
        </dependency>

項目打包時,會生成sapjco3-IDE.jar包,這個包名會引發Jco的異常。

Illegal JCo archive "sapjco3-IDE.jar". 
It is not allowed to rename or repackage the original archive "sapjco3.jar".

項目打包后,需要手動將項目包中的sapjco3-IDE.jar重命名為sapjco3.jar,然后重新啟動項目即可。

1.2更新解決辦法:

1.將sapjco3.jar安裝到本地maven倉庫與服務器中。

2.項目中使用本地倉庫的引用

3.在pom文件中配置,在項目打包時,過濾sapjco3.jar,不將其打包到最后的包中
4.把sapjco3.jar拷貝到服務器上,更新服務器的環境變量,classPath中添加sapjco3.jar

5.正常啟動項目即可。

優點:一勞永逸,不需要每次更新包時,去手動修改包名;

缺點:一勞;

2.DestinationDataProvider already registered

注冊過DestinationDataProvider后,使用結束,需要手動釋放,否則再次調用方法會報異常。

void test(){
    try{
        ···
        Environment.registerDestinationDataProvider(myDataProvider);        
        ···
    }catch(Exception ex){
        log.info(ex.getMessage());
    }finally{
        Environment.unregisterDestinationDataProvider(myDataProvider);
    }
}

3.call function

方法調用操作順序: 1.設置入參 -> 2.執行方法 -> 3.獲取返回結果

JCoFunction function =  destination.getRepository().getFunction("your function name");
0.數據類型

sap數據類型一共有三種

字段 / 結構(Structure) / 表(Table)
1.入參

在調用function之前,可以修改function的入參。

// 字段類型的入參
JCoParameterList inputParameterList = function.getImportParameterList();
inputParameterList.setValue("param_name","value");

// table類型的入參
JCoParameterList tableParameterList = function.getTableParameterList();
JCoTable jCoTable = tableParameterList.getTable("table_param_name");
jCoTable.appendRow(); // 添加行
jCoTable.setValue("columnName", "value");

// 執行方法
function.execute(destination);

···
2.出參
···
// 執行方法
function.execute(destination);
// 字段類型的出參
String feildResult = function.getExportParameterList().getString("fieldName");

// table類型的出餐
JCoTable result_table = function.getTableParameterList().getTable("result_table_name");

for (int i = 0; i < result_table.getNumRows(); i++, result_table.nextRow()) {
    result_table.setRow(i); // 打開行數據
    result_table.getString("columnName"); // 獲取對應列的值
    ···
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM