【问题标题】:maven not creating jar correctly, creates folder instead?maven 没有正确创建 jar,而是创建文件夹?
【发布时间】:2015-09-25 17:37:32
【问题描述】:

我的本​​地存储库中有一个依赖项 jReddit.jar。当我构建在其 pom 中引用 jReddit 的项目时,我在服务器启动时不断收到错误,因为它在目标 web inf 中找不到 jReddit.jar。我检查了目标 web inf,jReddit 在那里,只有一个文件夹而不是 jar。它看起来像“jReddit.jar”,但它是一个文件夹而不是一个 jar。如果我将实际的 jar 复制并粘贴到我的服务器中,它可以工作,但我需要它才能正确构建。在我的本地仓库中,jReddit 以 jar 的形式存在,看起来很正常。

我不确定为什么会发生这种情况,因为前一天一切正常,然后我无法正确构建或部署。

          <dependency>
            <groupId>com.github.jreddit</groupId>
            <artifactId>jreddit</artifactId>
            <version>1.0.5</version>
    </dependency>

自从它坏了我就没有改变它,所以我认为它很好

整个绒球

<?xml version="1.0" encoding="UTF-8"?>
<!--
    JBoss, Home of Professional Open Source
    Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
    contributors by the @authors tag. See the copyright.txt in the
    distribution for a full listing of individual contributors.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<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>org.jreddit.service</groupId>
    <artifactId>jRedditService</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>WildFly Quickstarts: jRedditService</name>
    <description>A starter Java EE 7 webapp project for use on JBoss WildFly / WildFly, generated from the jboss-javaee6-webapp archetype</description>

    <url>http://wildfly.org</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.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

        <!-- Define the version of the JBoss BOMs we want to import to specify 
            tested stacks. -->
        <version.jboss.bom>8.2.1.Final</version.jboss.bom>

        <!-- other plugin versions -->
        <version.compiler.plugin>3.1</version.compiler.plugin>
        <version.surefire.plugin>2.16</version.surefire.plugin>
        <version.war.plugin>2.5</version.war.plugin>

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


    <dependencyManagement>
        <dependencies>
            <!-- JBoss distributes a complete set of Java EE 7 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-7.0-with-tools stack (you can
                read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
                for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
                stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
                from the Hibernate family of projects) -->
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-tools</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

              <dependency>
                <groupId>com.github.jreddit</groupId>
                <artifactId>jreddit</artifactId>
                <version>1.0.5</version>
<!--                 <scope>provided</scope>                 -->
        </dependency>

        <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.5.4</version>
</dependency>
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1</version>
</dependency>

        <!-- First declare the APIs we depend on and need for compilation. All 
            of them are provided by JBoss WildFly -->

        <!-- Import the CDI API, we use provided scope as the API is included in 
            JBoss WildFly -->
        <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 WildFly -->
        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.2_spec</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Import the JAX-RS API, we use provided scope as the API is included 
            in JBoss WildFly -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Import the JPA API, we use provided scope as the API is included in 
            JBoss WildFly -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Import the EJB API, we use provided scope as the API is included in 
            JBoss WildFly -->
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.2_spec</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- JSR-303 (Bean Validation) Implementation -->
        <!-- Provides portable constraints such as @Email -->
        <!-- Hibernate Validator is shipped in JBoss WildFly -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Import the JSF API, we use provided scope as the API is included in 
            JBoss WildFly -->
        <dependency>
            <groupId>org.jboss.spec.javax.faces</groupId>
            <artifactId>jboss-jsf-api_2.2_spec</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Now we declare any tools needed -->

        <!-- Annotation processor to generate the JPA 2.0 metamodel classes for 
            typesafe criteria queries -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Annotation processor that raising compilation errors whenever constraint 
            annotations are incorrectly used. -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator-annotation-processor</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Needed for running tests (you may also use TestNG) -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Optional, but highly recommended -->
        <!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA) 
            JPA from JUnit/TestNG -->
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.protocol</groupId>
            <artifactId>arquillian-protocol-servlet</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <!-- Maven will append the version to the finalName (which is the name 
            given to the generated war, and hence the context root) -->
        <finalName>${project.artifactId}</finalName>
        <plugins>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
              <archive>
                <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>org.jReddit.service.rest.JaxRsActivator</mainClass>
                <classpathPrefix>dependency-jars/</classpathPrefix>
                </manifest>
              </archive>
            </configuration>
          </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>${version.war.plugin}</version>
                <configuration>
                          <failOnMissingWebXml>false</failOnMissingWebXml>

                    <archive>
                        <manifest>
                          <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>


            <!-- The WildFly plugin deploys your war to a local WildFly container -->
            <!-- To use, run: mvn package wildfly:deploy -->
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>${version.wildfly.maven.plugin}</version>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- The default profile skips all tests, though you can tune it to run 
                just unit tests based on a custom pattern -->
            <!-- Seperate profiles are provided for running all tests, including Arquillian 
                tests that execute in the specified container -->
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${version.surefire.plugin}</version>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>

            <!-- An optional Arquillian testing profile that executes tests
                in your WildFly instance -->
            <!--

此配置文件将启动一个新的 WildFly 实例,并执行 测试,完成后关闭 --> arq-wildfly 管理 org.wildfly wildfly-arquillian-container-managed 测试

    <profile>
        <!-- An optional Arquillian testing profile that executes tests
            in a remote WildFly instance -->
        <!-- Run with: mvn clean test -Parq-wildfly-remote -->
        <id>arq-wildfly-remote</id>
        <dependencies>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-arquillian-container-remote</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>


</profiles>

这是相关的 jReddits pom

   <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>7</version>
    </parent>

<groupId>com.github.jreddit</groupId>
<artifactId>jreddit</artifactId>
<version>1.0.5</version>
<name>jReddit</name>
<description>jReddit is a wrapper for the Reddit API written in Java.      </description>
<url>https://github.com/karan/jReddit</url>

Imgur

【问题讨论】:

  • 你能发布你的 POM 或至少它的 jreddit 依赖部分吗?
  • 我通过编辑更新了 OP
  • 其他依赖 jar 是否正常显示?
  • 提供treeWEB-INF/lib 输出。
  • 你说的真的很奇怪。发布整个 POM,以便我们可以重现它。是Maven建的war里面的文件夹吗?您确定您没有更改机器上的设置,使它看起来像一个 jar 是一个文件夹?

标签: java maven jar


【解决方案1】:

我知道很久以前就有人问过这个问题,但是由于我遇到了这个问题,并且我在 Stackoverflow 上没有找到任何关于此的信息,所以我会自己回答。

基本上,当您创建 JAR 文件的依赖项项目在您的 IDE 上仍处于打开状态时,就会发生这种情况。

这是因为如果您对依赖项进行更改,则不需要使用mvn packagemvn install,如果您关闭依赖项项目,您会看到该文件夹​​将变成正确的 JAR 文件预期,您的主项目将从您的 m2 文件夹中读取 jar。

【讨论】:

    猜你喜欢
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2018-09-03
    相关资源
    最近更新 更多