Package org.apache.tools.ant.taskdefs

Examples of org.apache.tools.ant.taskdefs.Java


            throw new MojoExecutionException("Geronimo installation directory does not exist: " + geronimoHomeStr);
        }

        log.info("Starting Geronimo client...");

        Java java = (Java)createTask("java");
        java.setJar(new File(geronimoHome, "bin/client.jar"));
        java.setDir(geronimoHome);
        java.setFailonerror(true);
        java.setFork(true);

        if (javaVirtualMachine != null) {
            if (!javaVirtualMachine.exists()) {
                throw new MojoExecutionException("Java virtual machine is not valid: " + javaVirtualMachine);
            }
           
            log.info("Using Java virtual machine: " + javaVirtualMachine);
            java.setJvm(javaVirtualMachine.getCanonicalPath());
        }
       
        if (timeout > 0) {
            java.setTimeout(new Long(timeout * 1000));
        }

        if (maximumMemory != null) {
            java.setMaxmemory(maximumMemory);
        }

        // Set the properties which we pass to the JVM from the startup script
        setSystemProperty(java, "org.apache.geronimo.home.dir", geronimoHome);
        setSystemProperty(java, "java.io.tmpdir", "var/temp");
        setSystemProperty(java, "java.endorsed.dirs", prefixSystemPath("java.endorsed.dirs", new File(geronimoHome, "lib/endorsed")));
        setSystemProperty(java, "java.ext.dirs", prefixSystemPath("java.ext.dirs", new File(geronimoHome, "lib/ext")));

        java.createArg().setValue(moduleId);

        for (int i=0;arg != null && i<arg.length;i++) {
            java.createArg().setValue(arg[i]);
        }

        if (logOutput) {
            File file = getLogFile();
            FileUtils.forceMkdir(file.getParentFile());

            log.info("Redirecting output to: " + file);

            java.setOutput(file);
        }

        java.execute();
    }
View Full Code Here


        }

        log.info("Starting Geronimo server...");

        // Setup the JVM to start the server with
        final Java java = (Java)createTask("java");
        java.setJar(new File(geronimoHome, "bin/server.jar"));
        java.setDir(geronimoHome);
        java.setFailonerror(true);
        java.setFork(true);

        if (javaVirtualMachine != null) {
            if (!javaVirtualMachine.exists()) {
                throw new MojoExecutionException("Java virtual machine is not valid: " + javaVirtualMachine);
            }
           
            log.info("Using Java virtual machine: " + javaVirtualMachine);
            java.setJvm(javaVirtualMachine.getCanonicalPath());
        }
       
        if (timeout > 0) {
            java.setTimeout(new Long(timeout * 1000));
        }

        if (maximumMemory != null) {
            java.setMaxmemory(maximumMemory);
        }
       
        if (maxPermSize !=null){   
            java.createJvmarg().setValue("-XX:MaxPermSize="+maxPermSize);        
        }

        // Load the Java programming language agent for JPA
        File javaAgentJar = new File(geronimoHome, "bin/jpa.jar");
        if (javaAgentJar.exists()) {
            java.createJvmarg().setValue("-javaagent:" + javaAgentJar.getCanonicalPath());
        }

        // Propagate some properties from Maven to the server if enabled
        if (propagateGeronimoProperties) {
            Properties props = System.getProperties();
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String name = (String)iter.next();
                String value = System.getProperty(name);

                if (name.equals("geronimo.bootstrap.logging.enabled")) {
                    // Skip this property, never propagate it
                }
                else if (name.startsWith("org.apache.geronimo") || name.startsWith("geronimo")) {
                    if (log.isDebugEnabled()) {
                        log.debug("Propagating: " + name + "=" + value);
                    }
                    setSystemProperty(java, name, value);
                }
            }
        }

        // Apply option sets
        if (options != null  && (optionSets == null || optionSets.length == 0)) {
            throw new MojoExecutionException("At least one optionSet must be defined to select one using options");
        }
        else if (options == null) {
            options = "default";
        }

        if (optionSets != null && optionSets.length != 0) {
            OptionSet[] sets = selectOptionSets();

            for (int i=0; i < sets.length; i++) {
                if (log.isDebugEnabled()) {
                    log.debug("Selected option set: " + sets[i]);
                }
                else {
                    log.info("Selected option set: " + sets[i].getId());
                }

                String[] options = sets[i].getOptions();
                if (options != null) {
                    for (int j=0; j < options.length; j++) {
                        java.createJvmarg().setValue(options[j]);
                    }
                }

                Properties props = sets[i].getProperties();
                if (props != null) {
                    Iterator iter = props.keySet().iterator();
                    while (iter.hasNext()) {
                        String name = (String)iter.next();
                        String value = props.getProperty(name);

                        setSystemProperty(java, name, value);
                    }
                }
            }
        }

        // Set the properties which we pass to the JVM from the startup script
        setSystemProperty(java, "org.apache.geronimo.home.dir", geronimoHome);
        // Use relative path
        setSystemProperty(java, "java.io.tmpdir", "var/temp");
        setSystemProperty(java, "java.endorsed.dirs", prefixSystemPath("java.endorsed.dirs", new File(geronimoHome, "lib/endorsed")));
        setSystemProperty(java, "java.ext.dirs", prefixSystemPath("java.ext.dirs", new File(geronimoHome, "lib/ext")));

        if (quiet) {
            java.createArg().setValue("--quiet");
        }
        else {
            java.createArg().setValue("--long");
        }

        if (verbose) {
            java.createArg().setValue("--verbose");
        }

        if (veryverbose) {
            java.createArg().setValue("--veryverbose");
        }

        if (startModules != null) {
            if (startModules.length == 0) {
                throw new MojoExecutionException("At least one module name must be configured with startModule");
            }

            log.info("Overriding the set of modules to be started");

            java.createArg().setValue("--override");

            for (int i=0; i < startModules.length; i++) {
                java.createArg().setValue(startModules[i]);
            }
        }

        //
        // TODO: Check if this really does capture STDERR or not!
        //

        if (logOutput) {
            File file = getLogFile();
            FileUtils.forceMkdir(file.getParentFile());

            log.info("Redirecting output to: " + file);

            java.setOutput(file);
        }

        // Holds any exception that was thrown during startup
        final ObjectHolder errorHolder = new ObjectHolder();

        StopWatch watch = new StopWatch();
        watch.start();

        // Start the server int a seperate thread
        Thread t = new Thread("Geronimo Server Runner") {
            public void run() {
                try {
                    java.execute();
                }
                catch (Exception e) {
                    errorHolder.set(e);

                    //
View Full Code Here

            args += " " + files[i];
        }

        String systemClassPath = System.getProperty("java.class.path");
        String execClassPath = FileUtils.translatePath(systemClassPath + ":" + classpath);
        Java ddCreatorTask = new Java(this);
        ddCreatorTask.setFork(true);
        ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper");
        Commandline.Argument arguments = ddCreatorTask.createArg();
        arguments.setLine(args);
        ddCreatorTask.setClasspath(new Path(getProject(), execClassPath));
        if (ddCreatorTask.executeJava() != 0) {
            throw new BuildException("Execution of ddcreator helper failed");
        }
    }
View Full Code Here

     *      jarfile.
     */
    private void buildWebsphereJar(File sourceJar, File destJar) {
        try {
            if (ejbdeploy) {
                Java javaTask = new Java(getTask());
                // Set the JvmArgs
                javaTask.createJvmarg().setValue("-Xms64m");
                javaTask.createJvmarg().setValue("-Xmx128m");

                // Set the Environment variable
                Environment.Variable var = new Environment.Variable();

                var.setKey("websphere.lib.dir");
                File libdir = new File(websphereHome, "lib");
                var.setValue(libdir.getAbsolutePath());
                javaTask.addSysproperty(var);

                // Set the working directory
                javaTask.setDir(websphereHome);

                // Set the Java class name
                javaTask.setTaskName("ejbdeploy");
                javaTask.setClassname("com.ibm.etools.ejbdeploy.EJBDeploy");

                javaTask.createArg().setValue(sourceJar.getPath());
                javaTask.createArg().setValue(tempdir);
                javaTask.createArg().setValue(destJar.getPath());
                javaTask.createArg().setLine(getOptions());
                if (getCombinedClasspath() != null
                    && getCombinedClasspath().toString().length() > 0) {
                    javaTask.createArg().setValue("-cp");
                    javaTask.createArg().setValue(getCombinedClasspath().toString());
                }

                Path classpath = wasClasspath;

                if (classpath == null) {
                    classpath = getCombinedClasspath();
                }

                if (classpath != null) {
                    javaTask.setClasspath(classpath);
                    javaTask.setFork(true);
                } else {
                    javaTask.setFork(true);
                }

                log("Calling websphere.ejbdeploy for " + sourceJar.toString(),
                    Project.MSG_VERBOSE);

                javaTask.execute();
            }
        } catch (Exception e) {
            // Have to catch this because of the semantics of calling main()
            String msg = "Exception while calling ejbdeploy. Details: " + e.toString();

View Full Code Here

        if (managementPassword == null) {
            throw new BuildException("You must supply a management password "
                                    + "to start the server");
        }

        Java weblogicServer = new Java(this);
        weblogicServer.setTaskName(getTaskName());
        weblogicServer.setFork(true);
        weblogicServer.setDir(weblogicSystemHome);
        weblogicServer.setClassname(weblogicMainClass);

        String jvmArgs = additionalJvmArgs;

        jvmArgs += " -Dweblogic.Domain=" + weblogicDomainName;
        jvmArgs += " -Dweblogic.Name=" + weblogicSystemName;
        jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome;

        jvmArgs += " -Dbea.home=" + beaHome;
        jvmArgs += " -Djava.security.policy==" + securityPolicyFile;

        jvmArgs += " -Dweblogic.management.username=" + managementUsername;
        jvmArgs += " -Dweblogic.management.password=" + managementPassword;
        if (pkPassword != null) {
            jvmArgs += " -Dweblogic.pkpassword=" + pkPassword;
        }


        weblogicServer.createJvmarg().setLine(jvmArgs);
        weblogicServer.createArg().setLine(additionalArgs);

        if (classpath != null) {
            weblogicServer.setClasspath(classpath);
        }

        if (weblogicServer.executeJava() != 0) {
            throw new BuildException("Execution of weblogic server failed");
        }
     }
View Full Code Here

                    + " not found in weblogic home " + weblogicSystemHome
                    + " or as absolute file");
            }
        }

        Java weblogicServer = new Java(this);
        weblogicServer.setFork(true);
        weblogicServer.setClassname(weblogicMainClass);

        String jvmArgs = additionalJvmArgs;

        if (weblogicClasspath != null) {
            jvmArgs += " -Dweblogic.class.path=" + weblogicClasspath;
        }

        jvmArgs += " -Djava.security.manager -Djava.security.policy==" + securityPolicyFile;
        jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome;
        jvmArgs += " -Dweblogic.system.name=" + weblogicSystemName;
        jvmArgs += " -Dweblogic.system.propertiesFile=" + weblogicPropertiesFile;

        weblogicServer.createJvmarg().setLine(jvmArgs);
        weblogicServer.createArg().setLine(additionalArgs);

        if (classpath != null) {
            weblogicServer.setClasspath(classpath);
        }
        if (weblogicServer.executeJava() != 0) {
            throw new BuildException("Execution of weblogic server failed");
        }
    }
View Full Code Here

        // get all the files in the descriptor directory
        DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);

        String[] files = ds.getIncludedFiles();

        Java helperTask = new Java(this);
        helperTask.setFork(true);
        helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper");
        String args = "";
        args += " " + descriptorDirectory;
        args += " " + generatedFilesDirectory;
        args += " " + sourceDirectory;
        args += " " + generatedManifestFile;
        args += " " + keepgenerated;

        for (int i = 0; i < files.length; ++i) {
            args += " " + files[i];
        }

        Commandline.Argument arguments = helperTask.createArg();
        arguments.setLine(args);
        helperTask.setClasspath(new Path(getProject(), execClassPath));
        if (helperTask.executeJava() != 0) {
            throw new BuildException("Execution of ejbc helper failed");
        }
    }
View Full Code Here

        //Weblogic.jspc calls System.exit() ... have to fork
        // Therefore, takes loads of time
        // Can pass directories at a time (*.jsp) but easily runs out of
        // memory on hefty dirs (even on  a Sun)
        Java helperTask = new Java(this);
        helperTask.setFork(true);
        helperTask.setClassname("weblogic.jspc");
        helperTask.setTaskName(getTaskName());
        // CheckStyle:MagicNumber OFF
        String[] args = new String[12];
        // CheckStyle:MagicNumber ON

        File jspFile = null;
        String parents = "";
        int j = 0;
        //XXX  this array stuff is a remnant of prev trials.. gotta remove.
        args[j++] = "-d";
        args[j++] = destinationDirectory.getAbsolutePath().trim();
        args[j++] = "-docroot";
        args[j++] = sourceDirectory.getAbsolutePath().trim();
        args[j++] = "-keepgenerated"//TODO: Parameterise ??
        //Call compiler as class... dont want to fork again
        //Use classic compiler -- can be parameterised?
        args[j++] "-compilerclass";
        args[j++] = "sun.tools.javac.Main";
        //Weblogic jspc does not seem to work unless u explicitly set this...
        // Does not take the classpath from the env....
        // Am i missing something about the Java task??
        args[j++] = "-classpath";
        args[j++] = compileClasspath.toString();

        this.scanDir(files);
        log("Compiling " + filesToDo.size() + " JSP files");

        for (int i = 0; i < filesToDo.size(); i++) {
            //XXX
            // All this to get package according to weblogic standards
            // Can be written better... this is too hacky!
            // Careful.. similar code in scanDir , but slightly different!!
            String filename = (String) filesToDo.elementAt(i);
            jspFile = new File(filename);
            args[j] = "-package";
            parents = jspFile.getParent();
            if ((parents != null&& (!("").equals(parents))) {
                parents =  this.replaceString(parents, File.separator, "_.");
                args[j + 1] = destinationPackage + "." + "_" + parents;
            } else {
                args[j + 1] = destinationPackage;
            }


            args[j + 2] =  sourceDirectory + File.separator + filename;
            helperTask.clearArgs();

            // CheckStyle:MagicNumber OFF
            for (int x = 0; x < j + 3; x++) {
                helperTask.createArg().setValue(args[x]);
            }
            // CheckStyle:MagicNumber ON

            helperTask.setClasspath(compileClasspath);
            if (helperTask.executeJava() != 0) {
                log(filename + " failed to compile", Project.MSG_WARN);
            }
        }
    }
View Full Code Here

        log("verify BAS " + sourceJar, Project.MSG_INFO);
        try  {
            String args = verifyArgs;
            args += " " + sourceJar.getPath();

            javaTask = new Java(getTask());
            javaTask.setTaskName("verify");
            javaTask.setClassname(VERIFY);
            Commandline.Argument arguments = javaTask.createArg();
            arguments.setLine(args);
            Path classpath = getCombinedClasspath();
View Full Code Here

     * @param genericJarFile jar file.
     * @param ejbFiles the hashtable.
     */
    private void addGenICGeneratedFiles(
        File genericJarFile, Hashtable ejbFiles) {
        Java genicTask = null;    // GenIC task
        String genicClass = null; // GenIC class (3 are supported for various
                                  // versions
        if (nogenic) {
            return;
        }

        genicTask = new Java(getTask());
        genicTask.setTaskName("genic");
        genicTask.setFork(true);

        // jonasroot
        genicTask.createJvmarg().setValue("-Dinstall.root=" + jonasroot);

        // java policy file
        String jonasConfigDir = jonasroot + File.separator + "config";
        File javaPolicyFile = new File(jonasConfigDir, "java.policy");
        if (javaPolicyFile.exists()) {
            genicTask.createJvmarg().setValue("-Djava.security.policy="
                              + javaPolicyFile.toString());
        }

        // outputdir
        try {
            outputdir = createTempDir();
        } catch (IOException aIOException) {
            String msg = "Cannot create temp dir: " + aIOException.getMessage();
            throw new BuildException(msg, aIOException);
        }
        log("Using temporary output directory: " + outputdir, Project.MSG_VERBOSE);

        genicTask.createArg().setValue("-d");
        genicTask.createArg().setFile(outputdir);

        // work around a bug of GenIC 2.5
        String key;
        File f;
        Enumeration keys = ejbFiles.keys();
        while (keys.hasMoreElements()) {
            key = (String) keys.nextElement();
            f = new File(outputdir + File.separator + key);
            f.getParentFile().mkdirs();
        }
        log("Worked around a bug of GenIC 2.5.", Project.MSG_VERBOSE);

        // classpath
        Path classpath = getCombinedClasspath();
        if (classpath == null) {
            classpath = new Path(getTask().getProject());
        }
        classpath.append(new Path(classpath.getProject(), jonasConfigDir));
        classpath.append(new Path(classpath.getProject(), outputdir.toString()));

        // try to create the classpath for the correct ORB
        if (orb != null) {
            String orbJar = jonasroot + File.separator + "lib"
                + File.separator + orb + "_jonas.jar";
            classpath.append(new Path(classpath.getProject(), orbJar));
        }
        log("Using classpath: " + classpath.toString(), Project.MSG_VERBOSE);
        genicTask.setClasspath(classpath);

        // class name (search in the classpath provided for the ejbjar element)
        genicClass = getGenicClassName(classpath);
        if (genicClass == null) {
            log("Cannot find GenIC class in classpath.", Project.MSG_ERR);
            throw new BuildException("GenIC class not found, please check the classpath.");
        } else {
            log("Using '" + genicClass + "' GenIC class." , Project.MSG_VERBOSE);
            genicTask.setClassname(genicClass);
        }

        // keepgenerated
        if (keepgenerated) {
            genicTask.createArg().setValue("-keepgenerated");
        }

        // nocompil
        if (nocompil) {
            genicTask.createArg().setValue("-nocompil");
        }

        // novalidation
        if (novalidation) {
            genicTask.createArg().setValue("-novalidation");
        }

        // javac
        if (javac != null) {
            genicTask.createArg().setValue("-javac");
            genicTask.createArg().setLine(javac);
        }

        // javacopts
        if (javacopts != null && !javacopts.equals("")) {
            genicTask.createArg().setValue("-javacopts");
            genicTask.createArg().setLine(javacopts);
        }

        // rmicopts
        if (rmicopts != null && !rmicopts.equals("")) {
            genicTask.createArg().setValue("-rmicopts");
            genicTask.createArg().setLine(rmicopts);
        }

        // secpropag
        if (secpropag) {
            genicTask.createArg().setValue("-secpropag");
        }

        // verbose
        if (verbose) {
            genicTask.createArg().setValue("-verbose");
        }

        // additionalargs
        if (additionalargs != null) {
            genicTask.createArg().setValue(additionalargs);
        }

        // the generated classes must not be added in the generic JAR!
        // is that buggy on old JOnAS (2.4) ??
        genicTask.createArg().setValue("-noaddinjar");

        // input file to process by GenIC
        genicTask.createArg().setValue(genericJarFile.getPath());

        // calling GenIC task
        log("Calling " + genicClass + " for " + getConfig().descriptorDir
            + File.separator + descriptorName + ".", Project.MSG_VERBOSE);

        if (genicTask.executeJava() != 0) {

            // the method deleteOnExit() do not work because the directory is not empty
            log("Deleting temp output directory '" + outputdir + "'.", Project.MSG_VERBOSE);
            deleteAllFiles(outputdir);

View Full Code Here

TOP

Related Classes of org.apache.tools.ant.taskdefs.Java

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.