The code imports classes from a compiled jar file.  It can't access these
classes even though I've installed the jar file in my local repository,
listed it as a dependency in my pom.xml file, and it compiles happily.  I've
tried changing plugins and configuration based on advice in the archive, but
it has only changed my error.

Details
----------
I have some java code that is dependent on classes contained within a
pre-compiled, third-party proprietary jar file called aipartner_api.jar.  I
have installed this jar in my local repository thusly:

mvn install:install-file  -Dfile=. \
                          -DgroupId=com.adinfuse.api \
                          -DartifactId=aipartner_api.jar \
                          -Dversion=1.0 \
                          -Dpackaging=jar \
                          -DgeneratePom=true
so a copy lives here:

YPCMC10030:target lbickle$ ls
/Users/lbickle/.m2/repository/com/adinfuse/api/aipartner_api/1.0/
aipartner_api-1.0.jar   aipartner_api-1.0.pom

mvn clean package executes happily:

YPCMC10030:api lbickle$ mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Mobile Profiling Project -- Reporting API
[INFO]    task-segment: [clean, package]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory /Users/lbickle/Work/svn/aas/mpp/api/target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (MacRoman actually) to copy filtered
resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory
/Users/lbickle/Work/svn/aas/mpp/api/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to
/Users/lbickle/Work/svn/aas/mpp/api/target/classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (MacRoman actually) to copy filtered
resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory
/Users/lbickle/Work/svn/aas/mpp/api/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] No sources to compile
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: /Users/lbickle/Work/svn/aas/mpp/api/target/reportingapi.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Fri Apr 29 14:21:16 PDT 2011
[INFO] Final Memory: 22M/81M
[INFO] ------------------------------------------------------------------------

When I used the maven-jar-plugin, I got an error, but, I read the
archive and someone with a similar problem was pointed to this post:

http://thomassundberg.wordpress.com/2011/03/05/create-an-executable-jar-from-maven/

Here's the error:

YPCMC10030:target lbickle$ java -jar reportingapi.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
com/adinfuse/api/Reporting
Caused by: java.lang.ClassNotFoundException: com.adinfuse.api.Reporting
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

So, I changed my pom.xml to this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0";
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd";>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.atti.api</groupId>
    <artifactId>reportingapi</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Mobile Profiling Project -- Reporting API</name>
    <packaging>jar</packaging>
    <dependencies>
      <dependency>
        <groupId>com.adinfuse.api</groupId>
        <artifactId>aipartner_api</artifactId>
        <version>1.0</version>
      </dependency>
    </dependencies>

    <build>
      <finalName>${artifactId}</finalName>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-assembly-plugin</artifactId>
              <version>2.2.1</version>
              <executions>
                <execution>
                  <id>package-jar-with-dependencies></id>
                  <phase>package</phase>
                  <goals>
                    <goal>single</goal>
                  </goals>
                  <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                      <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                      <manifest>
                        <mainClass>com.api.testcall.testcall</mainClass>
                      </manifest>
                    </archive>
                  </configuration>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-dependency-plugin</artifactId>
              <version>2.2</version>
              <executions>
                <execution>
                  <id>copy-dependencies</id>
                  <phase>package</phase>
                  <goals>
                    <goal>copy-dependencies</goal>
                  </goals>
                  <configuration>
                    <includeArtifactIds>aipartner_api</includeArtifactIds>
                  </configuration>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </pluginManagement>
    </build>
</project>


And now I get error instead:

YPCMC10030:api lbickle$ java -jar target/reportingapi.jar
Failed to load Main-Class manifest attribute from
target/reportingapi.jar


The imports look like this:

import com.adinfuse.api.*;
import com.adinfuse.api.cs.Advertisement;
import com.adinfuse.api.cs.ContentPlacement;
import com.adinfuse.api.cs.Creative;
import com.adinfuse.api.rpt.*;
import com.adinfuse.api.org.*;

The offending line is this:

                        Reporting rpt =
AdInfuseAPI.getReporting("intouch.adinfuse.com");

The Reporting class is in com.adinfuse.api.

I've tried googling "maven java jar java.lang.ClassNotFoundError",
"maven java jar java.lang.NoClassDefFoundError" and "maven import
dependency"

I've also tried searching the mailing list archives, but I don't see
anything it suggests to do that I haven't already done.

Any help is appreciated!

Reply via email to