Maven构建JBoss AS 7 Hello world示例失败

7
我正在尝试遵循这个教程:https://docs.jboss.org/author/display/AS7/Helloworld+quickstart,但是在按照清理 + 构建包的简单指示时出现了构建错误,以下是需要翻译的内容:

gert@gert-VirtualBox:~/workspace/jboss-eap-6.1.0.GA-quickstarts/helloworld$ mvn clean package [INFO] Scanning for projects... [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project org.jboss.as.quickstarts:jboss-as-helloworld:7.1.2-SNAPSHOT (/home/gert/workspace/jboss-eap-6.1.0.GA-quickstarts/helloworld/pom.xml) has 4 errors [ERROR] Non-resolvable import POM: Failure to find org.jboss.spec:jboss-javaee-6.0:pom:3.0.2.Final-redhat-3 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced @ line 68, column 25 -> [Help 2]

我没有编辑过pom.xml文件,这不应该正常运行吗?我已经在谷歌上搜索到了这个:https://community.jboss.org/message/762371#762371,但我似乎没有任何地方有设置文件。请帮忙解决,谢谢!

http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0

<groupId>org.jboss.as.quickstarts</groupId>
<artifactId>jboss-as-helloworld</artifactId>
<version>7.1.2-SNAPSHOT</version>
<packaging>war</packaging>
<name>JBoss AS Quickstarts: Helloworld</name>
<description>JBoss AS Quickstarts: Helloworld</description>

<url>http://jboss.org/jbossas</url>
<licenses>
    <license>
        <name>Apache License, Version 2.0</name>
        <distribution>repo</distribution>
        <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
    </license>
</licenses>

<properties>
    <!-- Explicitly declaring the source encoding eliminates the following 
        message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
        resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- JBoss dependency versions -->

    <version.org.jboss.as.plugins.maven.plugin>7.3.Final</version.org.jboss.as.plugins.maven.plugin>

    <!-- <version.org.jboss.spec.jboss.javaee.6.0>3.0.2.Final</version.org.jboss.spec.jboss.javaee.6.0>

--> 3.0.2.Final-redhat-3

    <!-- other plugin versions -->
    <version.compiler.plugin>2.3.1</version.compiler.plugin>
    <version.war.plugin>2.1.1</version.war.plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.6</maven.compiler.target>
    <maven.compiler.source>1.6</maven.compiler.source>
</properties>

<dependencyManagement>
    <dependencies>
        <!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
        <!-- JBoss distributes a complete set of Java EE 6 APIs including
            a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
            a collection) of artifacts. We use this here so that we always get the correct
            versions of artifacts. Here we use the jboss-javaee-6.0 stack (you can
            read this as the JBoss stack of the Java EE 6 APIs). You can actually
            use this stack with any version of JBoss AS that implements Java EE 6, not
            just JBoss AS 7! -->
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>${version.org.jboss.spec.jboss.javaee.6.0}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!-- Import the CDI API, we use provided scope as the API is included in JBoss AS 7 -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the Common Annotations API (JSR-250), we use provided scope 
        as the API is included in JBoss AS 7 -->
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.1_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the Servlet API, we use provided scope as the API is included in JBoss AS 7 -->
    <dependency>
        <groupId>org.jboss.spec.javax.servlet</groupId>
        <artifactId>jboss-servlet-api_3.0_spec</artifactId>
        <scope>provided</scope>
    </dependency>

</dependencies>

<build>
    <!-- Set the name of the war, used as the context root when the app 
        is deployed -->
    <finalName>jboss-as-helloworld</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
                <!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <!-- JBoss AS plugin to deploy war -->
        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>${version.org.jboss.as.plugins.maven.plugin}</version>
        </plugin>
        <!-- Compiler plugin enforces Java 1.6 compatibility and activates 
            annotation processors -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${version.compiler.plugin}</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

4个回答

5
如果你从 Github 仓库克隆快速入门指南,如下所示:

git clone --recursive git://github.com/jboss-jdf/jboss-as-quickstart.git --branch jdf-2.1.9.Final

参见:http://www.jboss.org/jdf/quickstarts/get-started/

然后在根目录下(./jboss-as-quickstart/settings.xml)找到一个maven settings.xml文件。

对于每个示例,请使用该设置文件运行maven:

cd jboss-as-quickstart
cd helloworld
mvn -s ..\settings.xml compile

请参考:

查看:http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/#configure-maven


5

好的,这是解决方法:

注释掉pom.xml中的这一行:(我以为这是一种在eclipse/其他软件自动插入/替换的变量类型,结果不是):

<!--                 <version>${version.org.jboss.spec.jboss.javaee.6.0}</version> -->

替换为:

<version>3.0.2.Final</version>

现在已经成功构建并且可以顺利部署,感谢 Nishant 的帮助!


3

您可能需要创建一个(有关更多详细信息,请参见this page):

有两个位置可以存储settings.xml文件:

  • Maven安装:$M2_HOME/conf/settings.xml
  • 用户安装:${user.home}/.m2/settings.xml

但我觉得问题在于依赖项的版本字符串。请硬编码版本并重试:

<dependency>
    <groupId>org.jboss.spec</groupId>
    <artifactId>jboss-javaee-6.0</artifactId>
    <version>3.0.2.Final</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

取消以下行的注释可能也可以运行:
<version.org.jboss.spec.jboss.javaee.6.0>3.0.2.Final
    </version.org.jboss.spec.jboss.javaee.6.0>

谢谢Nishant - 你有什么想法可以放在这个settings.xml文件中来帮助解决这个问题吗?看起来它找不到jboss-javaee-6.0构件,但我可以在这里看到它:http://search.maven.org/#search%7Cga%7C1%7Cjboss-javaee-6.0 - gvanto
@user446043 我认为问题出在您的pom.xml中有一个随机字符串3.0.2.Final-redhat-3。该页面上没有此版本的工件。请先尝试硬编码版本解决方案。 - user2030471

1

删除RedHat的"postfix"后缀解决了问题,只需使用实际的jar名称,而不是带有RedHat后缀。

在您的pom.xml中添加以下依赖项,然后它将成功构建。

     <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-6.0</artifactId>
                <version>3.0.2.Final</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.0-SP4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.1_spec</artifactId>
            <version>1.0.1.Final</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.servlet</groupId>
            <artifactId>jboss-servlet-api_3.0_spec</artifactId>
            <version>1.0.2.Final</version>
            <scope>provided</scope>
        </dependency>
      </dependencies>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接