繁体   English   中英

使用maven打包Java代码时出现类,接口或枚举预期的错误

[英]class, interface, or enum expected error when packaging java code with maven

我正在尝试使用Maven编译一些Java代码以在Spark上运行。 除了帮助程序类,我所有的代码都在我的主要方法中。 我觉得问题是我没有在正确的位置定义班级。 我尝试将其放在main方法内,具有main方法的类之后,在类之前。 我需要一个单独的文件来放置此类吗? 当我跑步

mvn package

我得到:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-    plugin:2.0.2:compile (default-compile) on project simple-project: Compilation failure: Compilation failure:
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:   [10,7] class, interface, or enum expected
[ERROR] 
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:[12,11] class, interface, or enum expected
[ERROR] 
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:[14,9] class, interface, or enum expected
[ERROR] 
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:[15,4] class, interface, or enum expected
[ERROR] 
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:[17,11] class, interface, or enum expected
[ERROR] 
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:[19,4] class, interface, or enum expected
[ERROR] 
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:[21,11] class, interface, or enum expected
[ERROR] 
[ERROR] /home/peter/Desktop/spark/spark-1.1.0/sent-svm/src/main/java/GenClassifiers.java:[23,4] class, interface, or enum expected
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal    org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project   simple-project: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at     org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilde    r.java:84)
at      org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilde    r.java:59)
at     org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.jav    a:183)
at     org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:622)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
at     org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:    101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
[ERROR] 
[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

这是我当前的代码,尝试先放置类,然后再放置其余代码:

/* SimpleApp.java */
import org.apache.spark.api.java.*;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.function.Function;
import cmu.arktweetnlp.Twokenize;
import java.util.*;
import java.io.*;


public Class Tweet {

    public Tweet(List<String> tokens, String sentiment) {
        private List<String> tweetTokens = tokens;
        private String label = sentiment;
    }

    public List<String> getTokens() {
        return tweetTokens;
    }

    public String getLabel() {
        return label;
    }
}


public class GenClassifiers {
    public static void main(String[] args) {

您有错字:

public Class Tweet {

代替

public class Tweet {

此外,在同一Java文件中定义的公共类不能超过一个。 公共类应与文件名相同。 因此,您需要在自己的文件中定义TweetGenClassifiers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM