I am just starting out with Maven. Is there any way to get maven dependencies to be added to the Eclipse project's build path? As of right now, my project is full of red x's due to Eclipse not being able to include some external class from one of these dependencies.
First you need to setup you M2_REPO variable. This is a class path variable that tells eclipse where your designated maven repository is located.
You can setup M2_REPO by running the following command in your workspace.
mvn -Declipse.workspace="replace with your Eclipse Workspace" eclipse:configure-workspace
Next make sure that your project has a maven fact applied by running the following command
mvn eclipse:eclipse
in the workspace of your project. run
mvn clean package
just for good measure to make sure all your dependencies are resolved and available before restarting eclipse.
Once you restart eclipse again and bring your project up your issues should be resolved.
You should look up more information about these 2 commands and how to use them effectively.
Save yourself a ton of hassle and get the M2Eclipse plugin. The plugin will handle all of the project setup for you and you don't have to worry about doing the mvn eclipse:eclipse commands.
http://www.sonatype.org/m2eclipse/
have you executed
mvn eclipse:configure-workspace -Declipse.workspace=/path/to/workspace
?
You need to execute it so maven set the M2_REPO path to eclipse. Or you can set it manually.
Remenber to restart eclipse after you do so :P
Related
I don't know what's the problem but I am not able to use a maven for my projects.
This is the output of the command that means all the setup for maven is done properly but dont know why performing tasks is leading to a BUILD FAILURE.
mvn.cmd
mvn clean
You are in your main user folder vipul. The clean command is project specific, you need to be in the project path, a project which is configured for maven (has pom.xml file)
The error says you don't have a pom.xml file, which means you're running the command in the wrong directory or you haven't got the project set up. This quick Maven overview guide will help you set up a project if you haven't already.
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.
Suppose I have the following file/project structure.
MSPCommon/trunk/pom.xml
MSPWebManager/trunk/pom.xml
and MSPWebManager depends on MSPCommon and MSPCommon and MSPWebManager are in the same directory.
I have imported these projects into eclipse, and within eclipse I can successfully do maven builds on MSPWebManager (like mvn clean compile) IF I do it the following way. Go to Run -> Run configurations, type in the maven commands AND select Resolve Workspace artifacts.
That's all great, but what I would like to be able to do is run the same maven commands from the command line. So I navigate to the MSPWebManager/trunk directory, do a mvn command like mvn clean compile and this is the result:
As you can see there is one other local jar that is missing, but for simplicity I only included one in this question because I'm assuming the fix is the same for them all.
Also, if I do some type of build within eclipse but I do NOT check the Resolve Workspace artifacts, I get the same error as I do on the command line.
Any suggestions on how to get this to work from the command line?
Thanks
Go to the module MSPCommon and run a mvn clean install then go to MSPWebManager and do the mvn clean compile
mvn install resolves the dependencies and installs your build inside of your .m2 repository / folder.
I imported a Maven project into Eclipse. I was able to deploy it from the command line. In Eclipse it is full of red Xs. I have cleaned the project, updated the configuration and I ran the following command:
mvn -Declipse.workspace=<pathtoworksapce> eclipse:add-maven-repo
and I still have the same problem. The project is dependent on another project.
What I ended up doing was removing all of the projects in Eclipse, but not deleting the source files. Then instead of directly importing the code as Maven->Check out as Maven Projects with SCM, I selected Existing Maven Project and imported the code from my local machine. This got rid of the errors, but when I would right click on code and select "Open Declaration", I would get Error: Could not open the editor: The file does not exist" So I removed all projects again and this time I deleted all the ".project" files and repeated the import Existing Maven Project. So now there are no red Xs (dependency problems) and the lookup functionality within the code works.
Go to your master project and type the following :
mvn install
mvn eclipse:eclipse
After that, import your project. You can also install m2eclipse for better support. If you use gwt or any other framework which has a custom maven execution, you should also install plugins for those in Eclipse.
I have maven eclipse plugin and I want to use a jar file in my project that is not supported in maven so I found out I have to do something like this :
mvn install:install-file -Dfile=c:\kaptcha-2.3.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar
So I have to install maven to issue that command but won't that cause redundancy with maven plugin ?
You can install multiple different versions of maven, and configure m2eclipse to use a specific instance, see the setting under Window > Preferences > Maven > Installations.
Managing multiple different versions on the command line is controlled by the PATH environment variable, you would normally define an environment variable M2_HOME which specifies the home directory of the version that you are currently using, and then add $M2_HOME/bin or %M2_HOME%\bin to your path environment variable.
It is no problem if you have both maven and eclipse maven plugin installed. I only use eclipse maven plugin for its pom.xml file editor. I do all other operations about maven through the command line.
Besides, the plugin (m2eclipse) I used, sometimes give strange dependency errors although everything is fine. Because when I run a "mvn install" for the project, it is built successfully. So, I think using maven itself is more reliable.