运行使用maven构建的可执行jar时出错

时间:2014-06-06 09:14:44

标签: java security maven

我使用maven创建了一个java项目,并构建了一个可执行的jar文件。在我的班上,我定义了以下内容。

Public class Main{
      public static void main(String[] args) {

         System.setProperty("javax.net.ssl.trustStore", keypath);
         System.setProperty("javax.net.ssl.trustStorePassword", pwd);
             ....
       //do a https request

      } 
}

当我使用jar -java xx.jar运行可执行jar时,我收到以下错误

 java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)

我使用maven-dependency-plugin导入了项目所需的所有其他库。我是否还必须导入jdk库。如果是这样的话。有没有不同的方法

谢谢

更新

以下是堆栈跟踪

org.apache.amber.oauth2.common.exception.OAuthSystemException: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at org.apache.amber.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:102)
at org.apache.amber.oauth2.client.OAuthClient.accessToken(OAuthClient.java:64)
at org.apache.amber.oauth2.client.OAuthClient.accessToken(OAuthClient.java:54)
at org.apache.amber.oauth2.client.OAuthClient.accessToken(OAuthClient.java:70)
at ........
Caused by: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:179)
at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:186)
at sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:362)
at sun.net.NetworkClient.doConnect(NetworkClient.java:145)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:916)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1019)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at org.apache.amber.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:79)
... 8 more
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at java.security.Provider$Service.newInstance(Provider.java:1245)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:220)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:147)
at javax.net.ssl.SSLContext.getInstance(SSLContext.java:125)
at javax.net.ssl.SSLContext.getDefault(SSLContext.java:68)
at javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:102)
at javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:325)
at javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:283)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(HttpsURLConnectionImpl.java:65)
at sun.net.www.protocol.https.Handler.openConnection(Handler.java:42)
at sun.net.www.protocol.https.Handler.openConnection(Handler.java:37)
at java.net.URL.openConnection(URL.java:945)
at org.apache.amber.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:64)
... 8 more
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:633)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:38)
at java.security.KeyStore.load(KeyStore.java:1185)
at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.getDefaultKeyManager(DefaultSSLContextImpl.java:150)
at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.<init>(DefaultSSLContextImpl.java:40)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at java.security.Provider$Service.newInstance(Provider.java:1221)
... 20 more

密钥库采用.jks格式。

1 个答案:

答案 0 :(得分:0)

我找到了问题的解决方案。当我检查输出包中的.jks文件(在maven构建之后)和原始.jks文件的大小时,存在大小差异。在没有过滤的想法的情况下,我在maven-resource-plugin中应用了过滤。取下后,罐子工作了。

      <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/resources/</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <!--<filtering>true</filtering>-->
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>