运行war文件

时间:2015-07-06 07:49:17

标签: java maven

当我尝试运行war文件时,我得到maven build错误,其中显示*无法获取依赖关系信息:无法读取工件的元数据文件。当我"mvn clean install"时,我没有收到任何错误,并且构建运行正常。 运行war文件的命令是mvn -e clean jetty:run-war -Denv=<directory>

有趣的是,相同的代码库在Prod env和我的同行的本地环境中运行良好并且运行良好。

我删除了.m2 / repository下的所有内容并重新运行mvn,但得到了相同的构建错误。谷歌搜索了很多,但没有得到任何解决方案。

mvn版本是:

Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.7.0_67
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: US-ASCII
OS name: "mac os x" version: "10.10.3" arch: "x86_64" Family: "mac"

-e switch错误:

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: org.sonatype.sisu.inject:guice-bean:pom:null

Reason: Cannot find parent: org.sonatype.sisu:sisu-inject for project: org.sonatype.sisu.inject:guice-bean:pom:null for project org.sonatype.sisu.inject:guice-bean:pom:null


[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Unable to get dependency information: Unable to read the metadata file for artifact 'org.sonatype.sisu:sisu-inject-plexus:jar': Cannot find parent: org.sonatype.sisu:sisu-inject for project: org.sonatype.sisu.inject:guice-bean:pom:null for project org.sonatype.sisu.inject:guice-bean:pom:null
  org.sonatype.sisu:sisu-inject-plexus:jar:2.1.1

from the specified remote repositories:
  apache.snapshots (http://repository.apache.org/snapshots),
  central (http://repo1.maven.org/maven2),
  m2.java.net (http://download.java.net/maven/2),
  glassfish.java.net (http://download.java.net/maven/glassfish)

Path to dependency:
    1) org.mortbay.jetty:jetty-maven-plugin:maven-plugin:7.6.9.v20130131
    2) org.apache.maven:maven-plugin-api:jar:3.0.3


    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:711)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.artifact.resolver.ArtifactResolutionException: Unable to get dependency information: Unable to read the metadata file for artifact 'org.sonatype.sisu:sisu-inject-plexus:jar': Cannot find parent: org.sonatype.sisu:sisu-inject for project: org.sonatype.sisu.inject:guice-bean:pom:null for project org.sonatype.sisu.inject:guice-bean:pom:null
  org.sonatype.sisu:sisu-inject-plexus:jar:2.1.1

from the specified remote repositories:
  apache.snapshots (http://repository.apache.org/snapshots),
  central (http://repo1.maven.org/maven2),
  m2.java.net (http://download.java.net/maven/2),
  glassfish.java.net (http://download.java.net/maven/glassfish)

Path to dependency:
    1) org.mortbay.jetty:jetty-maven-plugin:maven-plugin:7.6.9.v20130131
    2) org.apache.maven:maven-plugin-api:jar:3.0.3


    at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:430)
    at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:435)
    at org.apache.maven.artifact.resolver.DefaultArtifactCollector.collect(DefaultArtifactCollector.java:74)
    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:316)
    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:304)
    at org.apache.maven.plugin.DefaultPluginManager.ensurePluginContainerIsComplete(DefaultPluginManager.java:835)
    at org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo(DefaultPluginManager.java:647)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:468)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    ... 17 more
Caused by: org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException: Unable to read the metadata file for artifact 'org.sonatype.sisu:sisu-inject-plexus:jar': Cannot find parent: org.sonatype.sisu:sisu-inject for project: org.sonatype.sisu.inject:guice-bean:pom:null for project org.sonatype.sisu.inject:guice-bean:pom:null
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:200)
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedArtifact(MavenMetadataSource.java:94)
    at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:387)
    ... 25 more
Caused by: org.apache.maven.project.ProjectBuildingException: Cannot find parent: org.sonatype.sisu:sisu-inject for project: org.sonatype.sisu.inject:guice-bean:pom:null for project org.sonatype.sisu.inject:guice-bean:pom:null
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1396)
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1407)
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1407)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:823)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:255)
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:163)
    ... 27 more
Caused by: org.apache.maven.project.InvalidProjectModelException: Not a v4.0.0 POM. for project org.sonatype.sisu:sisu-inject at /Users/rajyavardhanmishra/.m2/repository/org/sonatype/sisu/sisu-inject/2.1.1/sisu-inject-2.1.1.pom
    at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1599)
    at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1571)
    at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:562)
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1392)
    ... 32 more

pom.build.xml:

<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.random.services</groupId>
<artifactId>build_xyz</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
    <module>../xyz1</module>
    <module>../xyz2</module>
 </modules>
 <build>
        <plugins>
           <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.2</version>
                    <executions>
                                   <execution>
                                            <id>make-a-jar</id>
                                            <phase>compile</phase>
                                            <goals>
                                                           <goal>war</goal>
                                            </goals>
                                   </execution>
                    </executions>
           </plugin>             
        </plugins>
 </build>
 </project>

的pom.xml

<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.random.services</groupId>
    <artifactId>xyz</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>xyz Jersey Webapp</name>
    <build>
        <finalName>xyz</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <inherited>true</inherited>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.glassfish</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>7.6.9.v20130131</version>
                <configuration>
                    <connectors>
                        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                            <port>9092</port>
                            <maxIdleTime>60000</maxIdleTime>
                        </connector>
                    </connectors>
                    <scanIntervalSeconds>0</scanIntervalSeconds>
                    <stopKey>foo</stopKey>
                    <stopPort>9997</stopPort>
         <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
                        <filename>${env.HOME}/logs/xyz_yyyy_mm_dd.request.log</filename>
                      <retainDays>10</retainDays>
                      <append>true</append>
                      <extended>false</extended>
                                            <logTimeZone>GMT</logTimeZone>
                                            <logLatency>true</logLatency>
          </requestLog>

                <webApp>
          <contextPath>/xyz</contextPath>
                    <descriptor>src/main/webapp/WEB-INF/web.xml</descriptor>
                </webApp>
                <jettyXml>src/main/resources/jetty.xml</jettyXml>
                <contextXml>src/main/webapp/WEB-INF/jetty-context.xml</contextXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4.3</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey-version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.12</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>${jersey-version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey-version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.distributions</groupId>
            <artifactId>web-all</artifactId>
            <version>10.0-build-20080430</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.embedded</groupId>
            <artifactId>gf-embedded-api</artifactId>
            <version>1.0-alpha-4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.random.commons</groupId>
            <artifactId>utils</artifactId>
            <version>1.0</version>
        </dependency>
     <dependency>
        <groupId>com.random.services</groupId>
        <artifactId>xyz1</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>       
    </dependencies>
    <properties>
        <jersey-version>1.13</jersey-version>
    </properties>
    <repositories>
        <repository>
            <id>glassfish.java.net</id>
            <name>GlassFish Maven Repository</name>
            <url>http://download.java.net/maven/glassfish</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>m2.java.net</id>
            <name>Java.net Maven 2 Repository</name>
            <url>http://download.java.net/maven/2</url>
            <layout>default</layout>
        </pluginRepository>
    </pluginRepositories>
</project>

1 个答案:

答案 0 :(得分:0)

这解决了我的问题:

使用-X开关运行mvn。它表明sisu-inject模块没有有效的pom。此模块位于~/.m2/repository/org/sonatype directory

已删除~/.m2/repository/org/sonatype directory

重新构建并解决了问题。