简体   繁体   中英

How to create a Maven project in Eclipse

I want to create a web application project in Eclipse with Maven. Everytime I try to create the project I get an error as "Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories" .

I have checked for solutions presented in other questions tried them, but none of them solved the issue. I have also changed my settings.xml file to point it to proxy even that didn't help. I also tried deleting the repositries folder in .m2 .

Please suggest some solutions for this

  1. Open Window > Preferences
  2. Open Maven > Archetypes
  3. Click 'Add Remote Catalog' and add the following:

That is quite a weird issue ... however m2eclipse gave me my fair share of problems when I tried to create my projects. In fact, I ended up creating the archetypes myself!

Let me share my maven 3 POM file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>example-project</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencies>
        <!-- add your dependencies here -->
  </dependencies>

  <build>
    <finalName>example-project</finalName>
    <pluginManagement>
        <plugins>

            <!-- v. useful! m2eclipse sometimes fails to see it as a 
                 dynamic web app project in Eclipse. Declaring this plugin 
                 would help eclipse recognize its nature (i.e. a Java 
                 project requesting at least JDK1.7+ -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

        </plugins>
    </pluginManagement>
  </build>
</project>

Running mvn eclipse:eclipse on this project should work. You can safely import to eclipse as a maven project as well ( File > Import > Existing Maven Projects ) If it doesn't, then you should consider re-installing a fresh copy of maven.

Let me know if you manage to get it up and running. :)

I was recently struggling to create a new Maven project in Eclipse. Trying to create a Dynamic Web Project first and then converting it into a Maven project did not work (none of the Java integration was working and my code wouldn't even compile)!

The following article describes how to create a Maven project in Eclipse. The tutorial recommends skipping the archetype part, which might solve the issue described in the original question:

https://www.tech-recipes.com/rx/39279/create-a-new-maven-project-in-eclipse/

If that doesn't work for you, perhaps doing a clean install with the latest version of Eclipse, in a new directory, may help. What you described might just be a bug in Eclipse or one of its installed plugins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM