Hi,

Am 07.07.2012 um 18:30 schrieb David Gillooly:
> 
> I am taking a beginning Java class that just uses a text editor and shell to 
> create java files,compile them and run them from a terminal that shows the 
> results. This is basic java stuff. Beginning java for idiots level!
> 
> I want to use MacVim to create, compile, and run the Java exercises and 
> examples.
> 
> I can write java from MacVim and get the proper highlighting etc. However I 
> have not been able to figure out how to compile the editor to allow me to 
> compile and run the programs.
> 
> What does one have to do? [make does't work for me]

Create or open your Java source code file in MacVim, if necessary use 

:setlocal filetype=java

to get proper syntax highlighting and finally 

:setlocal makeprg=javac\ %

Now when you want to compile your Java class just type

:make

It will execute "javac YourClass.java" (assuming your file name is 
"YourClass.java").
You'll get a list of warnings or errors, if any, the same way vim would present 
it for a C project.

To execute your Java program type

:!java -classpath . YourClass

All this is for really simple, almost stupid, Java classes.
If things turn more complex you could try to extend 'makeprg' by arguments 
passed to 'javac' using '\ ' to separate them.
But most probably it's going to be easier writing a small 'Makefile' and 
putting it next to your source code files.

A simple one for example could like similar to this:

===== 8>< ==========
#!/usr/bin/make

SOURCES = $(wildcard *.java)
CLASSES = $(patsubst %.java, %.class, $(SOURCES))
MAINCLASS = YourClass

CLASSPATH = .
JAVA_OPTS = -classpath $(CLASSPATH)
JAVAC_OPTS = -classpath $(CLASSPATH)

DEFAULT: all

%.class: %.java
        javac $(JAVAC_OPTS) $^

all: $(CLASSES)

run: all
        java $(JAVA_OPTS) $(MAINCLASS)

clean:
        @rm $(CLASSES)
===== 8>< ==========

With this (remember to replace "YourClass" with an appropriate value) Makefile 
next to your .java file(s) you should be able to open the source code in MacVim 
and type

:make

without any changes to 'makeprg'.
If you need to link additional libraries you only need to modify the Makefile 
and change 'CLASSPATH = .' appropriately (e.g. 'CLASSPATH = .:special.jar')
If you need to provide additional or special parameters to 'javac' or 'java' 
you'd only need to adjust 'JAVAC_OPTS' or 'JAVA_OPTS' appropriately.

But with all this information provided, remember: MacVim is not, and cannot 
replace, a full blown Java-IDE. There're significant differences.
Don't get me wrong, you CAN develop a Java project using MacVim as your only 
editor and you CAN have some (to 'a lot') of comfort doing so.
But usually a Java-IDE can provide much more, so up form a certain point it 
might be worth a thought to advance.
A step "in the middle" could be using 'Maven' for building your project. This 
way you could still stick with MacVim, while making use of Mavens great project 
and configuration management capabilities.
-- 
Best regards,

Peter

-- 
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to