Hi,
I need a to create a java file dynamically .This file contains myown methods,variables and constructors.Any one please help me..

Recommended Answers

All 8 Replies

Unfortunately I do not see what your are trying to achieve here or what is your objective after even creating this file. Would you mind explaining to us your actual objective.
What you have mentioned here appears to be a means to an end. If you tell us what that end may be we can suggest a better means.

I need how to create a java file dynamically.Also i need to add my own methodes,attributes etc to it and save this java file to a specific directory.

I need how to create a java file dynamically.Also i need to add my own methodes,attributes etc to it and save this java file to a specific directory.

Once again, you are describing a means to an end, would you care to illuminate what the "end" should be?

I.E. What are you trying to accomplish by doing this. What task are you attempting to fulfill by attempting to generate classes on the fly?

In c#.net we can create .cs files using the namespace CodDom
This name space contains methodes for creating Constructors,functions,adding namespaces etc.Like this name space is there is anything in java.
My req is to create dynamically some java files inside a solution ,all these files contains some predefined methodes,constructors and variables.After completing the creation we can compile this java files.

Nevermind.

You still haven't said why it is you feel the need to generate classes, which, if we knew that we might be able to recommend a finished product, but what the heck.

The answer, then, is no. You will have to actually do things like

println("  public void getVarName() {");
println("    return varName;");
println("  }");

yourself.

Using BCEL we can create class files dynamically.Is there is any way
to create a java file .Because i am currently in a product dev and my current module is to create a java file dynamically.Please help..

decompile that BCEL generated class file, as BCEL does not create and then compile java files, it directly creates/modifies the byte code contained within the class files. Don't expect to get "pretty" code, though.

Once again though, there are generators for specific purposes.

Here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.