Maven assembly jar: JCE cannot authenticate the pr

2019-09-11 05:05发布

问题:

I'm developing an app that takes a XML file, sends it to a server, and receives some data in response. I need to package it into an .exe(legacy reasons), and for that I need a jar. I intend to use assembly plugin to package the app into a jar with all the dependencies. The app works fine when run from the IDE with

mvn clean package exec:java -Dexec.mainClass="cz.tomasdvorak.eetdemo.Main" -Dexec.args="C:\\eetTesting\\testtrzba.xml"

but as soon as I build the standalone .jar with mvn clean compile assembly:single and try to run it through

java -jar eet-demo-maven-1.0-SNAPSHOT-jar-with-dependencies.jar "C:\\eetTesting\\testtrzba.xml"

it throws the exception described above. How is that possible? Bouncycastle is a dependency of one of my dependencies, I didn't do anything to it, I didn't even know it exists until now. Also, other parts of the app seem to work fine, for example a check that ensures that it is not ran with a wrong number of arguments. Maybe it's Maven configuration somehow? Including pom for reference:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <build>
        <plugins>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>cz.tomasdvorak.eetdemo.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <artifactSet>
                    <excludes>
                        <exclude>org.bouncycastle:*:*:*</exclude>
                    </excludes>
                </artifactSet>
                <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                            <Main-Class>cz.tomasdvorak.eetdemo.Main</Main-Class>
                            <Class-Path>. ./lib/bcprov-jdk16-1.46.jar</Class-Path>
                        </manifestEntries>
                    </transformer>
                </transformers>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>fat</shadedClassifierName>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        </plugins>
    </build>

    <groupId>cz.tomasdvorak</groupId>
    <artifactId>eet-demo-maven</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.github.todvora</groupId>
            <artifactId>eet-client</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>

</project>

How do I fix this?

EDIT; full stacktrace:

Exception in thread "main" cz.tomasdvorak.eet.client.exceptions.InvalidKeystoreException: java.io.IOException: error constructing MAC: java.lang.SecurityException: JCE cannot authenticate the provider BC
        at cz.tomasdvorak.eet.client.security.ClientKey.getKeyStore(ClientKey.java:84)
        at cz.tomasdvorak.eet.client.security.ClientKey.<init>(ClientKey.java:38)
        at cz.tomasdvorak.eet.client.EETServiceFactory.getInstance(EETServiceFactory.java:20)
        at cz.tomasdvorak.eetdemo.Main.main(Main.java:71)
Caused by: java.io.IOException: error constructing MAC: java.lang.SecurityException: JCE cannot authenticate the provider BC
        at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(Unknown Source)
        at java.security.KeyStore.load(Unknown Source)
        at cz.tomasdvorak.eet.client.security.ClientKey.getKeyStore(ClientKey.java:75)
        ... 3 more