tags:

views:

329

answers:

5

Hi everyone.

I had previously asked a question about using Vim to develop Java, but I ended up realizing JDK works very well and that Ant is wayyy too much complicated for a starter like me. Things got a little bit clearer, and now I have a question again.

When I work with a file such as 'filename.java', I need to be able to use 'javac.exe', which is in the Java Development Kit (JDK), on 'filename.java' (a typical project I could be working on). Normally, to do this outside Vim, I could do

:shell in Vim to access a shell outside Vim

C:\Program Files...\javac C:\home-directory-of-filename.java\filename.java

Which is pretty long, because I must access the javac directory and then write the whole 'filename.java' directory.

Is there anyway to ask Vim to call javac and use it directly on the file that I am working on? I would be pleased if anyone could help. I tried to write a couple of things in my _vimrc file, unsuccessfully. By the way, I am a windows vista user.

+1  A: 

To eliminate the need for full path to javac, just add the directory to your SYSTEM PATH Enviornment variable. It is possible to also add the directory that contains your .java files to the PATH variable as well - which would eliminate the need to use full path.

ftank99
A: 

If you use Ant for your build manager, you can set vim up to use Ant when you issue the :make command from within vim.

More details here: http://everything101.sourceforge.net/docs/papers/java_and_vim.html

Bob F.
+4  A: 

You can perform an action against the file open in the current buffer using %. So, if you want to execute javac.exe against your current buffer, you could type:

:!javac %

To make it easier on the fingers, you could create a mapping in your .vimrc like so:

map <LocalLeader>jc :!javac %<CR>

Now simply type \jc (or whatever your local leader is) in your buffer and presto, you've run javac against that file.

Drew Olson
I know what you're trying to make me do, and that is what I really want, but when I do \jc (\ is my local leader) a shell pops up and says that javac is not recognized as an external or internal command (practically speaking, the shell didn't find javac.exe, which is my current problem).
This is because javac is not in your path (or system path if this is windows). You'll need to rectify that problem and then the command should work fine for you. Google around for adding to your System Path. Hope that helps!
Drew Olson
+2  A: 

G'day,

Why not do something to map a function key to call the javac on the file you are currently editing? Maybe something like:

map <silent> <F9> :w<CR>:!C:\Program Files...\javac %<CR>

This will then call javac on the file you are currently editing.

HTH

cheers,

Rob Wells
+3  A: 

Thanks to Drew Olson, I found my answer. But it was not a system path problem, I simply needed to type correctly the path to javac in the mapping. What I have added in my _vimrc was this line :

map jc :!"C:\Program Files\path-leading-to-javac.exe\javac.exe" %

The path written between "s is read correctly by Vim. I don't know if it is written correctly for master-geeks, but I don't care, because it works for me and I know barely nothing right now. =D

P.S. : For geeks who think noobs know everything, please try to be user-friendly. Popping a website with no indications is not user-friendly. It is only a tip, not an offense. I still appreciate the help.