Note that there are some explanatory texts on larger screens.

plurals
  1. POMaven local dependency not resolving sub-dependencies
    primarykey
    data
    text
    <p>I'm having problems resolving sub-dependencies from a third-party package. I'm a bit of a Maven beginner. Basically it goes like this:</p> <pre><code>git clone git://github.com/unidata/thredds.git cd thredds mvn install </code></pre> <p>Everything works great and stuff is installed into <code>~/.m2</code>. Now, I wrote my own code that uses the package that I just installed:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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/xsd/maven-4.0.0.xsd"&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;test&lt;/groupId&gt; &lt;artifactId&gt;test&lt;/artifactId&gt; &lt;packaging&gt;jar&lt;/packaging&gt; &lt;version&gt;0.1&lt;/version&gt; &lt;name&gt;Test Package&lt;/name&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;edu.ucar&lt;/groupId&gt; &lt;artifactId&gt;netcdf&lt;/artifactId&gt; &lt;version&gt;4.3.8-SNAPSHOT&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/project&gt; </code></pre> <p>Ok, this also works great when I run <code>mvn package</code>. The <code>netcdf</code> artifact is found. Now, when I try to run my code, I start down a long <code>ClassNotFoundException</code> path, having to keep adding all of <code>netcdf</code>'s dependencies to my classpath.</p> <p>Am I doing something wrong, or should the <code>thredds</code> package and all its dependencies automatically be picked up?</p> <p><strong>edit:</strong> the thredds package has many sub-modules one of which is netcdf. My code only depends on the netcdf jar.</p> <p><strong>edit:</strong> the snapshot version is installed</p> <pre><code>$ ls -l ~/.m2/repository/edu/ucar/netcdf/4.3.8-SNAPSHOT/ total 4272 -rw-rw-r-- 1 nwatkins nwatkins 700 2012-03-29 23:23 maven-metadata-local.xml -rw-rw-r-- 1 nwatkins nwatkins 182 2012-03-29 23:23 _maven.repositories -rw-rw-r-- 1 nwatkins nwatkins 4357494 2012-03-29 23:23 netcdf-4.3.8-SNAPSHOT.jar -rw-rw-r-- 1 nwatkins nwatkins 7840 2012-03-29 22:28 netcdf-4.3.8-SNAPSHOT.pom </code></pre> <p><strong>edit:</strong> to run the code which is in a single file <code>Test.java</code></p> <pre><code>$ java -cp target/test-0.1.jar Test </code></pre> <p><strong>edit:</strong> first error message</p> <p>$ java -cp target/test-0.1.jar Test</p> <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: ucar/ma2/InvalidRangeException Caused by: java.lang.ClassNotFoundException: ucar.ma2.InvalidRangeException at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) </code></pre> <p><strong>edit:</strong> then I just try to manually add the dependency jar to the class path</p> <pre><code>$ java -cp ../thredds/cdm/target/netcdf-4.3.8-SNAPSHOT.jar:target/test-0.1.jar Test xception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at ucar.nc2.NetcdfFile.&lt;clinit&gt;(NetcdfFile.java:97) at Test.main(Test.java:37) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) ... 2 more </code></pre> <p>The <code>slf4j</code> package is also in <code>~/.m2</code>. I stopped trying to add things to the classpath after this as it seemed like the wrong approach. at java.lang.ClassLoader.loadClass(ClassLoader.java:266)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload