Reputation: 315
I'm using Windows, and my _vimrc file has the following lines:
autocmd Filetype java set makeprg=javac\ -d\ %:~:h:s?src?bin?\ %
set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
map <F9> :make<Return>:copen<Return>
map <F10> :cprevious<Return>
map <F11> :cnext<Return>
map <F12> :!start cmd /k "java %:~:s?src?bin?:r"
I just want to use this for quick editing, and I will be using an IDE most of the time, thus the need for the classic /src/ and /bin/ folders (they are at the same folder level).
So it happens like this:
- I open the .java file that I want to edit in vim (it is in the /src/ folder)
- I hit F9 and javac runs on my current file (%) and puts the class files in the /bin/ folder (this seems to work as expected), and a new error window is opened in vim to display compile errors
- I hit F10/F11 to cycle between errors
- I hit F12 to open a command prompt and execute the java program (I think I have to open the command prompt because my program asks for user input in the console), except it gives an error in the command prompt that it could not find or load the main class
I don't know why it won't work, the class paths seem correct. Can you show me where I have went wrong?
Edit: @merlin2011 led me to the following answer:
map <F12> :!start cmd /k "cd %:~:h:s?src?bin? & java %:r"
I had to cd to /bin/ and then run java.
Or: without changing directory, and just changing the classpath:
map <F12> :!start cmd /k "java -classpath %:~:h:s?src?bin? %:r"
Upvotes: 0
Views: 781
Reputation: 75629
For permanency, I am converting my comment into an answer.
In order run the Java command from vim
, one must first cd
to the directory bin
and run the Java command from there.
map <F12> :!start cmd /k "cd %:~:h:s?src?bin? & java %:r"
Upvotes: 2