Hello,

I have created a JAR that contains (among other things) a java class with the 'main' method, i.e. it can be executed from the command line or using the 'java' task.

The program can take many parameters on the command line; the parameters have not very nice names (for some historical reasons).

To make the usage of the program from within ant a little bit easier, I've also created a custom ant task which has some nicely named nested elements that more or less correspont to the program parameters.

When the task is executed, it internally creates an instance of the Java task (passing itself as the owner in the constructor), sets the classname attribute to the name of the program's class, adds the command line parameters, and executes the Java task.

I.e. it effectively translates its own definition to a call of the Java task.

This is a code snippet from my custom task:


    @Override
    public void execute() throws BuildException {
        Task progExecutionTask = getProgramExecutionTask();
        progExecutionTask.execute();
    }

    private Task getProgramExecutionTask() {
        Java javaTask = new Java(this);
        javaTask.init();

        javaTask.setClassname(MyProgram.class.getName());

        // Set the program parameters
        CommandlineJava cmdLine = javaTask.getCommandLine();

        // programArgumentsList is an instance variable in my custom
        // task; it gets filled when addConfiguredXyz methods are called
        for (String arg : programArgumentsList) {
            cmdLine.createArgument().setValue(arg);
        }

        return javaTask;
    }


My problem is that I also have to set the classpath attribute for the internal Java task. And I'd like to set it automatically to the same classpath that was used for loading of my custom task (since the 'main' class and the custom task are in the same JAR).

Is it possible (and how?) to get the classpath that was used to load a custom task, from withing that custom task?

I hope you understand what I mean.

Thank you!

Al

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to