Reputation:
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.
Upvotes: 2
Views: 1478
Reputation:
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.
Upvotes: 3
Reputation: 37159
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,
Upvotes: 2
Reputation: 3747
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.
Upvotes: 7
Reputation: 3872
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
Upvotes: 1
Reputation: 51
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.
Upvotes: 1