我已经阅读了所有关于“找不到符号”maven错误的问题,但我想它们不适合我。
首先,我使用Eclipse开发了一个教育项目。这是一个简单的聊天,可以在github上访问。它的编译和运行都很好,但现在我需要使用Maven而不是Eclipse来编译它。我运行“mvn清理”、“mvn验证”(均成功)。然后,mvn编译,我得到错误:
C:\Users\fresh\Documents\git\SpringBootThymeleaf\SpringBootThymeleaf>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< ru.aconsultant:SpringBootThymeleaf >-----------------
[INFO] Building SpringBootThymeleaf 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ SpringBootThymeleaf ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 22 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ SpringBootThymeleaf ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 21 source files to C:\Users\fresh\Documents\git\SpringBootThymeleaf\SpringBootThymeleaf\target\classes
[INFO] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/controller/WebSocketConfiguration.java: C:\Users\fresh\Documents\git\SpringBootThymeleaf\SpringBootThymeleaf\src\main\java\ru\aconsultant\thymeleaf\controller\WebSocketConfiguration.java uses unchecked or unsafe operations.
[INFO] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/controller/WebSocketConfiguration.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/service/FileProcessor.java:[158,43] cannot find symbol
symbol: method readAllBytes()
location: variable inputStream of type java.io.InputStream
[ERROR] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/service/FileProcessor.java:[172,51] cannot find symbol
symbol: method readAllBytes()
location: variable inputStream of type java.io.InputStream
[ERROR] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/service/FileProcessor.java:[201,43] cannot find symbol
symbol: method readAllBytes()
location: variable inputStream of type java.io.InputStream
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.669 s
[INFO] Finished at: 2020-06-17T10:48:00+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project SpringBootThymeleaf: Compilation failure: Compilation failure:
[ERROR] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/service/FileProcessor.java:[158,43] cannot find symbol
[ERROR] symbol: method readAllBytes()
[ERROR] location: variable inputStream of type java.io.InputStream
[ERROR] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/service/FileProcessor.java:[172,51] cannot find symbol
[ERROR] symbol: method readAllBytes()
[ERROR] location: variable inputStream of type java.io.InputStream
[ERROR] /C:/Users/fresh/Documents/git/SpringBootThymeleaf/SpringBootThymeleaf/src/main/java/ru/aconsultant/thymeleaf/service/FileProcessor.java:[201,43] cannot find symbol
[ERROR] symbol: method readAllBytes()
[ERROR] location: variable inputStream of type java.io.InputStream
[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
此外,在那之后,即使是Eclipse也无法正确运行项目。附加字符串出现在起始日志中:
2020-06-17 11:20:15.433 INFO 16244 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: fe0f803b-2116-43b6-910c-47e5b11b168b
出现了一些默认的Spring Security登录页面,而不是我的自定义登录页面。当我制作“项目-
如果我通过Eclipse清理并运行项目,而不是使用maven(不使用mvn清理)编译它,那么它也是成功的。
我完全意识到依赖项或导入有一些不好的地方,但我无法找到确切的原因。我甚至用相同的POM创建了一个新项目-maven成功地编译了它。我提供以下POM:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ru.aconsultant</groupId>
<artifactId>SpringBootThymeleaf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringBootThymeleaf</name>
<description>Spring Boot and Thymeleaf</description>
<properties>
<java.version>1.8</java.version>
<spring-security.version>5.3.2.RELEASE</spring-security.version>
<spring.version>5.0.6.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.36</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<scope>runtime</scope>
</dependency>
<!-- #refactor -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<!-- file processing -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
谢谢你的建议!
问题出在java版本中。方法readAllBytes()仅从第9个jdk支持。我没有提到它,因为我的POM中有java版本1.8,但Eclipse在其安装的库中有jdk 14,并以某种方式将其用于编译。
由于某种原因,此命令在我的本地计算机上运行良好: 但是,对于Codeship,它现在起作用了,并抛出这个“无法找到符号”错误。在Codeship中,完整命令为: 在POM中,存储库具有以下内容: 错误:
我无法从命令行编译Maven项目。我使用的是Maven版本: Apache Maven 3.5.4 null 这是我的pom.xml(没有依赖项): 新的堆栈跟踪是:
问题:无法使用带有JDK 1.8的Jenkins构建Spring maven项目 描述:我使用Jenkins构建我的Spring项目,由Maven管理。我已经使用JDK安装选项在Jenkins中配置了Java 1.7和1.8。当在构建配置中选择Java 1.7并运行构建时,构建过程是成功的。但当我在构建配置中选择Java 1.8并运行构建时,构建过程会失败。 下面是 jenkins 控制台输出**
问题内容: 当代码到达递归调用增量时,我收到错误找不到符号,我不知道为什么?这是增量代码。任何帮助将不胜感激。 编辑:我真的是Java的新手,所以可以做的答案越基本越好。好的,所以我收到的错误是:BigNatural.java.35:找不到符号符号方法增量()位置:类java.lang.String temp.increment() 并在此处清除所有其他问题,是整个代码。 }公共类BigNatur
这是一个非常简单的网页抓取程序,我用intellij的想法和maven构建系统构建的。它在今天之前工作得很好,但是当我今天试图构建它的时候,它给了我对象没有找到基本java对象的错误,比如字符串和列表。当我试图重新加载maven项目时,我得到了下面的另一个错误。idea也用红色突出了基本的java对象,没有给出任何建议。我做的唯一一件事是稍微修改了java源代码。所以,我用股票你好世界代码进行了测
问题内容: 嘿,我刚开始我的第一本Java编程书籍,所以这应该很容易解决。弄乱我对条件句的新知识,发现标题错误。 这是代码: 当我尝试编译时: 问题答案: 错误消息告诉您变量“输入”在您的作用域中不存在。您可能想使用Scanner对象,但将其命名为“ x”,而不是“ input”。 应该修复它。