Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2005 Jeff Genender.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.codehaus.mojo.jboss;
 
 
 
 import java.net.URL;
 import java.io.File;
Created by IntelliJ IDEA. User: jeffgenender Date: Oct 1, 2005 Time: 12:12:56 PM To change this template use File | Settings | File Templates.
 
 public abstract class AbstractJBossMojo extends AbstractMojo {

    
The location of JBoss Home. This is a required configuration parameter (unless JBOSS_HOME is set).

Parameter:
expression="ENV"
Required:
 
     protected String jbossHome;

    
The server name.

Parameter:
expression="default"
Required:
 
     protected String serverName;
 
     protected void checkConfig() throws MojoExecutionException {
         if ( == null || .equals("ENV")) {
             if (SystemUtils.getJavaVersion() < 1.5)
             {
                 throw new MojoExecutionException(
                         "Neither JBOSS_HOME nor the jbossHome configuration parameter is set! Also, to save you the trouble, JBOSS_HOME cannot be read running a VM < 1.5, so set the jbossHome configuration parameter or use -D.");
             }
              = System.getenv("JBOSS_HOME");
         }
 
         if ( == null) {
             throw new MojoExecutionException(
                     "Neither JBOSS_HOME nor the jbossHome configuration parameter is set!");
         }
     }
 
     protected void launch(String fNameString params)
         throws MojoExecutionException {
 
         try {
             checkConfig();
             String osName = System.getProperty("os.name");
             Runtime runtime = Runtime.getRuntime();
 
             Process p = null;
             if (osName.startsWith("Windows")) {
                 String command[] = {
                     "cmd.exe",
                     "/C",
                     "cd " +  + "\\bin & "
                         + fName + ".bat " + " " + params };
                     p = runtime.exec(command);
                     dump(p.getInputStream());
                     dump(p.getErrorStream());
             } else {
                 String command[] = {
                     "sh",
                     "-c",
                     "cd " +  + "/bin; ./"
                         + fName + ".sh " + " " + params };
                     p = runtime.exec(command);
             }
 
         } catch (Exception e) {
             throw new MojoExecutionException("Mojo error occurred: "
                     + e.getMessage(), e);
         }
    }
    protected void dump(final InputStream a_input) {
        new Thread(new Runnable() {
            public void run() {
                try {
                    byte[] b = new byte[1000];
                    while ((a_input.read(b)) != -1) {
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
New to GrepCode? Check out our FAQ X