[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JDK tools



I'm not seeing the System.exit. Here is how I am using Main:

protected String sunCompile( File javaFile )
    {
        String[] source = new String[3];
        source[0] = javaFile.getPath();
        source[1] = "-classpath";
        source[2] = System.getProperty( "java.class.path");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        new sun.tools.javac.Main( baos, source[0] ).compile( source );

        if( baos.toString().indexOf("error") != -1 )
        {
            return baos.toString();
        }
        return null;
    }

I have a GUI that allows a user to provide input that I use to generate a .java file.

I call this method to generate the corresponding .class file. The beanshell figures
into
this process as a means to verify and test code before I do the heavier weight
compile.
So this is an iterative process and I have not noticed the effect of the System.exit.

Are we talking about the same thing?


Pat wrote:

> Sun does System.exit at the bottom of the main method in all of their tools.  I
> have no idea why but its very annoying!
>
> Pat, your compiler work isn't obsolete (although the source is now available for
> the compiler so you don't have to decompile.)  Sun has yet to create a reasonable
> API for the compiler.  I also had to copy all the source and make massive
> modifications just to compile a String in memory (rather than hitting the disk).
> Another super, super, super annoying "feature" is the wonderful security
> restriction which prevents classes from being reloaded even when completely
> dereferenced.  I can't dynamically update a class definition in Lingua without
> bouncing the VM.  I would think security of this type should be optional
> (defaulting to "on").  Suns VM also seems to hold on to classes loaded in the VM
> indefinitely.  This is very poor design.
>
> BTW - I just found a new bug.  Beanshell doesn't like (primitive).class (such as
> int.class) which is legal under the JLS.
>
> wait, I just thought of something else...
>
> Yep, I suspected as much.  It also doesn't like (type)[].class (such as
> Object[].class) which is also legal under the JLS.
>
> PS The new version of BeanShell kicks ass.
>

> ...but I still think you should add some scripting niceties such as foreach and
> loop statements.  I've already added them to Lingua and I'd be happy to add them
> to BeanShell with your permission...
>
> foreach example:
> ints=new int[] {4,5,6};
> foreach(i, ints) print(i);
>
> output:
> 4
> 5
> 6
>
> loop example:
> loop(i,4,6) print(i);
>
> output:
> 4
> 5
> 6
>
> You should also overload arithmetic and comparison operators for classes
> extending java.lang.Number.  Comparison operators should also work with any class
> implementing java.lang.Comparable.  Again, I'll do it for you if you approve such
> changes.  This should have been a Java feature but time restrictions prevented
> Gosling from implementing them properly (by his own admission).  Time
> restrictions also screwed us out of parametric polymorphism (at least for the
> moment) and multiple return values.  Arg!  Calling methods to add two BigDecimals
> really sucks.
>
> I know you have voiced concern with deviating from the JLS during previous
> conversations we've had on this subject.  I have some thoughts on that subject.
>
> A) I don't think keywords such as foreach polute the namespace.  Who uses foreach
> as a variable name?  If anyone does I hope I don't ever meet them in a dark
> alley.
> B) I tried your -strict switch idea in Lingua but performance problems arose.
> This could be ameliorated by creating separate code bases but at that point you
> have different languages with different bugs...
>
> Anyway, enough bathering for today.  BeanShell looks great.  Back to work...
>
> Pat wrote:
>
> > On Thu, Dec 23, 1999 at 09:04:47PM +0100, Mikael Ståldal wrote:
> > > Is it possible to run the JDK tools (javac, javap, jar, etc) from
> > > within Beanshell?
> > >
> > ...
> > > I tried to this in bsh:
> > >
> > > BeanShell 1.0 beta - by Pat Niemeyer (pat@pat.net)
> > > bsh % args = new String[] { "HelloWorld.java" };
> > > bsh % sun.tools.javac.Main.main(args);
> > >
> > > and it did compile HelloWorld.java fine, but then I was
> > > immediatly thrown out of bsh.
> >
> > I have always assumed it is possible, but I hadn't tried it.
> >
> > I might be the case that Sun deliberately adds a System.exit() to their
> > code just to prevent you from using the JDK compiler in this way...  Or maybe
> > it's something else.
> >
> > A *long* time ago I decompiled the Sun javac package and figured out how to
> > use it directly (without even necessitating going to the file system).
> > However I'm sure that's all been rendered obsolete.
> >
> > I would like to be able to make bsh commands that wrap these, so it would be
> > good if we can figure out what's up.
> >
> > Pat
>
> --
> X   U   M   A    <engineering for e-business>
> Daniel Leuck
> 160 Pine St., 2nd Floor
> San Francisco, CA  94111
> Phone: (415)777-9988
> Fax: (415)777-2704
> email: dleuck@xuma.com
> http://www.xuma.com
begin:vcard 
n:Johns;Rich
x-mozilla-html:TRUE
org:Trajecta
version:2.1
email;internet:rjohns@trajecta.com
title:Software Designer
note:rpj@metierproductions.com
x-mozilla-cpt:;0
fn:Rich Johns
end:vcard