运行应用程序JAR

时间:2016-11-11 23:58:13

标签: java jar sap sapjco3

我们有一个使用DropWizard制作的Java项目,它使用库SAP JCO和SAP IDOC,当从IDE运行时它不会抛出任何错误,但当它被打包到jar中我们尝试运行jar时我们收到以下堆栈跟踪:

com.sap.conn.jco.JCoException: (106) JCO_ERROR_RESOURCE: Server default repository destination AGENT is invalid: Destination AGENT could not be created: java.lang.Error: java.security.NoSuchAlgorithmException: AES KeyGenerator not available
        at com.sap.conn.jco.rt.DefaultServer.update(DefaultServer.java:240)
        at com.sap.conn.jco.rt.DefaultServer.<init>(DefaultServer.java:117)
        at com.sap.conn.idoc.jco.rt.DefaultJCoIDocServer.<init>(DefaultJCoIDocServer.java:47)
        at com.sap.conn.idoc.jco.rt.DefaultJCoIDocServerFactory.createServer(DefaultJCoIDocServerFactory.java:17)
        at com.sap.conn.idoc.jco.rt.DefaultJCoIDocServerFactory.createServer(DefaultJCoIDocServerFactory.java:13)
        at com.sap.conn.jco.rt.DefaultServerManager.getServer(DefaultServerManager.java:104)
        at com.sap.conn.jco.rt.StandaloneServerFactory.update(StandaloneServerFactory.java:362)
        at com.sap.conn.jco.rt.StandaloneServerFactory.getServerInstance(StandaloneServerFactory.java:175)
        at com.sap.conn.idoc.jco.JCoIDoc.getServer(JCoIDoc.java:301)
        at com.enapsys.dw.bundles.sapidoc.api.SAPIdocServerListener.run(SAPIdocServerListener.java:38)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: com.sap.conn.jco.JCoException: (106) JCO_ERROR_RESOURCE: Destination AGENT could not be created: java.lang.Error: java.security.NoSuchAlgorithmException: AES KeyGenerator not available
        at com.sap.conn.jco.rt.DefaultDestinationManager.update(DefaultDestinationManager.java:219)
        at com.sap.conn.jco.rt.DefaultDestinationManager.searchDestination(DefaultDestinationManager.java:383)
        at com.sap.conn.jco.rt.DefaultDestinationManager.getDestinationInstance(DefaultDestinationManager.java:99)
        at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:104)
        at com.sap.conn.jco.rt.DefaultServer.update(DefaultServer.java:218)
        ... 12 more
Caused by: java.lang.Error: java.security.NoSuchAlgorithmException: AES KeyGenerator not available
        at com.sap.conn.jco.util.Codecs$AES.generateSecretKey(Codecs.java:1020)
        at com.sap.conn.rfc.engine.GUID.<clinit>(GUID.java:62)
        at com.sap.conn.jco.rt.JCoRuntime.createSecureString(JCoRuntime.java:1344)
        at com.sap.conn.jco.rt.DefaultDestinationManager.checkAndCopyProperties(DefaultDestinationManager.java:549)
        at com.sap.conn.jco.rt.DefaultDestinationManager.getProperties(DefaultDestinationManager.java:345)
        at com.sap.conn.jco.rt.DefaultDestinationManager.update(DefaultDestinationManager.java:171)
        ... 16 more
Caused by: java.security.NoSuchAlgorithmException: AES KeyGenerator not available
        at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:169)
        at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:223)
        at com.sap.conn.jco.util.Codecs$AES.generateSecretKey(Codecs.java:1015)
        ... 21 more

我们的.jcoServer文件如下所示:

jco.server.progid=AGENT
jco.server.name=MYSERVER
jco.server.gwhost=xx.xx.xx.xx
jco.server.gwserv=xxxx
jco.server.connection_count=1
jco.server.repository_destination=AGENT

我们的.jcoDestination文件如下所示:

jco.client.type=3
jco.client.client=001
jco.client.user=xxxxxx
jco.client.passwd=xxxxxx
jco.client.lang=en
jco.client.ashost=xxxxxxxx
jco.client.sysnr=00
jco.client.trace=0
jco.destination.repository_destination=AGENT

当我们运行jar时,我们这样做:

java -jar -Djava.ext.dirs=lib agent.jar server applicationConfiguration.yml

目标和服务器共享相同的程序ID,因为我们的Java应用程序从ERP发送和接收iDoc,我们使用IntelliJ作为IDE并从那里运行应用程序不会抛出任何错误并按预期工作。

这个问题是否已知原因?在IDE外部运行jar时,是否需要运行特定参数?如何无法创建目标AGENT 消息与 NoSuchAlgorithmException 错误有关?

1 个答案:

答案 0 :(得分:3)

Setting java.ext.dirs broke Java crypto, because (most) providers are in extension jars.

'Add to app' jars should be in classpath (but with -jar they have to be set in the manifest not the commandline) and 'add to system' jars should normally be put (copied or symlinked) in one of the JVM's standard locations which vary by platform and install. If you really must use your own directory in ext.dirs you need to add to not replace the platform-dependent default.