I'm totally new to StackOverflow so please try to tolerate me.Thank you.I'm new to ANT with a beginners knowledge in java. So I wanted to know if it is possible to run multiple classes of java source files in an xml file using Ant.
Instead of specifying multiple java classnames within the targets, can I run the run classes in a single go?
If you are indeed asking whether a java task can be configured to run more than one class I believe the answer is no. According to the documentation for the java task the classname attribute specifies
the Java class to execute.
If you need to run multiple classes using a single java task you could create a controller class to run these classes then simply invoke that single controller.
Related
I developed a transformation that generates a Kermeta XMI file.
My problem is that I would run this transformation (.kmt file) in the background, that is to say from a Java program.
I tried a lot of code but always without result.
Someone can help me?
Thank you in advance for your help.
Running a kermeta program depends on the version of Kermeta and about its execution context.
With Kermeta 2, the kmt code is compiled into scala. This scala code can be directly called from java thanks to scala compatibility with java.
You first need to declare at least one main operation in order to generate the appropriate initialization operation.
Let's say you have a method "transformFooToBar" in a class "org::example::FooToBar" in your kermeta code.
Declare it as a main entry point using the tags
#mainClass "org::example::FooToBar"
#mainOperation "transformFooToBar"
This main operation must have only string parameters.
This will generate an utility scala class org.example.MainRunner which contains useful initialization methods and a main operation that you can call from the command line.
Case 1/ With Kermeta 2 code called from an eclipse plugin:
This is the simpliest case, call the method org.example.MainRunner.init4eclipse()
before any other call. Then call your main method org.example.KerRichFactory.createFooToBar.transformFooToBar()
You can call any other classes or methods (ie. even with parameters that aren't String)
This is quite convinient for building tool for eclipse based on kermeta transformation.
Case 2/ Kermeta 2 code called from a standard java application (ie. not running in an eclipse plugin)
The initialiation method is then org.example.MainRunner.init()
Common trap for case 2: many transformations that run as standalone still need to manipulate models using eclipse uri scheme in their internal refencing system. Ie. platform:/plugin/... , platform:/resource/..., pathmap:/... , or even more complex uri mapping (typically using custom protocols ) (you can check that easily in by looking in the xmi files as text)
In that case, since Eclipse platform isn't running to provide the search mechanism, you need to provide manually the equivalent URI mapping to map these URI to your local system URI (Ie. to file:/... or jar:file:/ URIs)
One possibility is to use an urimap.properties file that provide such mapping. By default when running a kermeta program in eclipse, an urimap.properties is generated for the current eclipse configuration.
When deploying a kermeta program to another computer, or using a custom deployment packaging, you will have to provide/compute an equivalent file for the target computer.
For convinience, you can set the location of this urimap.properties files thanks to the system propery "urimap.file.location"
I have to generate java docs for a project but not for all files.
I want to create index.hmtl which contains java docs for some specific classes and some specific packages.
I know how to create each of them separately but if i give two commands the last command results are shown and everything else is over written.
How to i do all of this using one command. Basically i want to club it all in one.
Thanks.
I want to create a one .java from the Java program. When I run the program, automatically one Java file will created in my project, and also create some run time (dynamic) variable in that file. How can I do this?
I know for this I have to use a Reflection API like Class and Method, but what are the methods in Class and Method to do this?
You cannot create new classes or methods using the reflection APIs. They are not designed for this. (The Class and Method APIs are for performing operations on object instances in a dynamic fashion.)
If you want to create new code on the fly, there are two basic approaches to doing this:
Generate Java source code, write it to a file, use the Java compiler to compile it to a bytecode file, and then load the bytecodes. (There are standard APIs for running the Java compiler within the JVM of a running application.)
Use BCEL or equivalent to construct a bytecode file from scratch, and then load the bytecodes.
Both approaches are tricky and computationally expensive. The BCEL approach is particularly tricky because you need to understand a lot about the JVM to do the job.
Apparently you want to create a new class at Runtime and use it. You can sure create a .javafile, compile it and load it from a custom class loader but that's probably not the best/easiest thing to do. Here are a bunch of solutions:
First of all if you want to extend an interface, you can use the Proxy from the Java Reflection API.
It you want to extend a class rather than implements an interface or create a class out of the blue you need to use a library to create bytecode. You can find a bunch of them on http://www.java-opensource.com/open-source/bytecode-libraries.html. Among these libraries I like javassist mainly because it is the only library to my knowledge letting you enter Java code directly rather than bytecode.
A last solution should be to use a framework like Groovy or BSH to interpret pseudo-java code.
No, you can't generate new .java files using Reflection. You could perhaps create a new class, and use this class, in runtime, but you can't write that class out to file in the form of a .java source file.
Have a look at the JustAdd framework for instance. This framework solves this type of problems IIRC.
Java is a strongly typed language( As opposed to a weakly typed language). Simply put you need to have a Class (prototype) to create a instance of object. What you are trying to do is not natural in java (or any strongly typed language).
If you have to have this functionality in java, you need to use groovy. Groovy is a dynamic language that can run in Java JVM. You need to check Expandos in groovy.(ofcourse it still will not create a .java file).
I am finding a way to write a script that I can generate javadoc for my program's Interfaces only (not for public classes). I have tried Eclipse built-in tool and even JAutodoc tool but have not been successful yet.
Does anyone have some ideas, please?
Thanks.
Personally, I would go with custom ant script (if you're familiar with it). With javadoc task you can use nested 'fileset' element with dynamically generated list of interfaces. Or just have script to copy all interfaces to temporary directory, run javadoc and remove temp dir in the end. Last can be implemented even with bash script.
But if you want user to not see your implementation classes, it makes more sense to limit their visibility. And then you can generate documentation only for public entries. Just a thought.
I used wsimport command line tool for creating classses but I want to do it from the java code. Any idea?
It is possible to call the WsImport main() method:
import com.sun.tools.ws.WsImport;
...
String[] args = {"put", "your", "arguments", "here"};
WsImport.main(args);
I think that this is what the Ant task does.
Update: I'm not sure to understand what you're trying to do (and I don't think that you want to generate source code and compile it during runtime).
If the question is actually about doing dynamic invocation, JAX-WS's dynamic invocation interface (DII) is the javax.xml.ws.Dispatch object. Check JAX-WS's dynamic Dispatch interface.
What you are trying to achieve is not typical Java Web Services flow. But you can achieve this with dynamic JVM based Groovy language using GroovyWS module.
You can use the wsimport ant task programatically.
You can do this by using the task class - com.sun.tools.ws.ant.WsImport. Instantiate it, set its properties (as defined on the task documentation), and call the execute() method.