Java错误:找不到符号:方法连接(java.lang.String,java.lang.String [])

时间:2017-12-28 20:13:57

标签: java tomcat tomcat7 ami

我在远程ami实例上的tomcat服务器(v.7)上运行了项目。

当我尝试编译项目并在本地生成.war文件时,没有问题。

但是当我尝试在远程ami实例上做同样的事情时,我收到以下错误:

  

[INFO] -------------------------------------------- -----------------   [信息]   -------------------------------------------------- ---------------------- [INFO] BUILD FAILURE [INFO]   -------------------------------------------------- ---------------------- [INFO]总时间:21.963秒[INFO]完成于:Thu Dec 28 20:01:58 UTC   2017 [INFO]最终记忆:114M / 1431M [INFO]   -------------------------------------------------- ---------------------- [错误]无法执行目标   org.apache.maven.plugins:Maven的编译器插件:3.3:编译   项目wildbook上的(default-compile):编译失败:   编译失败:[错误]   /home/ubuntu/Wildbook_javaTweetBot/src/main/java/org/ecocean/servlet/ServletUtilities.java:[866,24]   找不到符号[ERROR]符号:方法   join(java.lang.String,java.lang.String [])[ERROR] location:class   java.lang.String中

ServletUtilities.java的第866行内容如下:

String text2 = String.join(" ", text1);

对于上下文,这是围绕它的代码块:

text = text.replaceAll("[,.!?;:]", "$0 ");
System.out.println("text: " + text);
String[] text1 = text.replaceAll("[^A-Za-z0-9 ]", "").toLowerCase().split("\\s+"); //TODO I think this does a better version of what the above (text = text.replaceAll("[,.!?;:]", "$0 ");) does??
String text2 = String.join(" ", text1);

我在javarepl本地运行此代码没有问题(我正在使用"等等这是测试12/28/2018"因为我的文本字符串(String text是传递的参数到上面的代码所在的方法。)

ami实例上的java版本是:

  

openjdk version" 1.8.0_91" OpenJDK运行时环境(构建   1.8.0_91-8u91-b14-0ubuntu4~14.04-b14)OpenJDK 64位服务器VM(内置25.91-b14,混合模式)

mvn -version收益:

  

Apache Maven 3.0.5 Maven主页:/ usr / share / maven Java版本:   1.8.0_91,供应商:Oracle Corporation Java home:/ usr / lib / jvm / java-8-openjdk-amd64 / jre默认语言环境:en_US,platform   编码:UTF-8操作系统名称:" linux",版本:" 3.13.0-48-generic",arch:   " amd64",家庭:" unix"

有谁知道为什么会发生这种情况/有关于我可以采取哪些措施来解决下一步问题的建议?

1 个答案:

答案 0 :(得分:0)

我无法重现您的问题。我的目录结构如下:

.
├── pom.xml
└── src
    └── main
        ├── java
        │   └── com
        │       └── example
        │           └── maven
        │               └── TestServlet.java
        └── webapp
            └── WEB-INF
                └── web.xml

我的pom.xml是:

<?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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.maven</groupId>
    <artifactId>compile-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                    <compilerArgument>-Xlint:all</compilerArgument>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我在使用Tomcat 7时猜测了servlet规范的3.0版本。我的代码很简单:

@WebServlet(name = "TestServlet", urlPatterns = {"/testServlet"})
public class TestServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String [] blah = {"a", "b", "c"};
        String result = String.join("-", blah);

        response.setContentType("text/plain");
        response.getWriter().println("join result is =\"" + result + "\"");
    }
}

Maven是:

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 06:51:28-0700)
Maven home: /home/scott/Downloads/apache-maven-3.0.5
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.10.0-38-generic", arch: "amd64", family: "unix"

我无法找到完全相同的JDK - 我正在使用:

openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

您可以发布最少量的代码来重现您的问题吗?

修改 - 我知道这是一种评论,但评论中不可能提供这么多信息。