Can I get a link to the .m2 directory in my pom.xml file. At the moment I am directing it at ${user.home}/.m2/repository but some of the users may have their .m2 folder elsewhere. I have tried ${localRepository} but it just creates that directory in my current directory instead of jumping to it plus it creates a weird structure like id: local url :file/.m2/repository/*. I want to link the .m2 repository directory
I believe that you're looking for:
${settings.localRepository}
as described in the List of predefined Maven properties.
Related
I downloaded maven gz file, unzipped same, but i dont know where the m2 is stored. I imagine im missing a step but i cant see what one?
Is there aninstall script etc?
[root#atddpvm5 apache-maven-3.5.4]# cd /var/tmp/apache-maven-3.5.4/
[root#atddpvm5 apache-maven-3.5.4]# ls
apache-maven DEPENDENCIES doap_Maven.rdf LICENSE maven-builder-
support maven-core maven-model maven-plugin-api
maven-resolver-provider maven-settings-builder NOTICE README.md
CONTRIBUTING.md deploySite.sh Jenkinsfile maven-artifact maven-compat
maven-embedder maven-model-builder maven-repository-metadata maven-
settings maven-slf4j-provider pom.xml src
By default the .m2 folder is stored in the home folder of the user. In this case since you are using root, the path is most likely /root/.m2. You also have to use the -a switch with ls to see that folder, since it's a hidden folder (it starts with a .). Note that the folder will only be created on the first usage of Maven, i.e. when you call a maven command on a maven project, like mvn clean install.
Additionally it looks like you have downloaded the source distribution of Maven, which only makes sense if you want to work on Maven itself. You might want to download the binary distribution, if you just want to use it.
I have imported a existent maven project (swagger for jersey jax-rs) into eclipse.
I get a bunch of errors:
It always has to do with the jackson-databind.jar
Example error:
Archive for required library: '.../.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.5/jackson-databind-2.1.5.jar' in project 'swagger-core_2.9.1' cannot be read or is not a valid ZIP file
I cannot find the .m2 folder? I am new to the maven stuff,
do i have to install something extra before i import a maven project into eclipse?
Thx
I cannot find the .m2 folder?
By default the .m2 directory is located at the home directory.
For *Unix operating systems, it will be something like /home/<user_who_fires_maven_commands>/.m2/...
For Windows machines , the m2 will be located at C:\Users\<user>\.m2\...
As for the exception you are getting
Archive for required library: '.../.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.5/jackson-databind-2.1.5.jar' in project 'swagger-core_2.9.1' cannot be read or is not a valid ZIP file
It is most probable that the archive file has gotten curropted ( maybe a download issue or might be possible that its sha1 doesn't match with the one that is on the central repo ). So you can try by simply deleting this jar file and then run mvn install and it will re-attempt to download the file again.
Another thing I would like to point out is that since this is a new eclipse installation, I would suggest that you re-index your local m2 folder so that this new eclipse knows about the files and folders inside the original m2 folder. To re-index, goto Window -> preferences --> Maven --> User settings --> there will be a text field stating the path of the .m2 ( make sure its correct ) and then press re-index
I am having an eclipse project created on Ubuntu, in which all the JARs that I am using, are located in a folder /home/xyz/AllJARs. Here the /home is the system home folder. The project as well as the AllJARs folder is git version controlled on a central git server.
So, all the paths to these JARs in the project's build path are /home/xyz/AllJARs. When I'm cloning the project repo and the AllJARs repo on a Windows machine, I'm shown errors related to build path since it can't find the path /home/xyz/AllJARs.
How can I manage this situation where I can have external JAR files in build paths which can work on Ubuntu as well as on a Windows machine? Thanks in advance.
You have two easy options:
use relative paths: for example, put the JAR folder in the folder above your project, then you can set the JARs' paths to ../AllJARs/
put JARs into project: you can also just put the JARs into the project folder; if you've set them up as "External JARs" in project settings, you'll have to remove them from that list, and re-add them with "Add JARs". Eclipse will then look for them locally in the project folder. If you don't want to commit the JARs to the git repo (size and/or permission being a problem), you can just copy them into the Project folder after cloning. While they're not there, you'll be shown a warning, but once Eclipse can find them, everything's fine.
How can I rename a directory in a custom Maven archetype to be the contents of ${artifactId}?
I have a directory named service/App1 that I want to customize to be service/${artifactId}.
This directory is full of a bunch of files and other directories so I can't just create it with the ${artifactId} I need to keep the contents intact and just rename it.
I was looking into the same thing and found: http://jira.codehaus.org/browse/ARCHETYPE-191
Works like a charm!
Use _____artifactId_____ instead of ${artifactId}
You should use in the folder name _rootArtifactId_
AFAIK maven does not have an installer for Windows, you simply unzip it wherever you like, as explained here.
However in many places there are references to a .m2 folder under the user folder (in Win7 I would guess it to be by default at C:\Users\.m2. Alas I do not have that folder. Is there some command to create this folder? Am I missing something basic?
On a Windows machine, the .m2 folder is expected to be located under ${user.home}. On Windows 7 and Vista this resolves to <root>\Users\<username> and on XP it is <root>\Documents and Settings\<username>\.m2. So you'd normally see it under c:\Users\Jonathan\.m2.
If you want to create a folder with a . prefix on Windows, you can simply do this on the command line.
Go to Start->Run
Type cmd and press Enter
At the command prompt type md c:\Users\Jonathan\.m2 (or equivalent for your ${user.home} value).
Note that you don't actually need the .m2 location unless you want to create a distinct user settings file, which is optional (see the Settings reference for more details).
If you don't need a separate user settings file and don't really want the local repository under your user home you can simply set the location of your repository to a different folder by modifying the global settings file (located in \conf\settings.xml).
The following snippet would set the local repository to c:\Maven\repository for example:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>c:\Maven\repository</localRepository>
...
When you first install maven, .m2 folder will not be present in C:\Users\ {user} path.
To generate the folder you have to run any maven command e.g. mvn clean, mvn install etc. so that it searches for settings.xml in .m2 folder and when not found creates one.
So long story cur short,
open cmd -> mvn install
It will show could not find any projects(Don't worry maven is working fine :P)
now check your user folder.
P.S. If still not able to view .m2 folder try unhiding hidden items.
Use mvn -X or mvn --debug to find out from which different locations Maven reads settings.xml. This switch activates debug logging. Just check the first lines of mvn --debug | findstr /i /c:using /c:reading.
Right, Maven uses the Java system property user.home as location for the .m2 folder.
But user.home does not always resolve to %USERPROFILE%\.m2. If you have moved the location of your Desktop folder to another place, user.home might resolve to the parent directory of this new Desktop folder. This happens when using Windows Vista or a more recent Windows together with Java 7 or any older Java version.
The blog post Java’s “user.home” is Wrong on Windows describes it very well and gives links to the official bug reports. The bug is marked as resolved in Java 8. The comment of the blog's visitor Lars proposes a nice workaround.
Do you have the file system display config set up to show hidden files and folders? If I remember correctly, by default it's hidden. Should be under c:\users\username\.m2.
If the default .m2 is unable to find, maybe someone changed the default path. Issue the following command to find out where is the Maven local repository,
mvn help:evaluate -Dexpression=settings.localRepository
The above command will scan for projects and run some tasks.
Final outcome will be like below
As you can see in the picture the maven local repository is C:\Users\X\.m2\repository
Check the configurations in {M2_HOME}\conf\setting.xml as mentioned in the following link.
http://www.mkyong.com/maven/where-is-maven-local-repository/
Hope this helps.
Is there some command to create this folder?
If smb face this issue again, you should know the most simple way to create .m2 folder. If you unzipped maven and set up maven path variable - just try mvn clean command from anywhere you like! Dont be afraid of error messages when running - it works and creates needed directory.
If I'm right, it's just because you are missing the cd command. Try c:\Users\Jonathan\cd .m2/.