mvn包找不到依赖项?

时间:2018-10-07 08:27:06

标签: eclipse maven

我可以从Eclipse run as-> maven build ..运行“ clean package”命令,并且没有错。战争文件已正确创建并部署,也不成问题。

但是,如果我尝试在控制台上使用mvn软件包,则会出现以下错误:

$ mvn package
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.kutar:example:war:1.0
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-war-plugin is missing. @ line 107, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------------< com.kutar:example >--------------------------
[INFO] Building example 1.0
[INFO] --------------------------------[ war ]---------------------------------
[WARNING] The POM for org.hibernate.validator:hibernate-validator:jar:6.0.7.Final is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The artifact org.hibernate:hibernate-validator-cdi:jar:6.0.13.Final has been relocated to org.hibernate.validator:hibernate-validator-cdi:jar:6.0.13.Final
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ example ---
[WARNING] Using platform encoding (MS949 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ example ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 13 source files to D:\my workspace\java\jsp\jspWithMaven\example\target\classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java: D:\my workspace\java\jsp\jspWithMaven\example\src\main\java\com\kutar\user\User.java uses or overrides a deprecated API.
[WARNING] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java: Recompile with -Xlint:deprecation for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[13,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[14,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[3,36] package javax.validation.constraints does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[4,36] package javax.validation.constraints does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[3,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[4,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[5,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[9,23] cannot find symbol
  symbol:   class Validator
  location: class com.kutar.support.MyValidatorFactory
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[14,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[15,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[9,10] cannot find symbol
  symbol:   class NotNull
  location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[10,10] cannot find symbol
  symbol:   class Size
  location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[13,10] cannot find symbol
  symbol:   class NotNull
  location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[14,10] cannot find symbol
  symbol:   class Size
  location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[17,10] cannot find symbol
  symbol:   class NotNull
  location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[18,10] cannot find symbol
  symbol:   class Size
  location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[37,17] cannot find symbol
  symbol:   class Validator
  location: class com.kutar.user.CreateUserServlet
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[38,21] cannot find symbol
  symbol:   class ConstraintViolation
  location: class com.kutar.user.CreateUserServlet
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[10,17] cannot find symbol
  symbol:   class ValidatorFactory
  location: class com.kutar.support.MyValidatorFactory
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[10,44] cannot find symbol
  symbol:   variable Validation
  location: class com.kutar.support.MyValidatorFactory
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[51,17] cannot find symbol
  symbol:   class Validator
  location: class com.kutar.user.UpdateUserServlet
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[52,21] cannot find symbol
  symbol:   class ConstraintViolation
  location: class com.kutar.user.UpdateUserServlet
[INFO] 22 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.018 s
[INFO] Finished at: 2018-10-07T17:01:20+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project example: Compilation failure: Compilation failure:
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[13,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[14,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[3,36] package javax.validation.constraints does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[4,36] package javax.validation.constraints does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[3,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[4,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[5,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[9,23] cannot find symbol
[ERROR]   symbol:   class Validator
[ERROR]   location: class com.kutar.support.MyValidatorFactory
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[14,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[15,24] package javax.validation does not exist
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[9,10] cannot find symbol
[ERROR]   symbol:   class NotNull
[ERROR]   location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[10,10] cannot find symbol
[ERROR]   symbol:   class Size
[ERROR]   location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[13,10] cannot find symbol
[ERROR]   symbol:   class NotNull
[ERROR]   location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[14,10] cannot find symbol
[ERROR]   symbol:   class Size
[ERROR]   location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[17,10] cannot find symbol
[ERROR]   symbol:   class NotNull
[ERROR]   location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/User.java:[18,10] cannot find symbol
[ERROR]   symbol:   class Size
[ERROR]   location: class com.kutar.user.User
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[37,17] cannot find symbol
[ERROR]   symbol:   class Validator
[ERROR]   location: class com.kutar.user.CreateUserServlet
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/CreateUserServlet.java:[38,21] cannot find symbol
[ERROR]   symbol:   class ConstraintViolation
[ERROR]   location: class com.kutar.user.CreateUserServlet
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[10,17] cannot find symbol
[ERROR]   symbol:   class ValidatorFactory
[ERROR]   location: class com.kutar.support.MyValidatorFactory
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/support/MyValidatorFactory.java:[10,44] cannot find symbol
[ERROR]   symbol:   variable Validation
[ERROR]   location: class com.kutar.support.MyValidatorFactory
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[51,17] cannot find symbol
[ERROR]   symbol:   class Validator
[ERROR]   location: class com.kutar.user.UpdateUserServlet
[ERROR] /D:/my workspace/java/jsp/jspWithMaven/example/src/main/java/com/kutar/user/UpdateUserServlet.java:[52,21] cannot find symbol
[ERROR]   symbol:   class ConstraintViolation
[ERROR]   location: class com.kutar.user.UpdateUserServlet
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

这是我的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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.kutar</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.0.7.Final</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.el</artifactId>
            <version>3.0.1-b09</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator-cdi</artifactId>
            <version>6.0.13.Final</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
            <scope>compile</scope>
        </dependency>

        <!-- MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.12</version>
            <scope>compile</scope>
        </dependency>


    </dependencies>

    <build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin> 

            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <wtpversion>2.0</wtpversion>
                    <wtpContextName>/</wtpContextName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

MAVEN_HOME和Path配置正确,我的存储库位于C:\ Users \ username.m2 \ repository。但是我认为控制台的专家似乎无法找到我的存储库。我能做什么 ?

1 个答案:

答案 0 :(得分:0)

这可能是因为您的日食和控制台未使用同一JDK。运行

mvn —version

并确保输出相同-如果不是,那就是问题所在。