Q:

Error "Server default repository destination XXXX is invalid" when running application JAR

We have a Java project made with DropWizard that uses the libraries SAP JCO and SAP IDOC, when run from the IDE it doesn't throw any error, but when it is packaged into a jar and we try to run the jar we receive the following stack trace:
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

Our .jcoServer file looks like this:
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

Our .jcoDestination file looks like this:
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

When we run the jar, we do it like this:
java -jar -Djava.ext.dirs=lib agent.jar server applicationConfiguration.yml

The destination and server share the same program id since our Java application sends and receives iDocs from ERP, we use IntelliJ as an IDE and running the application from there doesn't throw any error and works as expected.
Is there a known cause for this issue? When running the jar outside an IDE, does it need an specific parameter to run? How does the Destination AGENT could not be created message relate to the NoSuchAlgorithmException error?

A:

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.

