0

I am using Maven Buildin Eclipse IDE for a Spring project for uploading files.SPRING. The error is arising from

1-Plugin. I deleted the maven-compiler plugin from /.m2 directory (Windows), but the error still exist. The usual consensus is to delete whole ./m2 directory which is not feasible as I have other projects.

2- The FileUploadTest.java seems to be giving out a lot of errors. Is this due to corrupted jars or error in my pom.xml file?

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

Here is my pom.xml file

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

szfs
  • 1
  • 1

1 Answers1

1

In Maven, test classes have not to be located in the src/main/java directory but in the src/test/java directory.
src/test/java is indeed the test source directory and only classes located here can use dependencies specified with the test scope.

So all your test classes using classes of this dependency cannot compile :

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

Move your test classes in src/test/java and it should solve a large part of your issue.

This introduction on the directory layout of Maven could probably help you.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
  • I moved but import com.mastercard.ayman.image.storage.StorageFileNotFoundException; import com.mastercard.ayman.image.storage.StorageService; canot be resolved. Should I move the *.storage to test folder as well? – szfs Jun 14 '18 at 06:09
  • Applicative classes have to be in `src/main/java`. And classes in `src/main/java` are usable by classes in `src/test/java`. So it means that these classes are probably not there or not in the correct package. Check that. – davidxxx Jun 14 '18 at 06:18
  • Now on Spring App I am getting this error Description: Parameter 0 of constructor in com.mastercard.ayman.image.FileUploadController required a bean of type 'com.mastercard.ayman.image.storage.StorageService' that could not be found. Action: Consider defining a bean of type 'com.ayman.image.storage.StorageService' in your configuration. I have Component Scan for the Bean. in SpringBootApplication Why is the error? – szfs Jun 14 '18 at 07:26
  • It is a runtime error, so a distinct problem. Please open a new question and specify all relevant information. Someone will very probably address it. – davidxxx Jun 14 '18 at 07:28