Vim Syntastic无法识别当前项目中的Java类

7

使用Vim Syntastic来处理Android项目(例如com.myproject.project)。它不能识别在当前文件之外但在我的项目中声明的类。例如,下面的代码会出现错误:

import com.myproject.project.SomeClass;
...
SomeClass someclass = new SomeClass();

Syntastic只是Vim和许多外部程序之间的中间人。您应该1. 找出用于检查代码的程序,2. 在其文档中寻找使其更智能化的方法,3. 看看是否可以配置Syntastic。 - romainl
很可能是因为你从错误的目录运行javac,导致它感到困惑。 - FDinoff
谢谢。我正在与You Complete Me (YCM)结合使用它。 - lorean
请确保您从正确的上下文中运行它(即确保在vim中“cd”到正确的项目根目录)。此外,您可以通过在项目根目录中创建一个 .syntastic_javac_config 文件来指定 Syntastic 使用的类路径。添加 ./classes 或您的类所在的任何位置应该可以解决这个问题。 - Troy Patrick
2个回答

10

看到了这篇文章“如何配置Syntastic以使其适用于Android项目”,可以解决问题:

方法一:
在vim编辑器内执行以下命令:

:SyntasticJavacEditClasspath

然后将以下内容添加到缓冲窗口中

/path-to-your-app/bin/classes  
/path-to-your-android-sdk/platforms/android-19/*.jar

方法2:
将以下内容添加到 .vimrc 文件中:

let g:syntastic_java_javac_classpath = "/<path-to-your-app>/bin/classes:/<path-to-your-android-sdk>/platforms/android-19/*.jar"

2
关于方法2!我不知道是否有人和我遇到了相同的情况,但我曾尝试使用“:”来分隔多个类路径,但它不起作用,所以我尝试使用“\n”,它可以工作。例如:“/<path-to-your-app>/bin/classes\n/<path-to-your-android-sdk>/platforms/android-19/*.jar”。记住只需将“:”替换为“\n”,不要添加其他任何内容。 - minh truong

1
这是一个关于在Linux vim7.4和Syntastic3.7.0-224中适用的各种方法总结,以下是我使用过的一些方法,同时也感谢每个方法的作者。
方法1 - 手动创建 .syntastic_javac_config 文件。
1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_config_file_enabled = 1

2. Where you edit your vim files, add this to a file named .syntastic_javac_config

let g:syntastic_java_javac_classpath = '/home/davis/progs/princeton-algos/week1/libs/algs4.jar'

方法二 - 无论您在何处编辑类路径,都具有优势。

1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_classpath = "/home/davis/progs/princeton-algos/week1/libs/algs4.jar"

这个操作添加了jar包。
方法3 - 自动生成.syntastic_javac_config文件。
1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_config_file_enabled = 1
2. Edit a java file with vim
3. :SyntasticJavacEditClasspath
When the edit window opens, add the class path without quotes and a newline after each entry the class path. In my case, this is the entry
for the setting includes the current folder as well:
/home/davis/progs/princeton-algos/week1/libs/algs4.jar
.
4 :wq the edit setting window
5. Now the class path is set for syntastic when editing files from that location. If you edit from a new directory, you will need to repeat the process.

除了上面的评论,这篇文章也有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接