12 Replies Latest reply: Feb 21, 2010 5:01 PM by EJP RSS

    runtime compiler

    843810
      hey guys,

      I was looking around a while for this, I didn't find relevant threads or pages, they are all talking about javac as the compiler, which I understand, but isn't there an object, Compiler, to design the compiler properties with setters, and then to use a method to compile, instead of suppling a String[] parameter?

      Thanks,
      Adam.
        • 1. Re: runtime compiler
          843810
          Are you talking about JavaCompiler or javacc?
          • 2. Re: runtime compiler
            843810
            JavaCompiler, yes that is what I was looking for thanks, I was googling for "Java Runtime Compiler", it didn't pop straight up.

            Thanks.
            • 3. Re: runtime compiler
              843810
              hey,
              is there a link anyone can provide that describes in details, how the java compiler perform its compiling steps? I looked around but nothing really fitted what I was looking for, I would like to get to the, not the bottom, but deep enough to get my head around the process and to be able to implement a runtime compilation and Jar-ing of the compiled files....

              Thanks in advance,
              Adam.
              • 4. Re: runtime compiler
                843810
                Adam-Z. wrote:
                ... a link ... that describes in details,
                how the java compiler perform its compiling steps? I looked around but nothing really fitted what I was looking for, I would like to get to the, not the bottom, but deep enough to get my head around the process
                There are people here with a thorough understanding of how compilers work
                but I don't know if there is a good resource for [how compilers work ^(google)^|http://www.google.com/search?q=how+compilers+work] anywhere...
                and to be able to implement a runtime compilation and Jar-ing of the compiled files....
                I would not think you need to understand the internals of the compiler to use it programmatically.
                • 5. Re: runtime compiler
                  843810
                  Thanks you for your reply,
                  I would not think you need to understand the internals of the compiler to use it programmatically.
                  O, I see how I described what I wanted to ask, not clear again...
                  What I meant was that I would like to understand how the objects that the compiler is working with, if its the JavaFileObject implementation, or the FileManager, their docs, are really not providing any detailed insight about their part in the compilation process or how they may be used...

                  Thanks in advance,
                  Adam Zehavi.
                  • 6. Re: runtime compiler
                    jschellSomeoneStoleMyAlias
                    Adam-Z. wrote:
                    Thanks you for your reply,
                    I would not think you need to understand the internals of the compiler to use it programmatically.
                    O, I see how I described what I wanted to ask, not clear again...
                    What I meant was that I would like to understand how the objects that the compiler is working with, if its the JavaFileObject implementation, or the FileManager, their docs, are really not providing any detailed insight about their part in the compilation process or how they may be used...
                    Rephrasing it again...you would like more information on the API to the exposed JavaCompiler.

                    I believe you are out of luck. Best I can suggest is that you google for other questions about using it.
                    • 7. Re: runtime compiler
                      843810
                      Something else that I have problem with the in the compiling process, my files are located in:

                      D:/%Important Documents/WorkSpaces/...

                      there are two problems, the '%' and ' ' charachter, when I try to create a URI for :
                                private final class CompilerJavaFileObject extends SimpleJavaFileObject {
                                     private CompilerJavaFileObject(String name, Kind kind) throws URISyntaxException {
                                          super(toURI("file:"+name), kind);
                                     }
                                     
                                     ByteArrayOutputStream baos;
                                     
                                     @Override
                                     public InputStream openInputStream() throws IOException, IllegalStateException, UnsupportedOperationException {
                                          return new ByteArrayInputStream(baos.toByteArray());
                                     }
                                     
                                     @Override
                                     public OutputStream openOutputStream() throws IOException, IllegalStateException, UnsupportedOperationException {
                                          return baos = new ByteArrayOutputStream();
                                     }
                                     
                                }
                      am I missing something...

                      Thanks,
                      Adam.
                      • 8. Re: runtime compiler
                        jschellSomeoneStoleMyAlias
                        Adam-Z. wrote:
                        Something else that I have problem with the in the compiling process, ...
                        The problem with this particular question is that you didn't actually tell us what the problem is.
                        • 9. Re: runtime compiler
                          843810
                          yes well sorry... it was too much in my face the last few hours... I just forgot to add it....
                           java.net.URISyntaxException: Malformed escape pair at index 8:... 
                          which is the %, and if I remove the '%' sign then the space char causes the exception...

                          Adam.
                          • 10. Re: runtime compiler
                            843810
                            I have to point out the reasons for the exception are clear I read the URI docs, but it does not state a way around this... what if my path involves spaces and '%' signs?

                            Adam.
                            • 11. Re: runtime compiler
                              EJP
                              Something wrong with your toURI() method, which you haven't shown us. The correct way to construct a file: URI for a filename that needs escaping is new URI("file", name, null);

                              Note that new URI(String) doesn't do any escaping.
                              • 12. Re: runtime compiler
                                843810
                                sorry to say that, I had the wrong idea about the Compiler, I looked at over complicated examples, and after tring to use that implementation for 2 days I gave it up and start to look for a different approach, then I bumped on a simple example that kinda summed it all up at in the main() method: [Compiler example|http://www.java2s.com/Code/Java/JDK-6/CompileaJavafilewithJavaCompiler.htm]

                                Thank you all for your help.
                                Adam Zehavi