I have a local jar being imported into my project through Maven. When I update the jar in my other project, then do maven package, it is not getting updated in the main project.
I have tried everything, cleaning it, forcing dependencies, relaunching IntelliJ, deleting m2 repository, everything. Nothing is working for me.
Any help would be appreciated.
Heres the code from the main project's pom.
<dependency>
<groupId>com.example</groupId>
<artifactId>manager</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
EDIT: SOLUTION!
I accidentally had another import of the same project in my dependencies, this time not from maven. Removed that and everything was fixed.
Thanks for everybody's help!
Your changes needs to be installed into local repository with mvn install to be visible in other project. But you can import second project as module into Intellij. After this two projects can work without install (internal syncing).
Documentation: Creating and importing Maven projects
Related
I am using my local jar project in another project through a maven dependency.
<dependency>
<groupId>some.groupid</groupId>
<artifactId>some.artifactid</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
The jar is getting liked to the project but when I try to access any class from it, say com.companyname.app.Abc; it is imported as com.companyname.app.Abc and not just Abc with import statement separate.
I even tried putting import statement separately, but that did not work.
The IDE I am using is IntelliJ.
It was pom related issue where few of the plugins were causing the issue.
I tried creating project from scratch and got the difference.
I am setting up a project in eclipse . This projects builds successfully through command line(all mvn commands like mvn package, mvn compile, mvn clean install) work perfectly fine. While setting up this project on STS or Eclipse . I see some of the dependencies are not getting downloaded even though they are present in pom.xml. However, searching them in the maven repository and downloading the jar to my local computer and then adding them to build path makes it work on Eclipse.
Is there anything that we need to do to eclipse to make sure it downloads all the dependencies from the repository.
My POM:
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server-compat410</artifactId>
<version>4.1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server-compat420</artifactId>
<version>4.2.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server</artifactId>
</exclusion>
</exclusions>
</dependency>
Both these artifacts were not downloaded for eclipse and there jars found http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat410/4.1.0 and http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat420/4.2.0 were not present in the folder for MavenDependencies and were subsequently giving errors in Eclipse.
However manually adding them to the build path created a new folder (Reference Library) and resolved the Eclipse Errors . Why did Eclipse not download and import these dependencies by themselves from the maven repository ?? Is it a bug in Eclipse or some problem from my side . Please help.
I got the same problem and this is how i solved. :
Right click your project, choose Run As -> Maven install.
Observe the output console to see the installation progress. After
the installation is finished, you can continue to the next step.
Right click your Spring MVC project, choose Maven -> Update Project.
Choose your project and click OK. Wait until update process is
finished.
The error still yet, then do Project->Clean and then be sure you have selected our project directory and then do the follow Project->Build.
Solution 1:
Set correct proxy:
<proxy>
<id>optional</id>
<active>false</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>172.27.171.91</host>
<port>8080</port>
</proxy>
Solution2 :
just delete
lastupdated extension files from folder
and try updating maven.
[Most of the times this solution will work]
Sometimes there is an error downloading a dependency - eg. some files are downloaded but the actual JAR is missing from the local Maven repository.
In this case I had to delete the whole folder of the problematic dependency in the local maven repository. Only then did Maven update work (Right-click on the project and select Project > Maven > Update Project.... )
In my case, I had unchecked Build automatically. Checking it again started downloading the jars.
I have come across the same issue recently.
First of all you have to configure proxy settings in settings.xml in your maven repository.
If you are using eclipse/STS then please do verify following.
Window -> Preferences -> Maven -> User Settings -> update user settings by pointing your settings.xml
Now it's set to update the maven project. It worked for me.
I was facing similar sort of issue. I tried deleting folders inside .m2 and again building maven project.
I could download all dependency except one dependency which we have created by ourselves and published on Nexus.
Then I changed by java pointing from JRE to JDK which solved my problem
The following worked for me.
Just right-click on Project -> Maven -> Update Project... such as it is shown here.
I had faced a similar issue and following the below steps helped me fix it.
Delete the last modified jar from respective folders.
Select the project
Right Click -> Maven
Update project..
It will download all the missing Jars.
Try to move your dependencies from "type" tag to "scope" tag like below
or
<dependency>
<groupId>net.xyz.xyz</groupId>
<artifactId>xyz-xyz</artifactId>
<version>x.y.z</version>
<type>pom</type>
</dependency>
or
<dependency>
<groupId>net.xyz.xyz</groupId>
<artifactId>xyz-xyz</artifactId>
<version>x.y.z</version>
<scope>test</scope>
</dependency>
then further Maven > Update Project
For me I changed the packaging from pom to jar, and then the dependency got downloaded.
so I changed from <packaging>pom</packaging> to <packaging>jar</packaging>
Make sure you're defining the dependency as close as possible to the leaf of the project tree where it is needed. Otherwise, Maven might ignore it.
For example, if you have a parent project that references projects A and B and the dependency is with respect to project A, then defining the dependency in the parent's pom.xml might get ignored by Maven. So, define it in project A's pom.xml.
Parent Project's pom.xml
Sub-project A's pom.xml <<< define the dependency where it is needed
Sub-project B's pom.xml
I hope this helps someone as it took me 2 days to realize. I re-imported the project multiple times and followed every possible step I've seen online and in the end I had added a small piece of xml code within the pom.xml. Even though it wasn't erroring or even showing a warning it was preventing maven from reading the lifecycle-mappings.
Click into your pom.xml and go to the dependencies tab on the bottom left, if you see an error there it's likely your pom.xml is corrupted in some way and maven will never attempt to download the dependencies even though you won't get any real error. I had looked back at a previous PR and noticed where/what I added and removed it and was able to get maven to work.
I've got two Maven projects, A, that generates a jar, and B, that generates a war, in my Eclipse Workspace. A is a dependency of B, and, as such, is in B's POM.
My problem is that A is not being deployed to a .jar in /lib/ when I run a Tomcat server with B.
It seems strange A appears in B's Maven dependencies as a folder, not as jar. Is this anomalous in some manner? If so, how can I fix it?
If this is not the problem, perhaps it's with Tomcat. Do I need to configure it somehow to accommodate this dependency schema (in which the dependency appears as a folder)?
Thanks!
--
EDIT: After manually exporting the .war file of B, I've discovered that A is being put in /lib/ as an empty .ear file.
Here is a screenshot of the dependency been displayed as a folder:
Here are the relevant parts of the POM of A:
<groupId>br.com.reglare</groupId>
<artifactId>rule-model</artifactId>
<packaging>jar</packaging>
<version>1.8</version>
And B:
<dependency>
<groupId>br.com.reglare</groupId>
<artifactId>rule-model</artifactId>
<version>1.8</version>
</dependency>
#urir: Yes, it fails to find a class defined in A: http://990fca173882239e.paste.se/
The dependency should be defined in your pom in this format:
<dependency>
<groupId>xmlbeans</groupId>
<artifactId>xmlpublic</artifactId>
<version>2.2.0</version>
</dependency>
Also to view the dependecy tree use the 'dependency:tree' directive as follows:
mvn clean compile dependency:tree
If the dependecy is still not in the WEB-INF/lib folder of the war, then run the compile with the debugging flag and look for errors:
mvn -X clean compile
Assuming you are using m2e in eclipse to manage the webapp, you need to install m2e-wtp. You should also be able to find it within eclipse in the marketplace. It takes care of making sure that when you launch a maven web project through eclipse it gets all the dependencies in the right place. Once you install the plugin, you may want to delete your project and import it again as an "existing maven project" then the plugin will get it all setup correctly. Applying it after-the-fact has been iffy for me.
I'm having something quite peculiar here, my build is successful in maven when I type "mvn clean install" however once imported into Eclipse it's showing errors.
See for yourself:
I guess exluding quartz from the `pom.xml solved the problem but I'd like to know why.
PS: Here is the pom.xml in case you want to see it:
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nantes.mpclient</groupId>
<artifactId>MyClient</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyClient</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.nantes.mp</groupId>
<artifactId>MyEjb</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>5.1.0.GA</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
###EDIT
As you can see quartz is here:
Updating maven project after importing it has fixed this issue for me:
Right click on the project --> Maven --> Update project.
Sometimes I get these types of issues as well.
Generally, what worked best for me with Eclipse & Maven:
Use the latest m2e Eclipse plugin
Use Maven 3
Make sure m2e uses the same Maven version as the one you're using on the command line (not the internal one)
Import projects as Maven projects to generate the Eclipse project files
The other upvoted answers did not work for me using these versions:
Eclipse Neon
Maven 3
m2e 1.7
This is what I had to do:
Delete the Eclipse project from Eclipse interface (do not delete project contents on disk)
Go to the project's root directory in a file explorer or terminal
Delete these files: .classpath, .project, and .settings directory
Back to Eclipse, File -> Import... -> Maven -> Existing Maven projects
If you don't see any error in Eclipse project but it keeps showing the red icon on your project name. Try mvn eclipse:eclipse.
Then select all projects in Eclipse, Right click > Maven > Update projects
Hope it helps.
You should try mvn eclipse:eclipse
And then make sure the M2_REPO variable is point to your local repository.
sometimes maven update nor all above works.
so check which import statement gives you error, then go particular lib file which is usually in c:user/ur-PC-NAME/.m2 get into package delete that .jar file.
then in eclipse, right click on project > maven > update maven.
Sometimes the m2e "maintained" eclipse project is out-of-sync with the actual project in POM (There are lots of reason for that). Assume you have using m2e 0.8 or later, right click on the project, under Maven, there are two entries that are usually useful. They are Update Dependencies and Update Project Configuration
Have a try on them, wait a while after u clicked that for eclipse to update the project and build. Normally it solves similar problems.
That often happens when the m2eclipse hasn't updated the build path to correspond to what a modified POM file says. There's an entry in the Maven context menu to update the Configuration.
In my case,
I just deleted project from Eclipse (not ticked checkbox to delete
from project location).
Opened project as "Existing Maven Project" again.
and it solved my issue.
I found that my project was using a project specific Java Compiler setting set to Java 1.5. Furthermore, the project facets were still referencing Java 1.5 when Maven, m2e, Eclipse general Java Compiler settings were all set to Java 1.8.
In my case there were also problems with Java build path like the following:
"Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment." Fixing this resolved compilation errors.
You've a library (quartz-1.5.2.jar) that's reference to your m2 local repository which doesn't exist if you just remove the quartz from your build path and update your dependencies internally(in eclipse) that would solve the problem
Try to use different/older version of JRE. In my case switching back to JRE7 from JRE8 eliminated the problem.
Delete and Re-Import the project in eclipse (without deleting files of course). Unlike other answers I have not looked into why this happens but it works. poof - compilations errors be-gone
It may help: After upgrading eclipse or changing it or something like, old eclipse specific files (.classpath, .project, and .settings) may not be compatible to the new version of eclipse. So you may have to re generate this eclipse specific files using Maven. So try this in your eclipse project root
mvn eclipse:eclipse
In my case, eclipse starts to show all errors after I changed some versions of dependencies in pom.xml, however the command line mvn clean install build successfully
I deleted folders of the dependencies I changed manually from the .m2 repositories (in my case everything under org.apache.beam), because I also has corrupted dependency issues.
mvn clean build the project, this downloaded the dependencies again
right click project: maven -> update project
delete the project from eclipse (but not from disk) and reimport (this actually left me with 1 error still, then i delete and reimported again)
Go to Eclipse> Project (Menu) > Clean... > Select project to clean
This also removes invalid errors from Eclipse.
For me Right click on the project --> Maven --> Update project with the "Force Update of Snapshots/Releases" checkmarked worked.
Some times, eclipse's validation causing these errors.
You can disable them by going to Menu>window>preferences>validation and uncheck suspend all validators or disable them one by one for builds.
E.G, every time You build the project eclipse does not validate your files and does not show up those errors.
This worked for me
Delete the Eclipse project from Eclipse interface (do not delete
project contents on disk)
Go to the project's root directory in a
file explorer or terminal
Delete these files: .classpath, .project,
and .settings directory
Back to Eclipse, File -> Import... -> Maven
-> Existing Maven projects
Got the same problem, I deleted the project from my workspace (not on disk), opened the project folder and deleted the files .project, .classpath and the folder named .settings.
Now goto eclipse again, import the same project again and viola my error is gone!
I'm merging two projects into one(mergin project1 into project2). Now I'm going to copy all dependencies from project1 pom into project2 pom, like :
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.6</version>
</dependency>
And some others. The build is successful the thing in eclipse annoys me so much like when hovering over import org.apache.commons.configuration.ConfigurationException:
The import org.apache.commons.configuration cannot be resolved
But the build still succeds, what can I do to get rid of these?
If you use m2eclipse, you need to click Maven -> Update Dependencies.
Otherwise I guess you need to regenerate the Eclipse project with mvn eclipse:eclipse.
Try doing 'mvn eclipse:clean eclipse:eclipse'. That will force maven to delete all of the old eclipse configurations for your project and rebuild them from scratch.
Maybe try to edit POM by inserting whitespace and saving it. It should trigger rebuilding of the project. There is also a "Refresh Dependencies" option in m2eclipse plugin.
I had similiar problems when I used Eclipse integrated with Maven and the 1st technique usually helped.
Make sure a build is done successfully and ensure that on your Package Explorer the org.apache.commons jar is found under the Maven Dependencies section (given you have m2eclipse plugin installed in your eclipse)
What version of Eclipse, mvn and m2eclipse? Might want to double-check those.
You shouldn't need to do mvn eclipse:eclipse anymore - that's obsolete. You can try deleting your Eclipse project files and reopening the project (settings, project, classpath).