I have two projects both use maven. The project A is a utility library, and I use mvn install to my local maven repo. The project B is a web app, it has a dependency on A library.
when I run B project use mvn jetty:run it don't load a.jar in my local maven repository, but if I execute mvn package to package my web app, the a.jar will in its WEB-INF/lib.
I tried under maven 3.1 and maven 3.2, both have the problem.
I'm new to Maven 3 and have been using Maven 2 for many years, why can't this solution work as before?
Edit:
From the pom.xml:
<dependency>
<groupId>me.donnior</groupId>
<artifactId>rtl</artifactId>
<version>0.3</version>
</dependency>
Edit:
My problem is that my own installed A.jar can't be found when run mvn jetty:run, but others third-party jars that downloaded from network can be found in class path.
Updated:
I figure it out is a jetty plugin's dependency problem, can be closed now.
mvn jetty:run dont perform packaging Lifecycle.
It enables project without requiring that it is packaged. In this mode every component of the project is used from its origin location.
try to use jetty:deploy-warinstead as it perform mvn package lifecycle phase as well.
Related
I have created a Java project with maven that I want to implement in other maven project.
The child project is not a spring project, is a Java project created from scratch migrated to maven to manage the dependencies.
I can generate the jar with mvn install. So far so good.
Then I try to implement this jar to other project that is built with maven and spring.
For that I added that jar to my local maven repo with the following command:
mvn install:install-file -Dfile=/Users/.../target/app-0.0.1-SNAPSHOT.jar -DgroupId=com.mycompany.childapp -DartifactId=childapp -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
Then I am able to see that in the repo folder in .m2, the jar file is correct.
And this in the parent project pom.xml:
<dependency>
<groupId>com.mycompany.childapp</groupId>
<artifactId>childapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
And also, in the plugin section:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
At least for eclipse everything is good, as I can develop and implement the classes inside the library without any issue. I can build the parent app with mvn clean package But when I run the app and try to execute the section of the code that uses the child library I get ClassNotFoundException for the classes that are in the child project.
In the parent project, in the libraries imported by maven I see that my library has a folder icon instead of the one the other have.
How could this be fixed?
mvn clean package creates jar for parent project but it does not include child jar.
You should use SpringBoot
mvn bootRun to run your project locally
mvn bootJar to build fat jar which will include all required dependencies.
To run this fat jar call java -jar parent.jar
Finally it was that the library was like... 'corrupted'.. or something like that.. It was a Java Project (created with eclipse wizard) than then I converted to maven (with eclipse wizard).
I started a new project as maven project from the beggining and everything was working at the first attempt....
So I just have to run mvn clean install to generate the jar and installed in the .m2 repo
Then in the main app pom.xml I have to declare as any other dependency:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>mylibrary</artifactId>
<version>0.0.1</version>
</dependency>
As per the comments, you want to create a project with maven which will create a jar file. That jar file will be used in another project. If my understanding is correct. You have to do the followings.
Create a simple maven project with simple type archetype.
Run the pom.xml with the command like mvn clean install or mvn clean package.
Use the jar file from the simple project upload into your nexus/artifactory repository and use the maven definition in another maven project.
If you do not have nexus or artifactory, you can use the jar file locally in another maven project.
To add a jar file locally in another project, you have to add the following dependency structure in pom.xml.
<dependency>
<groupId>your group id</groupId>
<artifactId>name of the application</artifactId>
<version>some version</version>
<scope>system</scope>
<systemPath>your location/jar-file-name.jar</systemPath>
</dependency>
Hope it answers your question.
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'm working on an API that depends on a small library I created in my project. In IntelliJ IDEA, it looks like :
PROJECT : myProject
MODULE : mySimpleAPI (maven project + spring boot application)
MODULE : mySmallLib (maven project)
I just added mySmallLib in mySpringAPI's dependencies.
But when I execute the spring-boot:run command, it tried to download the dependency from spring repositories. I tried in offline mode, but it also didn't work. How can I tell to maven that the dependency is already in the project and it doesn't need to download it ?
run mvn clean install on "mySmallLib" project first. This will install the jar in your local maven repo. Then you can perform mvn spring-boot:run on "mySimpleAPI" project.
Seems your code/library is not updating automatically. So you will need to update them manually.
Go to each sub module of your project and open pom.xml. now right click on the file and click on clean install.
Try running your application again, and it should work. Let me know if it doesn't.
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 faced with foggy issue.
I am novice in project. I use Eclipse. all my colleagues use IDEA. I have checkout project from svn.
I performed corresponding maven tasks for building and deploying project. all works good.
But my Eclipse shows me problem.
in code:
sceneService.uploadFile(...);
eclipse shows that sceneService hasn't uploadFile method
I began researching. I show this class on PC of my colleague. But there aren't this issue. I noticed that we use different version of jar file of sceneService class.
We use same revision of the pom.xml.
dependency for jar in my pom.xml(for my module):
<dependency>
<groupId>com.day.cq.dam</groupId>
<artifactId>cq-dam-scene7</artifactId>
<scope>provided</scope>
</dependency>
when I type alt+shift+w I see that jar contains sceneService class takes from another module.
I think there is some issue in downloading the correct jar by Maven. your local repository may contain an earlier version of the jar.
Try these commands by going to the root folder of your project from command prompt.
mvn eclipse:clean
mvn eclipse:eclipse
mvn install
if still the problem persists try deleting your local .m2 repository and again rebuilding the project
I think my earlier comments about the "provided" scope are a red herring. The actual problem is likely due to conflicting versions.
By default, Eclipse enables workspace resolution of artifacts. This means it will find artifacts to use (i.e. cq-dam-scene7) from other projects in your workspace. It will also find them in the .m2 repository as well; I'm not sure which takes precedence.
Possible routes towards a solution include:
Specify a version for your artifact. This will ensure you use the correct JAR, even if it has to be found in the local .m2 repository.
<dependency>
<groupId>com.day.cq.dam</groupId>
<artifactId>cq-dam-scene7</artifactId>
<version>1.2.3</version>
<scope>provided</scope>
</dependency>
Ensure your local cq-dam-scene7 project contains the correct code - i.e. a version with the uploadFile() method defined.
I am facing a similar issue, I have two Maven projects in workspace. Main Project is using output JAR of a Helper project as an artifact.
Now the problem is that Main project is trying to Reference JUnit library of Helper project (which has older version 4.10) instead of it's own JUnit library having version 4.12. Because of this in-correct referencing I get build errors in main project.
Only work around which I found is to close the Helper project and have only Main project open in workspace.
Possibly this is an Eclipse bug.
Delete the repository folder in .m2 (in your user dir) and let maven rebuild it in next build cycle.
It will ensure no old jars are cached locally