无法在eclipse中打开新创建的Maven项目

时间:2015-05-06 15:17:06

标签: java eclipse maven build workspace

我使用以下maven命令

创建了一个新的maven项目
mvn archetype:generate -DgroupId=com.company.lib_name -DartifactId=lib_name -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

当我在eclipse中打开这个新创建的项目时,会出现以下错误:

Could not calculate build plan: Plugin org.apache.maven.plugins:maven-jar-  plugin:2.3.2 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin:jar:2.3.2
Plugin org.apache.maven.plugins:maven-jar-plugin:2.3.2 or one of its    dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin:jar:2.3.2: Hostname cannot be null

我尝试了以下内容:

  1. 删除.m2 /存储库并重建项目
  2. 已验证maven repo中存在工件
  3. Maven用户设置指向正确的settings.xml
  4. 项目在命令行上编译
  5. 清理项目
  6. 强制更新项目
  7. 检查回购以查看所有依赖项已下载
  8. 更改eclipse以使用外部maven而不是embeded 我也在使用Kepler和Maven 3。
  9. 知道什么'主机名不能为空'指着?

    这是pom内容

      <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.company.lib</groupId>
      <artifactId>liby</artifactId>
       <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
     <name>lib</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
         <dependency>
           <groupId>org.slf4j</groupId>
           <artifactId>jcl-over-slf4j</artifactId>
           <version>1.7.0</version>
           <scope>runtime</scope>
           </dependency>
           <dependency>
           <groupId>org.slf4j</groupId>
           <artifactId>slf4j-api</artifactId>
            <version>1.7.0</version>
            <scope>runtime</scope>
        </dependency>
       <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <scope>runtime</scope>
       </dependency>
       <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.14</version>
       </dependency>
       </dependencies>
     </project>
    

    还有settings.xml

    <settings>
    <profiles>
        <profile>
            <id>Blah</id>
            <repositories>
                <repository>
                    <id>inhouse</id>
                    <url>http://mavenrepo/maven2_repositories/inhouse</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>inhouse_snapshot</id>
                    <url>http://mavenrepo/maven2_repositories/inhouse_snapshot</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>inhouse</id>
                    <url>http://mavenrepo/maven2_repositories/inhouse</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>inhouse_snapshot</id>
                    <url>http://mavenrepo/maven2_repositories/inhouse_snapshot</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile> 
    </profiles>
    <activeProfiles>
        <activeProfile>company_name</activeProfile>
    </activeProfiles>
    
    <mirrors>
        <mirror>
            <id>central-to-nexus</id> 
            <mirrorOf>*</mirrorOf>
            <url>http://mw_maven_repository_readonly/nexus/content/groups/cached</url>
        </mirror>
    </mirrors>
    

3 个答案:

答案 0 :(得分:1)

您似乎已经从Maven模板创建了项目,但在Eclipse中导入之前您没有将此项目作为Eclipse项目。

因此,在使用maven命令创建新的maven项目之后,您还应该执行以下命令将项目作为Eclipse项目

mvn eclipse:eclipse

它将生成Eclipse IDE所需的所有项目文件。

我还希望在Eclipse中导入项目之前执行&#34; mvn clean install&#34;

答案 1 :(得分:0)

在命令提示符处

日食:日食 mvn clean install

这应该下载所有依赖项

答案 2 :(得分:0)

谢谢大家的答案。但问题出在maven repo网址上。