Loading ...
Sorry, an error occurred while loading the content.

How to Compile Java from MacVim and Show Output in Terminal

Expand Messages
  • 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
    Message 1 of 5 , Jul 7, 2012
    • 0 Attachment
      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]

      Thanks..Dave

      --
      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
    • Xiao G. Wu
      I would offer that you write to file, type :shell javac ?.java java ? type exit to return to the editor Sent from my iPad ... -- You received this message from
      Message 2 of 5 , Jul 8, 2012
      • 0 Attachment
        I would offer that you write to file,
        type :shell
        javac ?.java
        java ?
        type exit to return to the editor

        Sent from my iPad

        On Jul 7, 2012, at 1:25 PM, David Gillooly <david.gillooly@...> wrote:

        > 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]
        >
        > Thanks..Dave
        >
        > --
        > 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

        --
        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
      • Peter Palmreuther
        Hi, ... Create or open your Java source code file in MacVim, if necessary use ... to get proper syntax highlighting and finally ... Now when you want to
        Message 3 of 5 , Jul 8, 2012
        • 0 Attachment
          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
        • David Gillooly
          ... Thanks for the assistance..Dave -- You received this message from the vim_mac maillist. Do not top-post! Type your reply below the text you are replying
          Message 4 of 5 , Aug 23, 2012
          • 0 Attachment
            On Sunday, July 8, 2012 10:37:16 PM UTC-7, Xiao G. Wu wrote:
            > I would offer that you write to file,
            >
            > type :shell
            >
            > javac ?.java
            >
            > java ?
            >
            > type exit to return to the editor
            >
            >
            >
            > Sent from my iPad
            >
            >
            >
            > On Jul 7, 2012, at 1:25 PM, David Gillooly <david.gillooly@...> wrote:
            >
            >
            >
            > > 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]
            >
            > >
            >
            > > Thanks..Dave
            >
            > >
            >
            > > --
            >
            > > 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

            Thanks for the assistance..Dave

            --
            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
          • David Gillooly
            ... Thanks for the assistance. I am working OK now. Yes I agree that an IDE is the way to go long term. I have looked at Eclipse and NetBeans and for me either
            Message 5 of 5 , Aug 23, 2012
            • 0 Attachment
              On Sunday, July 8, 2012 11:53:42 PM UTC-7, Peter Palmreuther wrote:
              > 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

              Thanks for the assistance. I am working OK now.

              Yes I agree that an IDE is the way to go long term. I have looked at Eclipse and NetBeans and for me either one would work fine. Eclipse seems to support Android well but I noticed that NetBeans has added Android support too.

              Thanks..Dave

              --
              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
            Your message has been successfully submitted and would be delivered to recipients shortly.