Failed to resolve version for org.apache.maven.archetypes - eclipse

I have configured maven3.0.3 in my local machine. Have installed m2e eclipse plugin.
But when i try to create a new maven project using maven-archetype-webapp, i get the following exception.
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
Could not resolve artifact org.apache.maven.archetypes:maven-archetype- webapp:pom:RELEASE
Failed to resolve version for org.apache.maven.archetypes:maven-archetype- webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype- webapp/maven-metadata.xml in local ([HOME]/.m2/repository)
Failed to resolve version for org.apache.maven.archetypes:maven-archetype- webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype- webapp/maven-metadata.xml in local ([HOME]/.m2/repository)
I do some processing behind a proxy and the proxy configurations are updated in {HOME}/.m2/settings.xml and M2_HOME/conf/settings.xml.
The archetype generate command works fine in command line. It downloaded the dependencies through proxy.
Any help is greatly appreciated.
Edit 05-10-2012
While creating a new Maven Web project in eclipse, the archetype "maven-archetype-webapp" version is displayed as RELEASE. Is this in anyway linked?

I had the same problem. I fixed it by adding the maven archetype catalog to eclipse. Steps are provided below:
Open Window > Preferences
Open Maven > Archetypes
Click 'Add Remote Catalog' and add the following:
Catalog File: https://repo1.maven.org/maven2/archetype-catalog.xml
Description: maven catalog

I found the following tutorial very useful.
Step1: The maven command used to create the web app:
mvn archetype:generate -DgroupId=test.aasweb -DartifactId=TestWebApp -DarchetypeArtifactId=maven-archetype-webapp
Step2: The following entry was added onto the project's pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>1.5</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<classpathContainers>
<classpathContainer>
org.eclipse.jst.j2ee.internal.web.container
</classpathContainer>
<classpathContainer>
org.eclipse.jst.j2ee.internal.module.container
</classpathContainer>
/classpathContainers>
<additionalProjectFacets>
<jst.web>2.5</jst.web>
<jst.jsf>1.2</jst.jsf>
</additionalProjectFacets>
</configuration>
</plugin>
Step3: Run the maven command to convert into eclipse project format.
mvn eclipse:clean eclipse:eclipse
Step4: Import the project onto eclipse as Existing Maven project.

If you are using eclipse, you can follow the steps here (maven in 5 min not working) for getting your proxy information. Once done follow the steps below:
Go to Maven installation folder C:\apache-maven-3.1.0\conf\
Copy settings.xml to C:\Users\[UserFolder]\.m2
Modify the proxy in settings.xml based on the info that you get from the above link.
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>your proxy</host>
<port>your port</port>
</proxy>
Open eclipse
Go to: Windows > Preferences > Maven > User Settings
Browse the settings.xml from .m2 folder
Click Update Settings
Click Reindex
Apply the changes and Click OK
You can now try to create Maven Project in Eclipse

Read carefully about the reason.
"Failed to resolve version for org.apache.maven.archetypes:maven-archetype- webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype- webapp/maven-metadata.xml in local"
So all you need to do is download the maven-metadata.xml
to your {HOME}.m2\repository
That's it.

You do need to have a settings.xml linked under user settings (Located in preferences under maven)
But, if that doesn't fix it, like it didn't for many of you. You also have to delete the directory:
.m2/repository/org/apache/maven/archetypes/maven-archetype-quickstart
then quit eclipse and try again.
This is what solved my problem.

Go to Windows-> Preference-> Maven -> User settings
Select settings.xml of Maven
Restart Eclipse

I had a similar problem building from just command line Maven. I eventually got past that error by adding -U to the maven arguments.
Depending on how you have your source repository configuration set up in your settings.xml, sometimes Maven fails to download a particular artifact, so it assumes that the artifact can't be downloaded, even if you change some settings that would give Maven visibility to the artifact if it just tried. -U forces Maven to look again.
Now you need to make sure that the artifact Maven is looking for is in at least one of the repositories that is referenced by your settings.xml. To know for sure, run
mvn help:effective-settings
from the directory of the module you are trying to build. That should give you, among other things, a complete list of the repositories you Maven is using to look for the artifact.

I too had same problem but after searching solved this. go to menu --> window-->preferences-->maven-->Installations-->add--> in place of installation home add path to the directory in which you installed maven-->finish-->check the box of newly added content-->apply-->ok. now create new maven project but remember try with different group id and artifact id.

The right way to solve my problem are as followed. Hope to be helpful to others.
the errors informations.
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:1.0 from any of the configured repositories. Could not resolve artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 Failure to transfer org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0
Delete the maven-archetype-webapp:1.0 in the directory ~/.m2/repository/org/Apache/maven/archetypes
Download the maven-archetype-webapp:1.0 and the maven-archetype-webapp-1.0.pom from
http://maven.ibiblio.org/maven2/org/apache/maven/archetypes/maven-archetype-webapp/1.0/
execute mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=maven-archetype-quickstart -Dversion=1.1 -Dpackaging=jar -Dfile=此处填maven-archetype-webapp-1.0的路径.
try to establish a maven project of webapp to test whether the problem has solved.

Create New User Environment Variables:
MAVEN_HOME=D:\apache-maven-3.5.3
MAVEN=D:\apache-maven-3.5.3\bin
MAVEN_OPTS=-Xms256m -Xmx512m
Appened below in Path variable (System Variable):
;D:\apache-maven-3.5.3\bin;

This worked for me:- navigate to windows-> preferences-> maven
and check the "download artifacts sources" and click apply.

No need to do all above lengthy steps.
Simply delete c:\Users\.m2\Repository\org folder
Maven will automatically downloads what it needs

I simple use below steps:
Create Maven project -> check checkobox -> "Create a simple project (skip archetype selection)"
It works for me

I downloaded the jar and pom from:
here
and put them here:
\.m2\repository\org\apache\maven\archetypes\maven-archetype-quickstart\1.1\

I also got same error ....And i found that my internet connection is closed so eclipse is unable to download repositories for webapps archetypes and when i got internet connection i just created again maven project with webapps archetypes and my eclipse downloaded repositories and its done...

This is 100% working:
Delete the .m2 folder which is present in your Desktop>User
connect your pc to the Internet
Create your maven project again
Thats it, hope it helps

Try , It worked for = I just removed "archetypes" folder from below location
C:\Users\Lenovo.m2\repository\org\apache\maven
But you may change following for experiment - download latest binary zip of Maven, add to you C:\ drive and change following....
Change Proxy
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>10.23.73.253</host>
<port>8080</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>

I had the same problem i solved it by only adding remote catalog
in eclipse go to Window -> Preferences ->Maven ->Archetypes ->click on add remote Catalog then a window will open in that paste
http://repo.maven.apache.org/maven2/archetype-catalog.xml
in that catalog file then hit ok restart eclipse now all working fine

The problem may also come from that you haven't set MAVEN_HOME environment variable. So the Maven embedded in Eclipse can't do its job to download the archetype.Check if that variable is set upfront.

Related

GWT Maven - webapp files getting deleted when running in dev mode

As specified in the gwt maven mojo plugin documentation, I have selected src/main/webapp folder as my war directory in eclipse->project properties->Google->Web application. Then, when I tried to run my gwt project in dev mode from eclipse, the html files in webapp folder was getting deleted. After some investigation, I was able to fix this by modifiying -war value in run configuration to the target folder of the project. But the problem I am facing now is that, after running the project in dev mode, I have to manually copy the html files to the target directory each time for the dev mode to work. Can anyone please help me to identify what I am missing here. How can I set the webapp folder as war directory and prevent the files from getting deleted? Please help.
The correct way to configure the Google Plugin for Eclipse (using M2Eclipse) and run DevMode is explained in the FAQ: http://web.archive.org/web/20130619170526/https://developers.google.com/eclipse/docs/faq#gwt_with_maven
May be you have to set the copyWebapp parameter to true?
<configuration>
<style>PRETTY</style>
<strict>true</strict>
<runTarget>index.html</runTarget>
...
<copyWebapp>true</copyWebapp>
</configuration>
Our .pom uses this:
<properties>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<gwt.war.directory>${project.build.directory}/war</gwt.war.directory>
</properties>
In the Arguments tab of the debug configuration we use:
-remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -startupUrl appname.jsp -logLevel INFO -port 8888 -codeServerPort 9997 -war
"${workspace_loc:appname/target/war}" com.yourcompany.app
Seems to work without the problem you are having.
I am not sure if this is a problem faced only by me, but even after following the steps specified in the maven plugin configuration the issue had occurred to me randomly. But nowadays its not happening and this is what I did differently.
Use the gwt only in eclipse java perspective, not in j2ee perspective.
In eclipse->project properties->Google->Web application, check the Launch and deploy from this directory option.
I was caught out by this too. If you put your static files for the webapp into the "src/main/webapp" folder, they will be copied over to the target folder if the tickbox in Settings->Web Application is unchecked (as it would be by default if it's an M2eclipse project).
I set my target folder to be the "war" folder on the project and ignored it in version control.

Where can I obtain the maven-source-plugin?

I checked out an open-source project from SourceForge's SVN source control using the Eclipse Maven plugin. After it checks out, I get this error in the pom.xml file:
Error resolving version for plugin
'org.apache.maven.plugins:maven-source-plugin' from the repositories
[local (C:\Documents and Settings\thomas.owens\.m2\repository),
central (http://repo1.maven.org/maven2)]: Plugin not found in any
plugin repository
I'm fairly new to Maven, but I followed the installation instructions for Apache Maven and the Eclipse plugin. It seems weird that this plugin would not be found in the central plugin repository for Maven or my local repository, when I can clearly see a directory located at C:\Documents and Settings\thomas.owens\.m2\repository\org\apache\maven\plugins\maven-source-plugin that contains a single resolver-status.properties file.
Any thoughts as to why this plugin might not be found and where I can find it?
The problem that I was encountering was not an issue with the maven-source-plugin, but incorrect proxy settings that was preventing the connection to the repositories. The answers to this question on the use of Maven with a proxy helped me to find the mistake and correct it.
That plugin is in the central repository.
Perhaps you just need to run with -U to update:
mvn -U clean install
Or in Eclipse: right-click on the project, select Maven-> Update Dependencies, (perhaps) Maven-> Update Project Configuration
Check if you are able to see Maven in Eclipse, Window > Preferences.
If so, select Maven and go to installations and check if the folder, in where maven was installed, is properly set. Then, set your setting.xml file, it should be in /(maven installation folder)/conf/
Then, right click in your project go to Maven > Update Maven Dependencies.
Did it help?
Which project?
Perhaps there is a bug in their pom.
Or perhaps they require a 'standardized' develop environment with specific environment variables set, or a specific setting in user.home/.m2/settings.xml

Eclipse doesn't find source attachements

When opening a class included through a Maven dependency, Eclipse tells me that the containing .jar file has got no source attachment.
But in the directory in which the .jar file resides, there is also as corresponding -sources.jar file.
Do you have any hints regarding the solution of this problem?
Is there a way to tell Eclipse where it should automatically look for the source attachment?
Edit: In the Eclipse .classpath file, the sourcepath value is set for external archives, but not for ours. But both jars and sources file reside in the same repo.
The property -Declipse.useProjectReferences=false is also set.
The problem was that there were already sources.jar-not-available files for certain projects in my local repository.
I've deleted them and now the attachment of source files is working. Obviously Eclipse respectively the Maven Eclipse plugin doesn't look for source attachments as long as these marker files exist.
If it hadn't been for the comment from K. Claszen I'd have never came up with this solution.
Check that you have downloadSources in the maven-eclipse-plugin section of your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
...
</configuration>
</plugin>
If you are using m2eclipse plugin for integrating Maven projects in Eclipse, you might need to enable downloading sources and javadocs in m2eclipse preferences:
Window > Preferences > Maven > Download Artifact Sources
For me the file was in place in local repo and eclipse (4.5) kept complaining there is no associated source jar (sources.jar-not-available did not existed). I ended up removing the directory from local repo, letting eclipse to download the sources again repolulating the repo, running mvn eclipse:eclipse and refreshing the project.
For me all these steps was necessary to get this working.
For those who are still having trouble downloading sources for your Maven dependencies (like me), you can try this alternate method:
Find the particular Maven dependency you wished to inspect Java source code for. You need to have the Maven artifact name.
Next, navigate to the Maven repository server where you download the Maven dependency from. For example, I have spring-security-core-5.5.1.jar as my Maven dependency. The repository host site is from mvnrepository.com, in which the repository server is from https://repo1.maven.org/maven2/.
Navigate to mvnrepository.com and search for your Maven dependency artifact. In my case, it would be spring-security-core, and I located the artifact information page here.
On this page, in the table row labeled Files, you want to click on View All, on the right of the JAR link with how many kilobytes displayed to the side. (Underlined)
Once you're viewing the list of all JARs provided with the Maven dependency, click and download the one that says, [artifact name]-[artifact version]-sources.jar. In my case, it's spring-security-core-5.5.1-sources.jar.
Once downloaded, on your local machine, use your File Explorer to navigate to the folder containing the artifact JAR which you have trouble downloading the source codes for. In my case, it would be $MAVEN_HOME/repository/org/springframework/security/spring-security-core/5.5.1.
Move the [artifact name]-[artifact version]-sources.jar into this folder.
Go back into Eclipse, and try attaching the sources. You should be able to pick up the ...-sources.jar file upon attaching it.
After attaching it, you will then be able to see the source codes for your Maven dependency.
Right click at project, select Maven, select Download Sources.
I download a maven project from online,use mvn eclipse:eclipse converted to eclipse project then I occurred the problem.
solution is remove all external lib that start with 'M2_REPO',it's work for me.

Eclipse m2eclipse getting dependencies from local repository

I have dependencies installed local on my machine (~/.m2/repository/blah/blah/blah) and m2eclipse is not recognizing them as there - I think m2eclipse is using its own maven instance. Is there any way to force m2eclipse to use the local maven installation in osx?
I had the same problem, and this is what worked for me. Using Eclipse Indigo:
Windows->Show View->Other
In the pop-up:
Maven->Maven Repositories
Once the view is displayed, right click on the appropriate repo, and select "Rebuild Index"
Wait a few seconds and done!
I have dependencies installed local on my machine (~/.m2/repository/blah/blah/blah) and m2eclipse is not recognizing them as there.
Do they have good metadata? How did you install them? Because m2eclipse definitely uses your local repository for dependency resolution.
I think m2eclipse is using its own maven instance. Is there any way to force m2eclipse to use the local maven installation in osx?
Yes, m2eclipse uses its own version of Maven by default and you can add an external installation via Window > Preferences > Maven > Installations but this won't change anything to the local repository used by one or the other that you can configure via Window > Preferences > Maven > User Settings as shown below:
alt text http://www.imagebanana.com/img/w5y2vevt/screenshot_008.png
This send us back to the questions above: how did you "install" the problematic dependencies?
You can change the used Maven instance in Windows->Preferences->Maven->Installations. But I'm not sure whether this will help as a comment below that setting says that dependency resolution will still be done with the internal Maven installation.
If I were you, I would try to add that local repository to the list of known repositories. Use Window->Show View->Maven repositories (this is sadly not visible in the preferences).
Check that the jar was installed properly. Maven does not give an error when you provide an incorrect path to the jar when installing to local repository. The jgravatar.jar was not in my ~ directory when I ran the command below.
mvn install:install-file -Dfile=~/jgravatar.jar -DgroupId=jgravatar -DartifactId=jgravatar -Dversion=06292012 -Dpackaging=jar
[INFO] Installing /Users/steve/~/jgravatar.jar to /Users/steve/.m2/repository/jgravatar/jgravatar/06292012/jgravatar-06292012.jar
[INFO] Installing /var/folders/gz/gjyqtkzj3ys8lpmh_38qvmn00000gq/T/mvninstall2662938607942511865.pom to /Users/steve/.m2/repository/jgravatar/jgravatar/06292012/jgravatar-06292012.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
I was getting the exact same issue. I added the JARs to the local repository via the install-file command. I verified they were installed. I rebuilt the index. I went to the directory and inspected the JAR file using 7Zip, but I could not get it to appear in the Maven Dependencies inside of my eclipse project.
For me the solution was pretty silly. When I added the dependency into the pom.xml using the dependencies editor, Maven threw in a packaging stanza into the XML. So the XML entry looked like:
<dependency>
<groupId>slf4j</groupId>
<artifactId>jdk14</artifactId>
<version>1.5.8</version>
<type>JAR</type>
</dependency>
When I removed the last stanza "JAR" and made the entry:
<dependency>
<groupId>slf4j</groupId>
<artifactId>jdk14</artifactId>
<version>1.5.8</version>
</dependency>
it all worked fine.

Get source jar files attached to Eclipse for Maven-managed dependencies

I am using Maven (and the Maven Eclipse Integration) to manage the dependencies for my Java projects in Eclipse. The automatic download feature for JAR files from the Maven repositories is a real time saver. Unfortunately, it does not include API documentation and source code.
How can I set up Maven to automatically also get the source and javadoc attachments and register them properly with Eclipse?
I am sure m2eclipse Maven plugin for Eclipse - the other way around - can do that. You can configure it to download both the source files and javadoc automatically for you.
This is achieved by going into Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options.
mvn eclipse:eclipse -DdownloadSources=true
or
mvn eclipse:eclipse -DdownloadJavadocs=true
or you can add both flags, as Spencer K points out.
Additionally, the =true portion is not required, so you can use
mvn eclipse:eclipse -DdownloadSources -DdownloadJavadocs
The other answers on this work, but if you want to avoid having to remember command line arguments, you can also just add to the downloadSources and downloadJavadocs config to the maven-eclipse-plugin section of your pom.xml:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
... other stuff ...
</configuration>
</plugin>
</plugins>
</build>
...
</project>
I prefer not to put source/Javadoc download settings into the project pom.xml file as I feel these are user preferences, not project properties. Instead, I place them in a profile in my settings.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<profiles>
<profile>
<id>sources-and-javadocs</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>sources-and-javadocs</activeProfile>
</activeProfiles>
</settings>
Right click on project -> maven -> download sources
If the source jars are in the local repository and you are using Eclipses maven support the sources are getting automatically attached. You can run mvn dependency:sources to download all source jars for a given project. Not sure how to do the same with the documentation though.
If you are using meclipse do
window --> maven --> Download Artifact Sources (select check)
(If you still get attach source window, then click on attach file button and close the attach source window. The next time you try to see the source it will open the correct source)
There is also a similiar question that answers this and includes example pom settings.
I tried windows->pref..->Maven But it was not working out. Hence I created a new class path with command mvn eclipse:eclipse -DdownloadSources=true and refreshed the workspace once. voila.. Sources were attached.
Source jar's entry is available in class path. Hence new build solved the problem...
in my version of Eclipse helios with m2Eclipse there is no
window --> maven --> Download Artifact Sources (select check)
Under window is only "new window", "new editor" "open perspective" etc.
If you right click on your project, then chose maven--> download sources
Nothing happens. no sources get downloaded, no pom files get updated, no window pops up asking which sources.
Doing mvn xxx outside of eclipse is dangerous - some commands dont work with m2ecilpse - I did that once and lost the entire project, had to reinstall eclipse and start from scratch.
Im still looking for a way to get ecilpse and maven to find and use the source of external jars like servlet-api.
Changing pom for maven-eclipse-plugin to include source/javadoc just apply for new dependencies being added to pom. If we need to apply for existing dependencies, we must run mvn dependency:sources. I checked this.
Checking download source/javadoc in Eclipse-Maven preference, sometimes is not enough. In the event maven failed to download them for some reason (a network blackout?), maven creates some *.lastUpdated files, then will never download again. My empirical solution was to delete the artifact directory from .m2/repository, and restart the eclipse workspace with download source/javadoc checked and update projects at startup checked as well.
After the workspace has been restarted, maybe some projects can be marked in error, while eclipse progress is downloading, then any error will be cleared.
Maybe this procedure is not so "scientific", but for me did succeded.
I've added the pom configuration to the maven-eclipse plugin to download source and javadocs, but I figure/hope that will happen for new dependencies, not existing ones.
For existing dependencies, I browsed in package explorer down to the "Maven Dependencies" and right-clicked on commons-lang-2.5.jar, selected Maven | Download Sources and... nothing appeared to happen (no progress bar or indication that it was doing anything). It did, however, download as I'm able to jump to source in commons-lang now.
overthink suggested using the setup in the pom:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
... other stuff ...
</configuration>
</plugin>
</plgins>
</build>
...
First i thought this still won't attach the javadoc and sources (as i tried unsuccessfully with that -DdownloadSources option before).
But surprise - the .classpath file IS getting its sources and javadoc attached when using the POM variant!
For Indigo (and probably Helios) the checkboxes mentioned above are located here:
Window -> Preferences -> Maven
I had a similar problem, and the solution that worked best for me was to include the source in the same jar as the compiled code (so a given directory in the jar would include both Foo.java and Foo.class). Eclipse automatically associates the source with the compiled code, and automatically provides the JavaDoc from the source. Obviously, that's only helpful if you control the artifact.
After Setting the Properties either at Project Level or User Properties level,
Please do a Maven -> Update Project (Force Update). It downloads the sources
A Small addition to the answer, if your project is not a maven project still you can get the source code of the jars, by using this plugin provided in eclipse
Java Source Attacher