I have a project which has dependency A.
Project is packing into WAR and dependency A - into jar.
And another dependency B, which also depends on A.
I want to pack project and when project B is packing it must rebuild its dependency A instead of getting compiled dependency.
Please help, how can i achieve this
Always perform a clean when doing an install, ie mvn clean install. This will make sure that all modules in the project are rebuilt, packaged, and installed in the local .m2 repository for inclusion by parent dependencies and projects.
What you may want is a multi-module project containing your three projects (WAR, A and B). Then you can run mvn package on the multi-module project and it will build and package all of the latest project code against each other without having to run mvn install to update the dependencies in your local repository first.
Related
I have a maven project in Eclipse and I added some local jar files to the buildpath. If I do not add any dependency to the pom.xml file I am able to execute maven install. Then, if I add those dependencies to the pom the command maven install continues working as well. Now in this situation if I run maven clean then maven install fails. Why?
I also tried to run Maven -> Update Project but the result is the same. What is the problem?
If you are using non maven dependencies then it will fail to build eg from CLI and in your case in Elipse after cleaning the project as well. In order to make it work you have to installl tha JAR you are using as Maven artifact and the ninclude it in POM dependencies like every other library.
Here you have info on how to install 3rd party JARs to local repo
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
I got the same problem and resolved by adding the 3rd party in the pom.xml manually
I have 2 Java projects where project2 depends on project1's jar. Bot are Maven projects. At the moment this is what I do to create a jar from project2:
c:\eclipse\workspace\project1> mvn install
c:\eclipse\workspace\project2> mvn package
Could I somehow "include" the mvn install command inside projects2's pom.xml so that only the last command would be enough to create the jar?
You have described a basic use case of Maven Reactor (i.e. Maven's fancy name for multi-project/module build).
In this respect, you'd have your two projects alongside a parent pom (which would be the predecessor of both project1 and project2).
Within a Maven multi-module build, modules are allowed to depend one on another; so in your case you'd specify project1 as a dependency of project2's just like you do with any other dependency. Then, when you run package (on the parent pom) Maven will see the dependency, build project1 first and then use the built jar for project2.
I have added dependencies in pom.xml and immediately the corresponding jars started to show up in maven dependencies section of dynamic web project.
I just want to know that I have not done mvn install in cmd so how did they get saved in maven repository.
Another query I have, is that since jars are availble in maven dependencies folder of dynamic wep project, so my project runs successfully or not as depndencies are already satisfied without doing mvn install.
When you list a <dependency> in your project's POM, M2Eclipse (Eclipse's plugin in this case) will trigger Maven to resolve that declared dependency...meaning Maven will check your local repo first for that dependency, and if it's not found there it will pull it down from the next highest repo you have configured (possibly an agency-level repo, or Maven's default public repo on the web).
No mvn install is required, as the purpose of that would be to install your current project's packaged artifact into your local repo, rather than install any dependency.
Hope this helps to clarify why an install is not used to copy dependencies into your local repo.
I have this file structure in my project:
Project
|--pom.xml
|--Sub-Module1
|----pom.xml
|--Sub-Module2
|----pom.xml
|--Sub-Module3
|----pom.xml
I want to create a JAR-file from Sub-Module2 (SM from now on). However, that module depends on SM1 and SM3. What I want to do is simply run "mvn package" from SM2 and it would run "mvn install" for SM1 and SM3. I already have SM1 and SM3 added to SM2's pom.xml as dependencies, so they get packaged in the JAR-file, but each time I start from fresh, I have to separately run "mvn install" in SM1 and SM3.
Is there a plugin for that or can I install other modules from SM2 in other means?
Invoke mvn package on project level insteed of module level. This way Maven will build all three modules, and include required dependencies in generated jar as expected.
I assume that pom.xml in Project directory, is a parent pom for submodules.
EDIT: After quick check on Maven docs, you could use mvn --also-make and this should build dependant modules as well.
I have a maven Java project (Project A) which depends on a second project (Project B). Right now, Project A downloads Project B from the repository so it can build. However, I am also working on Project B. How can I get Maven to use the version of Project B which is on my machine and ignore the version in the repository?
If both projects have the same version (and that's a SNAPSHOT version), build Project B locally (mvn clean install) and Project A will use that version.
You can do mvn install on B so it will be installed into local repo and used from there by A. You can aggregate these two projects as modules of multi-module project so they can be build within same build reactor and see each other. You can also use IDE plugin (like m2e for Eclipse) that supports what you're saying about if you have both project in the same workspace.
The last option is probably most comfortable.