简体   繁体   中英

Couldn't find or load main class error in VIM

I am quite new to VIM and trying to run a small java code to test whether its working or not but its showing error.

Error: Couldn't find or load main class test.java

This the command I used:

:!java test.java

My Code:

public class test{

    public static void main(string[] args){
        System.out.println("Hello world");
    }
}

I tried to fix it by following some some question in this site but couldn't make it. Ex: :!java -cp test.java

This is the the Java Plugin I installed for VIM LINK However, as the above plugin offers F5 to do all the process, its showing an error.

:!jikes + E test.java >c:\users\username\appdata\local\temp\VIeA690.tmp 2>&1 shell returned 1 (1 of 2): 'jikes' is not recognized as an internal or external command

So, I wonder if anyone could help on it.

You would have to compile the java source file then run the compiled class file:

javac test.java
java test

From within vim , the keystrokes would be:

:!javac test.java ; java test

but that's an awful lot to type in to compile and run. I'd tend to just open up another window and run a script (called something like x to minimise keystrokes) to compile and run, leaving me to only need saving in the vim window.

However, the plug-in you installed is supposed to make that easier by assigning the save, compile and run operations to a function key F5 so I'm not sure why you're not doing that.

Based on your comment that you're seeing:

javac is not recognized as an internal or external command, operable program or batch file

there's a very good chance you don't have a Java compiler installed. At a bare minimum, it's not in your path. You need to fix that first. While things like Eclipse come with their own compiler, you generally need to install and configure something like javac if you're using something like vim .

In any case, java runs class files - it doesn't compile source files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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