M2E setting file - maven

I just have installed M2E for my Eclipse IDE, I'd like to know how to create a setting file, which can be used to config maven for eclipse, contains infomation such as remote repository, etc. Whether I need to download maven and set maven_home to do that?
Thanks!

in Eclipse go to: Window -> Preferences -> Maven -> Installation: select a file (your settings.xml) for global settings for the embedded installation. The file can be located everywhere you want (the .m2 repository folder is a good location) and must fit the settings.xml style you can find in the documentation.

Related

Use default settings.xml file instead of one in ~/.m2

Is there possibility for Maven to ignore settings.xml contained in .m2 folder?
I want it to use default repository, but my laptop has configured development environment for other repositories and I don't want to lose these settings. What's more, these repositories have priority over repos in my pom.xml and fail if they can't download artifact.
What are the options? Should I choose other settings.xml file or is there option to use none?
You don't have to have a settings.xml in the .m2 folder. If there is none Maven uses <Maven installation folder>/conf/settings.xml, which has everything commented out by default.
See also Settings Reference, Quick Overview:
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml
You can use custom settings files with the command line options:
-s,--settings
Alternate path for the user settings file
-gs, --global-settings
Alternate path for the global settings file
And, BTW, .m2 is not the Maven home. It's the folder for user-specific configuration and local repository. I corrected the question's title acordingly.

How to specify Maven local repository if I cannot use default Maven local repository settings?

we have restrictions on size of the $HOME and therefore I cannot use default settings ~/.m2/ We use in per-job configuration "use private maven repository" option. What to do if job 2 is dependent on an artifact produced by job 1.
If you're using maven directly (through commandline maybe) than create a settings.xml within the conf directory of your maven. This settings.xml should look like:
<settings>
<localRepository>C:\Repository</localRepository>
</settings>
If you're working with Eclipse than place the settings.xml wherever you want and go within Eclipse to Window -> Preferences -> Maven -> User Settings and set User Settings with the path to your settings.xml.
The simplest solution for the command line is to give it via command line:
mvn -Dmaven.repo.local=WhereEverYouLikeToHaveYourRepo

maven + elicpse related questions

Forgive me asking following questions. I am totally lost in regards to maven+eclipse. I checked out someone's java project (maven built) from SVN to my local eclipse (kepler). When I click Windows > Preferences, I see Maven.
question 1)
Is this a maven plugin? When developers say maven in eclipse, are they referring to maven plugin? maven and maven plugin are two separate components?
question 2)
when I click on user settings, C:\Users\myName.m2\settings.xml is missing. Exact error message is "User settings file doesn't exist". Does it get created when you install maven plugin at first time?
question 3)
I found three folders may have to do with maven C:\workspace\maven_local_repo_artifactory directory, C:\maven_local_repo and C:\Users\myName.m2\respository but not sure how they get created and what is the relationship among them.
question 4)
Is it ok to remove current maven plugin from eclipse and re-install it then check out the java project from SVN? I think my maven or maven plugin settings are not correct in my local box.
1) Is this a maven plugin? When developers say maven in eclipse, are
they referring to maven plugin? maven and maven plugin are two
separate components?
Yes. This is the maven-plugin. maven-plugin uses the configurations of maven (%M2_HOME%/conf).
If you wanna work with maven, you need to install it on your machine. Then you can run maven commmands. In addition, if you want to invoke maven commands within eclipse (conveniently) - you can install the eclipse-plugin. "maven-plugin" is a plugin for eclipse, that lets you use maven within Eclipse conveniently.
2) when I click on user settings, C:\Users\myName.m2\settings.xml is
missing. Exact error message is "User settings file doesn't exist".
Does it get created when you install maven plugin at first time?
By default, the maven-plugin assumes that your settings.xml (which is the configuration file of maven) is in the path you have mentioned. However, there are cases (like in my case) where the config file is not there, but under %M2_HOME%/conf. you can update it in Eclipse, and the error will disappear.
3) I found three folders may have to do with maven
C:\workspace\maven_local_repo_artifactory directory,
C:\maven_local_repo and C:\Users\myName.m2\respository but not sure
how they get created and what is the relationship among them.
C:\Users\myName.m2\respository is the "local repository". If you learned a bit about how maven works, it holds a local repo on the local machine, and it keeps there all artifacts. It downloads them from the "repository" - if you have one in your company (Nexus, Artifactory, etc) or from Maven Central. However, this path is configurable by Maven's settings. So there might be that someone played with it and changed the path, and these other directories were created. You did not mention what resides inside these paths...
4) Is it ok to remove current maven plugin from eclipse and re-install
it then check out the java project from SVN? I think my maven or maven
plugin settings are not correct in my local box.
Sure it is OK. You may remove the plugin, and the source plus maven itself will not be deleted from your machine.
HTH.

maven install-file "Missing artifact"

I want to reference a jar (ie vim25.jar, VMWare VSphere server management) in the POM of my project. As this file is not referenced in MavenRepository I do the following steps:
Download the file from VMWare site
Install the file using:
mvn install:install-file -Dfile=./vim25.jar -DgroupId=manuallyInstalledJars -DartifactId=vim25 -Dversion=2.5 -Dpackaging=jar
Everyting works well and I can find the jar in myLocalRepo/manuallyInstalledJars/vim25/2.5/vim25-2.5.jar
Beside the jar there is the POM, I open it and extract the dependency references:
[groupId]manuallyInstalledJars[/groupId]
[artifactId]vim25[/artifactId]
[version]2.5[/version]
("<" replaced by "[" because of the editor)
I enclose this with the [dependency] tag and put everything in the POM that uses the jar
In Eclipse I get an error (red mark in the text editor) with this comment:
"Missing artifact manuallyInstalledJars:vim25:jar:2.5"
Any idea ?
Perhaps just post the dependency xml so we can rule that out.
In any case try this in Eclipse (assuming you have m2eclipse plugin installed)
Window-> Show View -> Maven Repositories
Expand Local Repositories
Right click Local Repository -> Rebuild Index.
This sometimes help refresh the maven repo in Eclipse when youve made external changes
After the rebuild, check you can see the JAR in that local repository tree in the maven repositories view. You can also confirm that Eclipse is looking at the same local repository as your external maven installation.
If it's not, check the user settings in the eclipse preferences.
Window -> Preferences -> Maven -> User Settings
You can check it is referencing the correct maven settings xml file

How to change maven repository folder in windows?

In windows, maven downloads everything in the C:\Documents And Settings\MyUser\.m2 folder (or C:\Users\MyUser\.m2). There exists some way to change the folder that it uses? Specially I want to set it to download anywhere BUT in the Documents And Settings/Users folder.
Look at your settings.xml in ${maven.home}/conf or, preferrably, ${user.home}/.m2/settings.xml (see this for details about the settings.xml). You can add (or uncomment) the following section:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
-->
<localRepository>/path/to/local/repo</localRepository>
as suggested by the commented out section already there by default. There, you should be able to change the path to achieve what you want.
For Eclipse IDE
If you are using your local maven as the Maven Installation in M2 plugin in Eclispe, editing the settings.xml wasn't enough for me. The plugin was still using the default {user.home}/.m2 as the repository location.
I had to go to : Windows > Preferences > Maven > User Settings and point to my local maven's settings.xml file in the Global Settings and/or User Settings input fields. Clicking apply will then start storing artifacts in the correct destination.

Resources