Programming Java with Vim
Solution 1:
You need Java SE Development Kit (JDK) to develop Java. Download JDK 6 Update 14 from the page. Modify your path to include bin
folder so you can call javac
, the Java compiler and java
command. Another tool you wanna learn is ant, which lets you compile multiple files all at once, run tests, etc.. Also see Configure vi for Java application development.
Edit: Adding link to What are the necessary environment variables one should set after installing JDK on Windows and how?
Solution 2:
Can I suggest that you use a decent IDE, and a VIM plugin? I used to be a VIM diehard, and only recently switched to using Eclipse with a VIM editor plugin.
Why? The productivity gains of using a modern IDE are enormous. For example, once you're able to navigate through the code by structure type (e.g. method call to list of implementations etc.) then the ctags
mechanism in VIM just isn't enough. Once you use more than a couple of libraries (or stuff you're not familiar with) then the code completion / method suggestion / doc navigation will save you a world of grief.
However I love the VIM method of keyboard navigation etc. Hence I use an IDE with an appropriate plugin.
Here's an answer I provided to a very similar question. That contains the link to the Eclipse VIM plugin. It's not free, but will pay for itself very quickly.
Solution 3:
Except for the JDK as mentioned by other answers, you might also want to try eclim. It makes VI a full Java IDE.
Solution 4:
As eed3si9n points out, you will need the JDK in order to start compiling your Java programs. But your question seems to be more about setting up your editor so that you can automatically compile Java programs from within it.
There are a couple of ways to approach this, of course. The easiest way is to work out a single command to build the project. In Java, most large projects are compiled with ant, and learning how to use that will serve you very well in the long term.
Once you've set up ant (http://ant.apache.org/manual/install.html to start), you can set vi to automatically call it via the ":make" command, by putting in your _vimrc file:
set makeprg=C:\path-to-ant\ant
So the steps should be:
(1) Get the JDK and learn how to use that.
(2) Get ant and learn how to use that. (*)
(3) Set your vimrc up so that it knows to invoke ant when you type :make.
As always, setting up a system to automate something (like your compiles) is easier when you're already proficient at doing it manually.
(*) Note: My vim doesn't have the javac command, so I'm not sure how to configure the vim options necessary to make sure you load it. If nothing else, it would be good to make sure that your javac was in your PATH at the time you load the editor.
Best wishes!