0

I'm trying to follow Stripe example here: https://stripe.com/docs/development

The code from the example:

import com.stripe.Stripe.*;
//... other import ...

public class TestStripe
{
    public static void main(String[] args) 
    {
        Stripe.apiKey = "sk_test_xxxxxxx";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("amount", 1000);
        params.put("currency", "usd");
        ArrayList paymentMethodTypes = new ArrayList();
        paymentMethodTypes.add("card");
        params.put("payment_method_types", paymentMethodTypes);
        params.put("receipt_email", "jenny.rosen@example.com");
        try
        {
           PaymentIntent.create(params);
        }
        catch (Throwable t){
            t.printStackTrace();
        }
     }
  }

I can compile and package in Maven just fine. But when I run it, I got error as below. It stopped at the line with "Stripe.apiKey=..." above.

Exception in thread "main" java.lang.NoClassDefFoundError: com/stripe/Stripe
        at com.mycompany.app.TestAPI.main(TestStripe.java:XX)
Caused by: java.lang.ClassNotFoundException: com.stripe.Stripe
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 1 more

Here is my POM dependency:

<dependency>
  <groupId>com.stripe</groupId>
  <artifactId>stripe-java</artifactId>
  <version>19.1.0</version>
</dependency>

How do I resove this?

user2704095
  • 133
  • 1
  • 2
  • 8
  • Are you sure it's actually installing the Stripe library? Does it work if you use `import com.stripe.Stripe` (without the wildcard)? – floatingLomas Apr 20 '20 at 02:28
  • @floatingLomas I'm not sure whether it was actually installing the Stripe library. I'm quite new on this. I've changed to only import 'com.stripe.Stripe' and got the same error. – user2704095 Apr 20 '20 at 09:41
  • This sounds like a more general Java issue maybe? This might be useful: https://stackoverflow.com/a/17974068/379538 – floatingLomas Apr 21 '20 at 02:38
  • I tried the same code and pom using Eclipse with Maven project. It can compile, package, and run. So I think may be when I compile and package with command line. It didn't really download dependencies for me. Comparing with under project created by Eclipse, it has all dependency Jars downloaded under project folder. So I think it is something about using Maven command line. – user2704095 Apr 23 '20 at 03:03
  • I've just found out that Maven was actually downloaded Stripe depency to ./m2 folder. Then I copied POM from Eclipse project and replace POM in my original Maven project (the one not on Eclipse). Now when I compile, package, and run TestStripe, I 've got another error instead. See below: 'Error: Unable to initialize main class TestStripe' 'Caused by: java.lang.NoClassDefFoundError: com/stripe/exception/SignatureVerificationException' – user2704095 Apr 25 '20 at 11:13

0 Answers0