Results 1 to 4 of 4
  1. #1
    sunil.natikar is offline Member
    Join Date
    Jul 2011
    Location
    Mumbai
    Posts
    1
    Rep Power
    0

    Question Create *.java file dynamicaly

    Hi all,

    I am writing a code which is generating .java and .xml files dyanamically.

    For xml files I am using javax.xml.parsers.DocumentBuilderFactory .

    My xml files are generating correctly but I have some queries regarding genrerating .java files.

    I want to create a java file which will have some methods and variables.

    Is there any way to do this?

    Is there any java classes or libraries to do this?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    I want to create a java file which will have some methods and variables.
    A .java file contains text written in Java syntax. You can write a .java file with any class that writes Strings.

    Are you asking if there is a Java statement generator engine? The only one I know of is the one in front of the keyboard.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    I've used Sun's Codemodel API to generate Java source from an XML specification. It seems to have been abandoned when Oracle acquired Sun, and it's not very well documented, but it's worked well for me.

    CodeModel — Java.net
    Codemodel 2.4 API
    Get in the habit of using standard Java naming conventions!

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Here's an example of how I used it. Note that although I defined the classes, methods, and fields the "right" way, when it came to generating the method bodies, I mostly cheated and used JBlock.directStatement(...).

    http://szprotocol.svn.sourceforge.ne...Generator.java
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. How to create java executable file through CMD
    By Riaz Ali in forum New To Java
    Replies: 4
    Last Post: 08-03-2010, 08:20 AM
  2. Create a file specifying the size JAVA
    By Harbox in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 01:42 PM
  3. How to create an exe file in java
    By pads in forum New To Java
    Replies: 4
    Last Post: 07-09-2010, 05:20 PM
  4. How to create exe file in java
    By radix in forum New To Java
    Replies: 8
    Last Post: 11-06-2008, 04:17 PM
  5. Need to dynamicaly get all parameters in a method call.
    By DavidJohns in forum Advanced Java
    Replies: 2
    Last Post: 05-21-2008, 07:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •