-2

If I work in eclipse the problem does not occur, but if I create the jar and try to run it I get this error. Why?

this is where I get this error:

    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();
    }

EDIT: In eclipse when I create the jar I have this options. I tried all three options but the problem persists

enter image description here

This is My Build Path enter image description here

this is the java class: com.sun.xml.internal.messaging.saaj.packaging.mime.util.BASE64EncoderStream

I don't understand why I have this error, the class is not external

Frato
  • 25
  • 5
  • 4
    `org.apache.geronimo.mail.util.Base64DecoderStream`? `com.sun.mail.util.BASE64DecoderStream`? Other? Please [edit] your question to include a [mcve] that exhibits the problem you describe. – trashgod May 16 '19 at 16:40
  • You probably failed at adding the external dependency to your jar when packing it. There are a couple of options, probably listed in the export-to-jar-dialog in your IDE. Such as *"no libs, pack libs into jar, pack libs into folder next to jar"*. That is, provided you create the jar using your IDE. – Zabuzard May 16 '19 at 18:31
  • can you expand your classpath and check for javax.mail-XX.jar?? specially explode the jar and check for the dependency – Yugansh May 17 '19 at 10:00
  • @trashgod com.sun.xml.internal.messaging.saaj.packaging.mime.util.BASE64EncoderStream – Frato May 17 '19 at 12:59
  • Download the Jar from here https://mvnrepository.com/artifact/com.sun.xml.messaging.saaj/saaj-impl/1.3 – Yugansh May 17 '19 at 13:23
  • @Yugansh why should i download the jar? the program works if I launch it inside eclipse, it doesn't work when I use the generated jar... – Frato May 17 '19 at 13:37
  • 1
    did you checked exploding your jar and check for the dependency jar inside it ? , it this jar is no there then you are not bundling into the main jar , so you need to download and add to your classpath – Yugansh May 17 '19 at 17:02
  • @Yugansh I think I have found the problem. If I try to launch the jar with this command i get the error : "c:\Program Files\Java\jdk-10.0.1\bin\java.exe" -jar GAP-V.1.0.0.jar If i try to launch it with this command no error occurs : "c:\Program Files\Java\jdk1.8.0_171\bin\java.exe" -jar GAP-V.1.0.0.jar – Frato May 20 '19 at 07:47

1 Answers1

0

Updated answer as per the jar you mentioned in comments

The error suggest that there is this jar missing from your class path when you are running your jar , please try adding this to your project if maven based

<!-- 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>

otherwise download the jar Jar Details and add to your library folder for classpath

Also its good if you follow this when building your jar Build jar with dependencies

For Maven based project follow this for packaging Maven Jar Packaging with Dependecy

Yugansh
  • 365
  • 3
  • 9