m2e Does Not Detect Any Jars in Local Repository - java

In my Java project, which has a maven 'nature', m2e version 1.0.10020110804 does NOT detect any jars located in my local repo. I can successfully compile/install using maven from the command line, but when I open the project in Eclipse I'm notified of 100+ (cannot be resolved to a type) errors. Does anyone know how to resolve this problem? I've tried updating dependencies and cleaning my project, but neither works. My local repo is set in m2e under 'User Settings'.

M2e needs to be configured to use your local , home repository . In general, one would expect it to do so automatically... But in your case, its using a different home repository.
I feel your pain here - I have seen it use a default repo inside of eclipse in some cases, which can cause problems if you have / need your own local .m2 directory.
I believe that when I first got this problem, I was installing the m2e plugin without having installed first setting maven up as a standalone application. In this case, it might be that the m2e plugin uses a local maven copy/repo .
So the moral of the story is : You need to configure the plugin to "see" and "use" your M2_HOME correctly.
There are some good tips on getting the settings right here : Eclipse m2eclipse getting dependancies from local repository
By editing the m2e plugin settings through the Preferences window, you can ensure that m2e is accessing the right Maven HOME directory, and that will solve this problem.

I recently faced the same problem. The root cause was that I imported my project as a generic project and later added maven and java natures to it. I resolved the issue by closing and removing the project from my workspace and re-importing as a maven project and then syncing it with my local repo. HTH.

did you try refreshing the workspace?
I am having a similar experience, and I've tried all those thing because it wasn't recognizing the Rhino jar in my unit tests. A lot less errors, but still a couple. Had to close the project, close eclipse, run mvn clean compile, open eclipse, open the project.

Related

Maven is not putting generated jars into the local repository

I recently did a pull on the local repository. I ran into some missing dependencies, nothing unusual there. I ran mvn clean -U install on the projects concerned, no problem, everything looks good in maven on the command line. I refresh my projects in eclipse, no joy, eclipse says I'm missing dependencies.
After a bit of messing around back and forth with no success, I looked in the local repository itself. Sure enough, many of the required dependencies are missing; they are however, located in the target folder.
I've tried building with install a number of times, but the jars aren't placed in the local repository, so my other projects can't find them.
Sometimes a later version of the library is there, but not an earlier on, for example 6.0.28-SNAPSHOT is there but not 6.0.27-SNAPSHOT.
I have checked my settings in eclipse and maven:
Eclipse is using the correct version of maven
They both have the same local repository
They are both using the same settings.xml file
They are both using the same version of Java
Since all the jars I checked appear to be in the target folder, I think the issue is with maven not installing them into the local repository. What could cause this issue, and how can i resolve it?
Also, although I don't think this is relevant myself, as everything has been working fine before, my target directory is a completely separate folder, and is not a sub-folder of each project. It's located in C:\Maven\target.
I forgot to run:
mvn eclipse:eclipse
After pulling the updates from git.

How to find and missing artifacts in a maven project using eclipse as editor?

I am working on a Maven project and I am using eclipse as an editor. I clone a project from GIT and then create a git repository in eclipse , import it and then create a maven project. After i finished the project of setup i got a lot of errors and this is due to pom.xml file and I am missing about 300 artifacts.I know want to know how can i find and add those artifacts in my project. I have seen different answers for that and one of the answers is to upload maven project. I did it but still not working , I am still missing the artifacts.
I really need some help here since i want to start working on this project as soon as possible.
Maven pulls all the dependencies either from maven repository or from local repository automatically (typically C:/Users/user1/.m2 on windows). if there are lot of dependencies, eclipse takes a while to download them all.
check if you see building workspace at the right bottom corner of eclipse. you can press Alt+F5 to refresh the project and then try command mvn clean install from your root folder (where your pom.xml is placed)
Sometimes, jars are not available on maven repository such as sqljdbc. in that case you will have to manually install them to your local repo using below command if you have the .jar file
mvn install:install-file -Dfile=<path-to-file>/stax-1.0.jar
-DgroupId=stax -DartifactId=stax -Dversion=1.0 -Dpackaging=jar
or a quick and dirty approach would be copy the .m2/repository folder from previous machine if project was working good on that machine.

Eclipse not seeing my updated classes

explored all solutions to this, including clearing out metadata folder and making sure the compiler matches the project version. I also have build automatically checked.
When I save my files in eclipse they update in the filesystem, but when I attempt to run my maven project and deploy it to the JBoss server it runs and old version.
I've even put in compiler errors on purpose and it doesn't bother it at all.
Please try building your project with a clean command
mvn clean install
and also refresh your workspace in eclispe. Might help!
do maven clean install through eclipse maven plugin, to avoid different code base confusion, it seems you are editing some different code base on eclipse which is different when you build through maven.
recheck the path for both the cases.
At the end copy the jar from the eclipse project itself after refresh the project on eclipse.
I faced the same issue, due to eclipse was not loading the new jar, caching the old one. it's required to refresh the project on eclipse before taking the build jar.

How to download all possible maven dependencies so they are local

I work behind a very massive firewall that likes to hiccup on random connections, which makes all work with remote repositories a living nightmare for me!
I am looking to work with a project from Git (this one https://github.com/mrniko/netty-socketio) which heavily utilizes maven for downloading dependencies.
What I would like to do is on another terminal (such as http://cloud9.io or something) download all the maven dependencies so that the entire project can be run standalone.
I have already tried mvn clean install and then zipping up the source folder, but its actually not enough! I still get ClassNotFound related errors when I try to run the project locally in eclipse. And for the record, I did add the compiled *.class files in the build properties, so Eclipse knows where they are. It seems like there are some random classes that get generated dynamically which still aren't present (such as log4j -- and I really don't want to hunt each one down individually)
I am wondering if there is a fully thorough way to download all possible dependencies from maven and then either run a project 100% standalone, or create a local maven server from it?
I am running Java 7 on Eclipse Luna and I do have Maven installed on my windows 7 machine (though again it barely works on remote repositories). I also have a Cloud9 instance which I could use to run Maven commands, then zip up the results for local download.
When you execute mvn clean install, maven downloads all dependencies of currently built project to your local maven repository. This is usually located in
%USERPROFILE%\.m2\repository
When you build your project, maven uses that path, to lookup required dependencies.
If you want do download them all, you can try using mvn dependency:copy-dependencies. Then, you'll find all project dependencies intarget/dependencies directory of your project. This also includes transitive dependencies.
To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin. Using that plugin, you can generate eclipse .project and .classpath files, using mvn eclipse:eclipse command. This will populate eclipse files with required dependencies from maven. You should then import the project to eclipse using Import existing projects into workspace, instead of Import existing maven projects.
maven-eclipse-plugin will add all those jars relative to a folder specified by M2_REPO variable. Just make sure you edit this variable inside eclipse project properties, and you should be set.
I've had to deal with similar issues. I would find that due to changes in firewall policies, occasionally all the .jar files in my project had been updated to be a 1K file that, when opened within notepad++ contained a message from the firewall saying that the download had been blocked.
I recommend looking into Nexus for your local repository management, it means your local projects don't have to go past your firewalls to check for maven updates.
http://www.andrejkoelewijn.com/blog/2010/03/09/getting-started-with-nexus-maven-repository-manager/
Use dependency plugin go-offline task.

Eclipse IDE behaves weirdly

I am getting a class not found exception for my Login Controller when I try to login to my application(It is a spring MVC Application). Before running the maven clean command the Application was running perfectly, I used maven clean and then again done a build using maven package command, suddenly it stopped working. I tried restarting the TomCat, re-deployed the application on TomCat, restarted the Eclipse IDE but nothing has worked so far.
Why this happens and what is the possible solution to this ??
Are you trying to run your project under Eclipse?
And does it generate source files?
If these are both true, you probably need to update the project config (select project or pom, right-click, Maven..Update..Project Configuration and Maven..Update..Project Dependencies).
The problem is that when Maven does a clean, it gets rid of the generated directories, which Eclipse observes and removes from your Build Path. But then when Maven rebuilds the directories, Eclipse doesn't notice it - you have to give it a hint.
Check your project for build errors and build path errors.
Make sure you've defined an M2_REPO classpath variable in Eclipse (Preferences - Java - Build Path - Classpath Variables).
If you're using the m2eclipe plugin, right-click your project and click on Maven - Update project configuration. That will configure an Eclipse build path for your project based on your pom dependencies.
If you're not using m2eclipse, execute mvn eclipse:clean eclipse:eclipse in your project folder. Then refresh your project in Eclipse.
What you haven't said is that you've checked and the missing class is in fact present.
A quick way to check is in the code editor SHIFT+CTRL+T and type the name of the missing class. Eclipse should not only show you the class if it exists, on highlighting the class, Eclipse should tell you which jar it is in.
Based on the info you have provided, I would say some dependecy in your POM has been removed by mistake or you need a newer version of some jar. If you find the class is not present, then you can figure out which jar you need by googling something like Maven 2 MyMissingClass jar that usually works for me.
Delete the .metadata folder in your eclipse workspace and then again open the workspace and import the required project.
This will solve your problem.
In .metadata folder it maintains the temporary copy of the project.
what worked in my case was simply removing the project from work space and importing it back again.
But I still don't know why it worked Vs why other things mentioned did not work (I tried updating dependencies in fact I removed all the dependencies from pom.xml and added everything again)

Categories