Java / Maven无法编译简单的代码

时间:2013-08-30 17:27:30

标签: string maven java

这个非常简单的代码根本无法编译。我不是一个Java专家,但我很确定这是标准的东西,应该可以工作!

String fields = "a,b,c";
String[] fields_array = fields.split(',');

无法编译

mvn test clean

cannot find symbol symbol  : method split(char)
location: class java.lang.String

的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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>simple-service</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>simple-service</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
        </dependency>
         <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>de.abas.ceks</groupId>
            <artifactId>jedp</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>de.abas.jfop</groupId>
            <artifactId>base</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>de.abas.eks</groupId>
            <artifactId>jfop</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>de.abas.erp</groupId>
            <artifactId>common</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency> 
            <groupId>net.sourceforge.javautil</groupId> 
            <artifactId>common</artifactId> 
            <version>0.0.5</version> 
            <scope>compile</scope> 
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <!-- <inherited>true</inherited> -->
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.example.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository> 
            <id>javautil</id> 
            <name>Java Util Repository</name> 
            <url>http://downloads.sourceforge.net/project/javautil/</url> 
        </repository>
    </repositories>

    <properties>
        <jersey.version>2.2</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

进口

package com.example;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.QueryParam;

import de.abas.ceks.jedp.*;

import java.lang.String;

1 个答案:

答案 0 :(得分:6)

String#split()方法接受一个字符串,','是一个字符。字符串文字用双引号括起来。你应该使用:

String[] fields_array = fields.split(",");

PS:您不需要从java.lang包导入类。默认情况下,该包在所有Java源文件中导入。