maven resolves dependecy but cannot find package/classes in it

20,418

Solution 1

Well, the actual reason was that the target computer had the restricted access to the internet, so the restricted access to the maven repos. With some black magic it did not fail with some kind of 'cannot download artifact' (maybe because of manual install of some jar files). So we got the server with normal access, set it up as a mirror, configured our maven to use the mirror and that solved the problem. Thanks @Samuel for participating in my problem, but as I can see that it was not possible to determine the problem from the problem description.

Solution 2

I can see two things to try to solve it out.

First, if you go in your local .m2 repo, you will see if there are other versions of the lib (however, sometimes different versions can have a different name, and therefor be stored in a different folder, which does not help)

You can also check what is the ACTUAL dependency used, in your IDE, or in command line (mvn dependency:tree). You might have to exclude some transitive dependency to remain consistent. I use the Eclipse plugin for that.

Finally, when you are sure of the dependency you use, you can open the jar and see if what you expect to be there is present.

Solution 3

I also had the same problem. In my case all classes in the module were in test package(it was Selenium project) and dependency was set to compile. I ended up moving some classes to main package.

Share:
20,418
Alex Stybaev
Author by

Alex Stybaev

Java developer.

Updated on February 23, 2020

Comments

  • Alex Stybaev
    Alex Stybaev over 4 years

    In custom geotools platform compilation (in fact OSGi-based) one of the modules compiles properly when I try to build it separetly. But when I build the whole project - it fails on compile stage with reason that it cannot find certain packages/classes. Howerver the dependincy is resolved fine.

    here is the dependency from module's pom.xml:

    <dependency>
       <groupId>org.picocontainer</groupId>
       <artifactId>com.springsource.org.picocontainer</artifactId>
       <version>1.2.0</version>
    </dependency>
    

    the part of maven's build error:

    ...\geotools-osgi\modules\extension\xsd\xsd-core\src\main\java\org\geotools\xs\bindings\XSGroupBinding.java:[19,24] package org.picocon tainer does not exist

    ...\geotools-osgi\modules\extension\xsd\xsd-core\src\main\java\org\geotools\xml\AbstractComplexBinding.java:[20,24] package org.picocon tainer does not exist

    ...\geotools-osgi\modules\extension\xsd\xsd-core\src\main\java\org\geotools\xml\ComplexBinding.java:[21,24] package org.picocontainer does not exist

    if I change the pom.xml dependecy - it fails with some kind of "cannot resolve bundle".

    The project is really big and the number of bundles and child/parent poms. So I can't post all of them here. So my question is: what is the possible reason for this kind of trouble? Could it be a dependency conflict between parent/child?

  • Alex Stybaev
    Alex Stybaev about 12 years
    Thanks for the quick reply. As you suggested I made a dependincy check mvn dependency:tree and it showed nothing wrong - BUILD SUCESSFUL. Thec search in folder .m2/repository by the keyword picocontainer shows only one .jar - just exactly the one I need and it is not empty - it contains all of the necessary packages and classes I need.
  • Samuel EUSTACHI
    Samuel EUSTACHI about 12 years
    Does your IDE succesfully compile your code ? Which IDE do you use ?