Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Drag and Drop Javac

Drag and Drop Javac
Thread Tools
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Feb 16, 2001, 11:45 AM
 
I have a very efficient development setup on my MacOS 9 partion which I wish to imitate in MacOS X PB. It's essentialy a folder with aliases for javac, JBindery and few other SDK tools. Draging a source file into the javac icon automatically compiles it and places the resulting .class file in the same directory. I then drag the .class to JBindery alias, and click "run" when the dialog window comes up. This quick and dirty setup is awesome for quick testing of simple disparate pieces of code that do not merit a Project Builder project and all the associated overhead files and file structures. Any ideas, anyone?

Thanks,
-FB

------------------


[This message has been edited by DaGuy (edited 02-16-2001).]
iMac 17" G4 800MHZ & 768 SDRAM
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Feb 16, 2001, 01:01 PM
 
Well, write a wrapper for what you want to do.

Roughly:
Code:
import java.io.*; public class ShellAccess { private String msg = "", msg1 = "", emsg = ""; private File[] class_files; private BufferedReader stdin; // private PrintWriter stdout; private BufferedReader stderr; public ShellAccess() {} // compile the .java files and return the .class files.. // pass something like: yourArray = {"javac", "-classpath", "whatever..", "Main.java", "Helper.java"}; public final File[] compile(String[] cmndArray) { msg = ""; emsg = ""; try { Process p = Runtime.getRuntime().exec(cmdArray); stdin = new BufferedReader(new InputStreamReader(p.getInputStream())); stderr = new BufferedReader(new InputStreamReader (p.getErrorStream())); // if you want to input something while it's running (not useable for a javac/java wrapper, really)... // stdout = new PrintWriter(new OutputStreamWriter(p.getOutputStream())); p.waitFor(); // you could do something with any messages that some from javac.. while ((msg = stdin.readLine()) != null) System.out.println(msg); while ((emsg = stderr.readLine()) != null) System.out.println(emsg); p.destroy(); //destroy the process } catch(Exception e) { /*handle your errors through NSLog?*/ } // figure out where the .java files came from.. // look in that directory for all the .class files // you might want to do some other checking too...dunno. class_files = null; //you fix. return class_files; } public void runProgram(String[] cmndArray) { //basically the same as above but send this something like: // yourArray = { "java", "-cp", "whatever", "YourClass.class" }; //you'd probably want to exclude "p.destroy()" though..not sure. } }
I know that's not what you were looking for but it would let you customize it so you can do it all through one app. I used to do exactly what you do in OS9 too. It would be nice to have something equally efficient for testing code in OSX.

Maybe I'll take this on. Looks like it could be fun.
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Feb 16, 2001, 02:23 PM
 
Hey, thanks a bunch! That is indeed a very useful class. I will begin thinking about implementing it (or some variation of it) in a tool that supports drag -and-drop java compiling.

And you are right, creating such tool does sound like a fun project . For that one, I'll probably use Project Builder, pretty ironic, ah?

Best,
-FB




------------------
iMac 17" G4 800MHZ & 768 SDRAM
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Feb 16, 2001, 02:47 PM
 
Just a tad ironic.

If you want some help with that I'd be more than willing.

I've done a bit of Java and Obj-C stuff. Nicer and Xk respectively. I'm working on a Nicer port to Obj-C right now but I still have to have something to escape to.

If you'd like you can reach me at ryanstevens@mac.com
     
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Feb 16, 2001, 02:54 PM
 
This isn't what you are asking for, but I use Ant (from the jakarta project). It is an excellent make-like tool written in Java and very easy to configure. In fact, my project structures are very complex, and I mostly just use Project Builder as a source editor, but the entire compile/build cycle is too complex for PB and Ant handles it just fine.
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Feb 16, 2001, 02:55 PM
 
Excellent offer, I will keep it very much in mind.

Thanks for your help,
-Francisco Bido

PS: I am at bido@mac.com
iMac 17" G4 800MHZ & 768 SDRAM
     
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Feb 16, 2001, 03:11 PM
 
Be careful with code like the above, namely:
Process p = Runtime.getRuntime().exec(cmdArray);
stdin = new BufferedReader(new InputStreamReader(p.getInputStream()));
stderr = new BufferedReader(new InputStreamReader (p.getErrorStream()));
p.waitFor();

This code can lead to deadlocks. The stream between The external process and the calling process has a fixed-length buffer, and once it fills up both processes will deadlock.

Also, you can create an instance of the java compiler yourself. The only caveat is that you can't use it twice since it stores static data about the classpath, etc.
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Feb 16, 2001, 05:08 PM
 
That is interesting... I will be careful with that issue.

absmith also mentioned creating an instance of the compiler itself. I have not seen that before, how is it implemented?

Thanks,
-FB



------------------
iMac 17" G4 800MHZ & 768 SDRAM
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2