gpt4 book ai didi

java - 运行 war 文件时 Maven 构建错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:15 26 4
gpt4 key购买 nike

当我尝试运行 war 文件时,我收到 Maven 构建错误,其中显示 *无法获取依赖项信息:无法读取 Artifact 的元数据文件。当我这样做时"mvn clean install"我没有收到任何错误并且构建运行良好。运行war文件的命令是mvn -e clean jetty:run-war -Denv=<directory> .

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

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

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 开关错误:

[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>

最佳答案

这解决了我的问题:

使用 -X 开关运行 mvn。它表明 sisu-inject 模块没有有效的 pom.xml 文件。该模块位于 ~/.m2/repository/org/sonatype 目录

已删除~/.m2/repository/org/sonatype目录

重新运行构建,问题已解决。

关于java - 运行 war 文件时 Maven 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31240370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com