Eclipse中的Maven构建失败(测试和插件)

时间:2018-06-14 05:53:30

标签: maven spring-boot maven-eclipse-plugin

我使用Maven Buildin Eclipse IDE作为Spring项目来上传文件。SPRING

引起错误

1的插件。我从/.m2目录(Windows)中删除了maven-compiler插件,但错误仍然存​​在。通常的共识是删除整个./m2目录,这是不可行的,因为我有其他项目。

2- FileUploadTest.java似乎发出了很多错误。这是由于我的pom.xml文件中的jar文件损坏还是错误?

    [INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.910 s
[INFO] Finished at: 2018-06-14T11:03:01+05:30
[INFO] Final Memory: 32M/297M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project SpringMVCImage: Compilation failure: Compilation failure:
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[6,20] package org.hamcrest does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[7,17] package org.junit does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[8,24] package org.junit.runner does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[11,63] package org.springframework.boot.test.autoconfigure.web.servlet does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[12,45] package org.springframework.boot.test.context does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[13,50] package org.springframework.boot.test.mock.mockito does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[14,36] package org.springframework.mock.web does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[15,47] package org.springframework.test.context.junit4 does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[16,44] package org.springframework.test.web.servlet does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[18,26] package org.mockito does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[18,1] static import only from classes and interfaces
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[19,26] package org.mockito does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[19,1] static import only from classes and interfaces
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[20,59] package org.springframework.test.web.servlet.request does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[20,1] static import only from classes and interfaces
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[21,59] package org.springframework.test.web.servlet.request does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[21,1] static import only from classes and interfaces
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[22,58] package org.springframework.test.web.servlet.result does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[22,1] static import only from classes and interfaces
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[23,58] package org.springframework.test.web.servlet.result does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[23,1] static import only from classes and interfaces
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[24,58] package org.springframework.test.web.servlet.result does not exist
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[24,1] static import only from classes and interfaces
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[29,2] cannot find symbol
[ERROR] symbol: class RunWith
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[30,2] cannot find symbol
[ERROR] symbol: class AutoConfigureMockMvc
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[31,2] cannot find symbol
[ERROR] symbol: class SpringBootTest
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[35,13] cannot find symbol
[ERROR] symbol:   class MockMvc
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[37,6] cannot find symbol
[ERROR] symbol:   class MockBean
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[40,6] cannot find symbol
[ERROR] symbol:   class Test
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[51,6] cannot find symbol
[ERROR] symbol:   class Test
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[63,6] cannot find symbol
[ERROR] symbol:   class Test
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[42,9] cannot find symbol
[ERROR] symbol:   method given(java.util.stream.Stream<java.nio.file.Path>)
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[47,25] cannot find symbol
[ERROR] symbol:   variable Matchers
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[46,28] cannot find symbol
[ERROR] symbol:   method model()
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[45,46] cannot find symbol
[ERROR] symbol:   method status()
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[45,26] cannot find symbol
[ERROR] symbol:   method get(java.lang.String)
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[53,9] cannot find symbol
[ERROR] symbol:   class MockMultipartFile
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[53,47] cannot find symbol
[ERROR] symbol:   class MockMultipartFile
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[57,28] cannot find symbol
[ERROR] symbol:   method header()
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[56,28] cannot find symbol
[ERROR] symbol:   method status()
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[55,26] cannot find symbol
[ERROR] symbol:   method fileUpload(java.lang.String)
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[59,9] cannot find symbol
[ERROR] symbol:   method then(com.ayman.image.storage.StorageService)
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[65,9] cannot find symbol
[ERROR] symbol:   method given(org.springframework.core.io.Resource)
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[68,60] cannot find symbol
[ERROR] symbol:   method status()
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] /C:/Users/workspace/SpringMVCImage/src/main/java/com/ayman/image/FileUploadTests.java:[68,26] cannot find symbol
[ERROR] symbol:   method get(java.lang.String)
[ERROR] location: class com.ayman.image.FileUploadTests
[ERROR] -> [Help 1]
[ERROR]  

这是我的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.ayman</groupId>
<artifactId>SpringMVCImage</artifactId>
 <version>0.0.1-SNAPSHOT</version>

 <properties>
    <start-class>com.ayman.image.Main</start-class>
  </properties>
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    </parent>


<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
<!--  Spring Mobile -->
    <dependency>
      <groupId>org.springframework.mobile</groupId>
       <artifactId>spring-mobile-device</artifactId>
       <version>1.1.5.RELEASE</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

1 个答案:

答案 0 :(得分:1)

在Maven中,测试类不能位于System.Window.Data Error目录中,而是位于src/main/java目录中。
src/test/java确实是测试源目录,只有位于此处的类可以使用src/test/java范围指定的依赖项。

所以使用此依赖项的所有测试类都无法编译:

test

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> 中移动您的测试类,它应解决您的大部分问题。

This introduction on the directory layout of Maven可能会帮助你。