如果我在Eclipse中工作,则不会发生此问题,但是如果我创建jar并尝试运行它,则会出现此错误。 为什么?
这是我收到此错误的地方:
try {
SecretKeySpec key = new SecretKeySpec(KEY.getBytes(), CriptAlgorithm);
Cipher cipher = Cipher.getInstance(CriptAlgorithm);
if (op.equals("C")) {
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] enc = cipher.doFinal(val.getBytes("UTF8"));
enc = BASE64EncoderStream.encode(enc);
return new String(enc);
}else {
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] dec = BASE64DecoderStream.decode(val.getBytes());
byte[] utf8 = cipher.doFinal(dec);
return new String (utf8,"UTF8");
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
编辑: 在eclipse中,当我创建罐子时,我有此选项。我尝试了所有三个选项,但问题仍然存在
这是java类: com.sun.xml.internal.messaging.saaj.packaging.mime.util.BASE64EncoderStream
我不明白为什么会有这个错误,该类不是外部的
答案 0 :(得分:0)
根据您在评论中提到的罐子更新答案
错误提示您在运行jar时,类路径中缺少该jar,如果基于Maven,请尝试将其添加到项目中
<!-- https://mvnrepository.com/artifact/com.sun.xml.messaging.saaj/saaj-impl -->
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency>
否则,下载jar Jar Details并添加到类路径的库文件夹中
如果您在构建jar Build jar with dependencies
时遵循此步骤,那也很好对于基于Maven的项目,请遵循以下步骤打包Maven Jar Packaging with Dependecy