FileDocCategorySizeDatePackage
Javah.javaAPI DocApache Ant 1.7013749Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional

Javah

public class Javah extends org.apache.tools.ant.Task
Generates JNI header files using javah. This task can take the following arguments:
  • classname - the fully-qualified name of a class
  • outputFile - Concatenates the resulting header or source files for all the classes listed into this file
  • destdir - Sets the directory where javah saves the header files or the stub files
  • classpath
  • bootclasspath
  • force - Specifies that output files should always be written (JDK1.2 only)
  • old - Specifies that old JDK1.0-style header files should be generated (otherwise output file contain JNI-style native method function prototypes) (JDK1.2 only)
  • stubs - generate C declarations from the Java object file (used with old)
  • verbose - causes javah to print a message to stdout concerning the status of the generated files
  • extdirs - Override location of installed extensions
Of these arguments, either outputFile or destdir is required, but not both. More than one classname may be specified, using a comma-separated list or by using <class name="xxx"> elements within the task.

When this task executes, it will generate C header and source files that are needed to implement native methods.

Fields Summary
private Vector
classes
private String
cls
private File
destDir
private org.apache.tools.ant.types.Path
classpath
private File
outputFile
private boolean
verbose
private boolean
force
private boolean
old
private boolean
stubs
private org.apache.tools.ant.types.Path
bootclasspath
private static String
lSep
private org.apache.tools.ant.util.facade.FacadeTaskHelper
facade
Constructors Summary
public Javah()
No arg constructor.


            
      
        facade = new FacadeTaskHelper(JavahAdapterFactory.getDefault());
    
Methods Summary
public org.apache.tools.ant.util.facade.ImplementationSpecificArgumentcreateArg()
Adds an implementation specific command-line argument.

return
a ImplementationSpecificArgument to be configured.
since
Ant 1.6.3

        ImplementationSpecificArgument arg =
            new ImplementationSpecificArgument();
        facade.addImplementationArgument(arg);
        return arg;
    
public org.apache.tools.ant.types.PathcreateBootclasspath()
Adds path to bootstrap class files.

return
a path to be configured.

        if (bootclasspath == null) {
            bootclasspath = new Path(getProject());
        }
        return bootclasspath.createPath();
    
public org.apache.tools.ant.taskdefs.optional.Javah$ClassArgumentcreateClass()
Adds class to process.

return
a ClassArgument to be configured.

        ClassArgument ga = new ClassArgument();
        classes.addElement(ga);
        return ga;
    
public org.apache.tools.ant.types.PathcreateClasspath()
Path to use for classpath.

return
a path to be configured.

        if (classpath == null) {
            classpath = new Path(getProject());
        }
        return classpath.createPath();
    
public voidexecute()
Execute the task

throws
BuildException is there is a problem in the task execution.

        // first off, make sure that we've got a srcdir

        if ((cls == null) && (classes.size() == 0)) {
            throw new BuildException("class attribute must be set!",
                getLocation());
        }

        if ((cls != null) && (classes.size() > 0)) {
            throw new BuildException("set class attribute or class element, "
                + "not both.", getLocation());
        }

        if (destDir != null) {
            if (!destDir.isDirectory()) {
                throw new BuildException("destination directory \"" + destDir
                    + "\" does not exist or is not a directory", getLocation());
            }
            if (outputFile != null) {
                throw new BuildException("destdir and outputFile are mutually "
                    + "exclusive", getLocation());
            }
        }

        if (classpath == null) {
            classpath = (new Path(getProject())).concatSystemClasspath("last");
        } else {
            classpath = classpath.concatSystemClasspath("ignore");
        }

        JavahAdapter ad =
            JavahAdapterFactory.getAdapter(facade.getImplementation(),
                                           this);
        if (!ad.compile(this)) {
            throw new BuildException("compilation failed");
        }
    
public org.apache.tools.ant.types.PathgetBootclasspath()
The bootclasspath to use.

return
the bootclass path.
since
Ant 1.6.3

        return bootclasspath;
    
public java.lang.String[]getClasses()
Names of the classes to process.

return
the array of classes.
since
Ant 1.6.3

        ArrayList al = new ArrayList();
        if (cls != null) {
            StringTokenizer tok = new StringTokenizer(cls, ",", false);
            while (tok.hasMoreTokens()) {
                al.add(tok.nextToken().trim());
            }
        }

        Enumeration e = classes.elements();
        while (e.hasMoreElements()) {
            ClassArgument arg = (ClassArgument) e.nextElement();
            al.add(arg.getName());
        }
        return (String[]) al.toArray(new String[al.size()]);
    
public org.apache.tools.ant.types.PathgetClasspath()
The classpath to use.

return
the classpath.
since
Ant 1.6.3

        return classpath;
    
public java.lang.String[]getCurrentArgs()
Returns the (implementation specific) settings given as nested arg elements.

return
the arguments.
since
Ant 1.6.3

        return facade.getArgs();
    
public java.io.FilegetDestdir()
The destination directory, if any.

return
the destination directory.
since
Ant 1.6.3

        return destDir;
    
public booleangetForce()
Whether output files should always be written.

return
the force attribute.
since
Ant 1.6.3

        return force;
    
public booleangetOld()
Whether old JDK1.0-style header files should be generated.

return
the old attribute.
since
Ant 1.6.3

        return old;
    
public java.io.FilegetOutputfile()
The destination file, if any.

return
the destination file.
since
Ant 1.6.3

        return outputFile;
    
public booleangetStubs()
Whether C declarations from the Java object file should be generated.

return
the stubs attribute.
since
Ant 1.6.3

        return stubs;
    
public booleangetVerbose()
Whether verbose output should get generated.

return
the verbose attribute.
since
Ant 1.6.3

        return verbose;
    
public voidlogAndAddFiles(org.apache.tools.ant.types.Commandline cmd)
Logs the compilation parameters, adds the files to compile and logs the "niceSourceList"

param
cmd the command line.

        logAndAddFilesToCompile(cmd);
    
protected voidlogAndAddFilesToCompile(org.apache.tools.ant.types.Commandline cmd)
Logs the compilation parameters, adds the files to compile and logs the "niceSourceList"

param
cmd the command line to add parameters to.

        log("Compilation " + cmd.describeArguments(),
            Project.MSG_VERBOSE);

        StringBuffer niceClassList = new StringBuffer();
        String[] c = getClasses();
        for (int i = 0; i < c.length; i++) {
            cmd.createArgument().setValue(c[i]);
            niceClassList.append("    ");
            niceClassList.append(c[i]);
            niceClassList.append(lSep);
        }

        StringBuffer prefix = new StringBuffer("Class");
        if (c.length > 1) {
            prefix.append("es");
        }
        prefix.append(" to be compiled:");
        prefix.append(lSep);

        log(prefix.toString() + niceClassList.toString(), Project.MSG_VERBOSE);
    
public voidsetBootClasspathRef(org.apache.tools.ant.types.Reference r)
To the bootstrap path, this adds a reference to a classpath defined elsewhere.

param
r a reference to a classpath
todo
this needs to be documented in the HTML.

        createBootclasspath().setRefid(r);
    
public voidsetBootclasspath(org.apache.tools.ant.types.Path src)
location of bootstrap class files.

param
src the bootstrap classpath.

        if (bootclasspath == null) {
            bootclasspath = src;
        } else {
            bootclasspath.append(src);
        }
    
public voidsetClass(java.lang.String cls)
the fully-qualified name of the class (or classes, separated by commas).

param
cls the classname (or classnames).

        this.cls = cls;
    
public voidsetClasspath(org.apache.tools.ant.types.Path src)
the classpath to use.

param
src the classpath.

        if (classpath == null) {
            classpath = src;
        } else {
            classpath.append(src);
        }
    
public voidsetClasspathRef(org.apache.tools.ant.types.Reference r)
Adds a reference to a classpath defined elsewhere.

param
r a reference to a classpath.
todo
this needs to be documented in the HTML docs.

        createClasspath().setRefid(r);
    
public voidsetDestdir(java.io.File destDir)
Set the destination directory into which the Java source files should be compiled.

param
destDir the destination directory.

        this.destDir = destDir;
    
public voidsetForce(boolean force)
If true, output files should always be written (JDK1.2 only).

param
force the value to use.

        this.force = force;
    
public voidsetImplementation(java.lang.String impl)
Choose the implementation for this particular task.

param
impl the name of the implemenation.
since
Ant 1.6.3

        if ("default".equals(impl)) {
            facade.setImplementation(JavahAdapterFactory.getDefault());
        } else {
            facade.setImplementation(impl);
        }
    
public voidsetOld(boolean old)
If true, specifies that old JDK1.0-style header files should be generated. (otherwise output file contain JNI-style native method function prototypes) (JDK1.2 only).

param
old if true use old 1.0 style header files.

        this.old = old;
    
public voidsetOutputFile(java.io.File outputFile)
Concatenates the resulting header or source files for all the classes listed into this file.

param
outputFile the output file.

        this.outputFile = outputFile;
    
public voidsetStubs(boolean stubs)
If true, generate C declarations from the Java object file (used with old).

param
stubs if true, generated C declarations.

        this.stubs = stubs;
    
public voidsetVerbose(boolean verbose)
If true, causes Javah to print a message concerning the status of the generated files.

param
verbose if true, do verbose printing.

        this.verbose = verbose;