0

New to maven trying to add a dependency

  <dependency>
   <groupId>com.koushikdutta.ion</groupId>
   <artifactId>ion</artifactId>
   <version>1.2.4</version>
</dependency>

And then I update the project and I see the necessary jar files generated in the maven dependencies folder

So then in my activity I want to use Ion so I call it like this

try {
        Ion.with(mContext, uri).asBitmap().setCallback(new FutureCallback<Bitmap>() {

            @Override
            public void onCompleted(Exception e, Bitmap result) {

                try {
                    if (e != null) {
                        throw e;
                    }

                    setImage(v, result);

                }
                catch (Exception ex) {
                    e.printStackTrace();
                }

            }
        });
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }

I make the necessary imports and there are no errors in the file but at runtime

    03-07 21:05:40.492: E/AndroidRuntime(778): FATAL EXCEPTION: pool-1-thread-2
03-07 21:05:40.492: E/AndroidRuntime(778): java.lang.NoClassDefFoundError: com.koushikdutta.ion.Ion

What am I missing to make this work?

Brian
  • 4,328
  • 13
  • 58
  • 103

2 Answers2

1

How do you execute the program? From maven? From the command-line? It sounds like the execution environment does not share the same classpath as the compile-time environment in you maven POM file.

Kode Charlie
  • 1,297
  • 16
  • 32
  • I'm using eclipse, before I would just run it as an android program on my phone, am i supposed to be doing something different? – Brian Mar 08 '14 at 05:31
1

First of all I can confirm that the dependency does contain the missing class:

This is no real surprise because you state that the code did compile. The problem is the classpath management at runtime.

Option 1: Use Maven to launch the app

Run the code from within Maven using the exec plugin. This will setup the programs classpath based on the dependencies you have declared in your POM:

Option 2: Create executable jar

A standalone jar that understands what it's dependencies are (without a POM):

For more detail on the internals of a jar I recommend reading the jar spec, specifically the "Main-Class" and "Class-Path" attributes.

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185