Reputation: 1861
Say I have a project A that has some dependencies which it requires to function. Then I use this A in a B project. B only depends on A and transitively depends on every A dependency, but that is not mentioned in B's pom. B's only defined dependency in pom is A.
A is packaged in a jar without the dependencies, so that it is leightweight.
B project works well on my pc. I have all the dependencies in my local repository. B project only has A in pom.
There is another computer which is absolutely clean, has NetBeans and has A's jar and B project. B does not run well. It requires all A dependencies defined in it's pom. The whole dependency tree. If dependencies are not defined, it throws NoClassDefFoundException most of the time. It requires all transitive dependencies defined in A's pom to run. On my pc, only A is required to be defined in B and transitive dependencies are downloaded, if they are missing in local repository.
What is happening?
Upvotes: 0
Views: 2029
Reputation: 5913
As described in the previous answers, ProjectB builds fine on your machine as ProjectA and the associated metadata is available in your local repository.
Why it's failing on your second PC?
Maven identifies dependencies and transitive dependencies from the pom files. When you define projecta as a dependency in projectb, it will look for it in the local/remote repositories. It will also look for projecta's pom file and figure out any transitive dependencies and the cycle goes on. In your case you don't have projecta's jar file /pom file or associated metadata in the local repository of the second computer.You also haven't defined any remote repository from where Maven can download the projecta's pom/jar and associated meta data.So there is no way by which Maven can download/copy projecta's pom/jar and identify what the transitive dependencies are
Below are few solution which will help you resolve this problem. Let's call your 'another computer' as PC_B
Solution 1. Build ProjectA on your 'another' computer and then build ProjectB
Solution 2. If you can't build ProjectA on PC_B, then you have to make it available in your local/remote repository
a. Make it available in the local maven repository of PC_B using this command
mvn install:install-file -Dfile=projecta-1.0.jar -DpomFile=projecta-pom.xml
(you will have to copy the jar and ProjectA's pom file over to PC_B)
Once you do this, ProjectA and the associated metadata will be added to the local maven repository on PC_B and hence you should be able to build ProjectB
OR
b. Create a common artifact repository to store your artifacts.There are many opensource repository managers like archiva, nexus etc which can help you with this.You can then configure this repository as one of the remote repositories in your maven pom/settings files.
You can use mvn deploy
to deploy artifacts to this remote repository(after doing the necessary configuration). So you can deploy ProjectA to the remote repository, so that when ProjectB is built on PC_B, it can get the required artifacts from the newly configured remote repository.
Upvotes: 2
Reputation: 458
Your PC has all A's dependencies, so they are not downloaded from some Maven (central) repository.
On the other computer, A's dependencies are not satisfied. Are you able to build A & B on this computer as well as on yours? Probably not. Or do you just want to run B on this computer? How is it packaged? Does the NetBeans on the other computer know how to connect to the Maven (central) repository? Do you use any?
Upvotes: 0
Reputation: 771
Project A is deployed to your local repository, so it works locally when you use project A inside project B. After you developed project A you released the project to your local repo. To fix this problem you can e.g. deploy the project A to some repositories available on-line and then use this repository or you can pack project A to jar file with all the dependencies and include in the project B pom file.
Upvotes: 0