Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

In this page you can find the example usage for java.io File getCanonicalPath.

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:eu.annocultor.utils.XmlUtils.java

public static void main(String... args) throws Exception {
    // Handling command line parameters with Apache Commons CLI
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName(OPT_FN).hasArg().isRequired()
            .withDescription("XML file name to be pretty-printed").create(OPT_FN));

    // now lets parse the input
    CommandLineParser parser = new BasicParser();
    CommandLine cmd;//from  ww w  . j a va  2 s  .  co m
    try {
        cmd = parser.parse(options, Utils.getCommandLineFromANNOCULTOR_ARGS(args));
    } catch (ParseException pe) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("pretty", options);
        return;
    }

    List<File> files = Utils.expandFileTemplateFrom(new File("."), cmd.getOptionValue(OPT_FN));
    for (File file : files) {
        // XML pretty print
        System.out.println("Pretty-print for file " + file);
        if (file.exists())
            prettyPrintXmlFileSAX(file.getCanonicalPath());
        else
            throw new Exception("File not found: " + file.getCanonicalPath());
    }
}

From source file:com.cloudera.recordbreaker.learnstructure.test.GenerateRandomData.java

/**
 *//*from w w  w .  j av a2s. c  om*/
public static void main(String argv[]) throws IOException {
    CommandLine cmd = null;
    Options options = new Options();
    options.addOption("?", false, "Help for command-line");
    options.addOption("n", true, "Number elts to emit");

    try {
        CommandLineParser parser = new PosixParser();
        cmd = parser.parse(options, argv);
    } catch (ParseException pe) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateRandomData", options, true);
        System.exit(-1);
    }

    if (cmd.hasOption("?")) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateRandomData", options, true);
        System.exit(0);
    }

    int numToEmit = 100;
    if (cmd.hasOption("n")) {
        try {
            numToEmit = Integer.parseInt(cmd.getOptionValue("n"));
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }

    String[] argArray = cmd.getArgs();
    if (argArray.length == 0) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateRandomData", options, true);
        System.exit(0);
    }
    File inputSchemaFile = new File(argArray[0]).getCanonicalFile();
    File outputDataFile = new File(argArray[1]).getCanonicalFile();
    if (outputDataFile.exists()) {
        System.err.println("Output file already exists: " + outputDataFile.getCanonicalPath());
        System.exit(0);
    }

    GenerateRandomData grd = new GenerateRandomData();
    Schema schema = Schema.parse(inputSchemaFile);

    GenericDatumWriter datum = new GenericDatumWriter(schema);
    DataFileWriter out = new DataFileWriter(datum);
    out.create(schema, outputDataFile);
    try {
        for (int i = 0; i < numToEmit; i++) {
            out.append((GenericData.Record) grd.generateData(schema));
        }
    } finally {
        out.close();
    }
}

From source file:com.kynetx.ParseRuleset.java

public static void main(String[] args) throws Exception {
    File f = new File(args[0]);
    int notparsed = 0;
    int parsed = 0;

    File[] files = null;/*  w  w w  .  j av  a 2s .c  om*/
    if (f.isDirectory()) {
        files = f.listFiles();
    } else {
        files = new File[1];
        files[0] = new File(args[0]);
    }
    for (int i = 0; i < files.length; i++) {
        File thefile = files[i];
        long start = System.currentTimeMillis();
        boolean skipfile = false;
        for (int ii = 0; ii < ignore.length; ii++) {
            if (thefile.getCanonicalPath().indexOf(ignore[ii] + ".krl") > 0) {
                skipfile = true;
                break;
            }
        }
        if (thefile.length() == 0 || thefile.length() == 31 || thefile.length() == 162 || skipfile) {
            notparsed = notparsed + 1;
            //               System.out.println("Skipping: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            //               System.out.println("Skipping " + thefile);
            continue;
        }
        parsed = parsed + 1;
        try {
            ANTLRFileStream input = new ANTLRFileStream(thefile.getCanonicalPath());
            com.kynetx.RuleSetLexer lexer = new com.kynetx.RuleSetLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            com.kynetx.RuleSetParser parser = new com.kynetx.RuleSetParser(tokens);
            parser.ruleset();
            JSONObject js = new JSONObject(parser.rule_json);
            if (parser.parse_errors.size() > 0) {
                for (int ii = 0; ii < parser.parse_errors.size(); ii++) {
                    System.err
                            .println("ERROR FOUND " + parser.parse_errors.get(ii) + " - " + thefile.toString());
                }
            }
            //               System.out.println("Parsed: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            //System.out.println(unescapeUnicode(js.toString()));
            System.out.println(js.toString());
            //System.out.println("=============");
            //System.out.println(js.toString());
        } catch (Exception e) {
            //               System.out.println("Error: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            System.out.println("Error " + thefile + " " + e.getMessage());
            e.printStackTrace();
        }
    }
    //         System.out.println("Not Parsed " + notparsed);
    //         System.out.println("Parsed " + parsed);

}

From source file:it.univpm.deit.semedia.musicuri.utils.experimental.LambdaCalculator.java

public static void main(String[] args) throws Exception {

    //*****************************************************************************
    //*************************   F I L E   I N P U T   ***************************
    //*****************************************************************************

    if ((args.length == 1) && (new File(args[0]).exists())) {
        // get the file's canonical path
        File givenHandle = new File(args[0]);
        String queryAudioCanonicalPath = givenHandle.getCanonicalPath();
        System.out.println("Input: " + queryAudioCanonicalPath);

        //PerformanceStatistic tempStat;
        SummaryStatistics lambdaSummary = SummaryStatistics.newInstance();

        if (givenHandle.isDirectory()) {

            File[] list = givenHandle.listFiles();
            if (list.length == 0) {
                System.out.println("Directory is empty");
                return;
            } else {
                ArrayList allStats = new ArrayList();
                File currentFile;
                for (int i = 0; i < list.length; i++) {
                    currentFile = list[i];
                    try {
                        if (Toolset.isSupportedAudioFile(currentFile)) {
                            System.out.println("\nCalculating optimal lambda : " + currentFile.getName());
                            lambdaSummary.addValue(getBestLambda(new MusicURIQuery(currentFile)));
                        }//from  w  ww.ja va  2s. co m
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                //               System.out.println("\n\nStatistics for Test Case: " + queryAudioCanonicalPath);
                //               mergeStatistics(allStats);
            }
        }
        if (givenHandle.isFile()) {
            if (Toolset.isSupportedAudioFile(givenHandle)) {
                //               tempStat = getBestLambda (new MusicURIQuery(givenHandle));
                //               if (tempStat!=null)
                //               {
                //                  //tempStat.printStatistics();
                //                  ArrayList allStats = new ArrayList();
                //                  allStats.add(tempStat);
                //                  mergeStatistics(allStats);
                //               }
                //               else 
                //                  System.out.println("Error in identification ");
            }
        }

    } //end if
    else {
        System.err.println("LambdaCalculator");
        System.err.println("Usage: java tester.LambdaCalculator {directory}");
    }

}

From source file:org.soasecurity.wso2.mutual.auth.oauth2.client.MutualSSLOAuthClient.java

public static void main(String[] args) throws Exception {

    File file = new File((new File(".")).getCanonicalPath() + File.separator + "src" + File.separator + "main"
            + File.separator + "resources" + File.separator + "keystore" + File.separator + keyStoreName);

    if (!file.exists()) {
        throw new Exception("Key Store file can not be found in " + file.getCanonicalPath());
    }//from  w w w .  j  a  v a2  s .  c  o m

    //Set trust store, you need to import server's certificate of CA certificate chain in to this
    //key store
    System.setProperty("javax.net.ssl.trustStore", file.getCanonicalPath());
    System.setProperty("javax.net.ssl.trustStorePassword", keyStorePassword);

    //Set key store, this must contain the user private key
    //here we have use both trust store and key store as the same key store
    //But you can use a separate key store for key store an trust store.
    System.setProperty("javax.net.ssl.keyStore", file.getCanonicalPath());
    System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);

    HttpClient client = new HttpClient();

    HttpMethod method = new PostMethod(endPoint);

    // Base64 encoded client id & secret
    method.setRequestHeader("Authorization",
            "Basic T09pN2dpUjUwdDZtUmU1ZkpmWUhVelhVa1QwYTpOOUI2dDZxQ0E2RFp2eTJPQkFIWDhjVlI1eUlh");
    method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    NameValuePair pair1 = new NameValuePair();
    pair1.setName("grant_type");
    pair1.setValue("x509");

    NameValuePair pair2 = new NameValuePair();
    pair2.setName("username");
    pair2.setValue("asela");

    NameValuePair pair3 = new NameValuePair();
    pair3.setName("password");
    pair3.setValue("asela");

    method.setQueryString(new NameValuePair[] { pair1, pair2, pair3 });

    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {

        System.out.println("Failed: " + method.getStatusLine());

    } else {

        byte[] responseBody = method.getResponseBody();

        System.out.println(new String(responseBody));
    }
}

From source file:D20140128.ApacheXMLGraphicsTest.TilingPatternExample.java

/**
 * Command-line interface//from www  . j  a  v a  2s  . com
 * @param args command-line arguments
 */
public static void main(String[] args) {
    try {
        File targetDir;
        if (args.length >= 1) {
            targetDir = new File(args[0]);
        } else {
            targetDir = new File(".");
        }
        if (!targetDir.exists()) {
            System.err.println("Target Directory does not exist: " + targetDir);
        }
        File outputFile = new File(targetDir, "tiling-example.ps");
        File pngFile = new File(targetDir, "tiling-example.png");
        TilingPatternExample app = new TilingPatternExample();
        app.generatePSusingJava2D(outputFile);
        System.out.println("File written: " + outputFile.getCanonicalPath());
        app.generatePNGusingJava2D(pngFile);
        System.out.println("File written: " + pngFile.getCanonicalPath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.prozesskraft.pkraft.Createmap.java

public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException {

    //      try/*from  w w w.  jav  a  2  s .  co  m*/
    //      {
    //         if (args.length != 3)
    //         {
    //            System.out.println("Please specify processdefinition file (xml) and an outputfilename");
    //         }
    //         
    //      }
    //      catch (ArrayIndexOutOfBoundsException e)
    //      {
    //         System.out.println("***ArrayIndexOutOfBoundsException: Please specify processdefinition.xml, openoffice_template.od*, newfile_for_processdefinitions.odt\n" + e.toString());
    //      }

    /*----------------------------
      get options from ini-file
    ----------------------------*/
    File inifile = new java.io.File(
            WhereAmI.getInstallDirectoryAbsolutePath(Createmap.class) + "/" + "../etc/pkraft-createmap.ini");

    if (inifile.exists()) {
        try {
            ini = new Ini(inifile);
        } catch (InvalidFileFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        System.err.println("ini file does not exist: " + inifile.getAbsolutePath());
        System.exit(1);
    }

    /*----------------------------
      create boolean options
    ----------------------------*/
    Option ohelp = new Option("help", "print this message");

    /*----------------------------
      create argument options
    ----------------------------*/
    Option ooutput = OptionBuilder.withArgName("FILE").hasArg()
            .withDescription("[mandatory; default: process.dot] file for generated map.")
            //            .isRequired()
            .create("output");

    Option odefinition = OptionBuilder.withArgName("FILE").hasArg()
            .withDescription("[mandatory] process definition file.")
            //            .isRequired()
            .create("definition");

    /*----------------------------
      create options object
    ----------------------------*/
    Options options = new Options();

    options.addOption(ohelp);
    options.addOption(ooutput);
    options.addOption(odefinition);

    /*----------------------------
      create the parser
    ----------------------------*/
    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        commandline = parser.parse(options, args);

    } catch (Exception exp) {
        // oops, something went wrong
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
        exiter();
    }

    /*----------------------------
      usage/help
    ----------------------------*/
    if (commandline.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("createmap", options);
        System.out.println("");
        System.out.println("author: " + author + " | version: " + version + " | date: " + date);
        System.exit(0);
    }

    /*----------------------------
      ueberpruefen ob eine schlechte kombination von parametern angegeben wurde
    ----------------------------*/
    if (!(commandline.hasOption("definition"))) {
        System.err.println("option -definition is mandatory.");
        exiter();
    }

    if (!(commandline.hasOption("output"))) {
        System.err.println("option -output is mandatory.");
        exiter();
    }

    /*----------------------------
      die lizenz ueberpruefen und ggf abbrechen
    ----------------------------*/

    // check for valid license
    ArrayList<String> allPortAtHost = new ArrayList<String>();
    allPortAtHost.add(ini.get("license-server", "license-server-1"));
    allPortAtHost.add(ini.get("license-server", "license-server-2"));
    allPortAtHost.add(ini.get("license-server", "license-server-3"));

    MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1");

    // lizenz-logging ausgeben
    for (String actLine : (ArrayList<String>) lic.getLog()) {
        System.err.println(actLine);
    }

    // abbruch, wenn lizenz nicht valide
    if (!lic.isValid()) {
        System.exit(1);
    }

    /*----------------------------
      die eigentliche business logic
    ----------------------------*/
    Process p1 = new Process();
    java.io.File output = new java.io.File(commandline.getOptionValue("output"));

    if (output.exists()) {
        System.err.println("warn: already exists: " + output.getCanonicalPath());
        exiter();
    }

    p1.setInfilexml(commandline.getOptionValue("definition"));
    System.err.println("info: reading process definition " + commandline.getOptionValue("definition"));

    // dummy process
    Process p2 = null;

    try {
        p2 = p1.readXml();
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.err.println("error");
        exiter();
    }

    // den wrapper process generieren
    ArrayList<String> dot = p2.getProcessAsDotGraph();

    // dot file rausschreiben
    writeFile.writeFile(output, dot);
}

From source file:com.tamingtext.classifier.bayes.ClassifyDocument.java

public static void main(String[] args) {
    log.info("Command-line arguments: " + Arrays.toString(args));

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputOpt = obuilder.withLongName("input").withRequired(true)
            .withArgument(abuilder.withName("input").withMinimum(1).withMaximum(1).create())
            .withDescription("Input file").withShortName("i").create();

    Option modelOpt = obuilder.withLongName("model").withRequired(true)
            .withArgument(abuilder.withName("model").withMinimum(1).withMaximum(1).create())
            .withDescription("Model to use when classifying data").withShortName("m").create();

    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();//from  w  w  w  . j  a  v a2 s  . c  om

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(modelOpt).withOption(helpOpt)
            .create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        File inputFile = new File(cmdLine.getValue(inputOpt).toString());

        if (!inputFile.isFile()) {
            throw new IllegalArgumentException(inputFile + " does not exist or is not a file");
        }

        File modelDir = new File(cmdLine.getValue(modelOpt).toString());

        if (!modelDir.isDirectory()) {
            throw new IllegalArgumentException(modelDir + " does not exist or is not a directory");
        }

        BayesParameters p = new BayesParameters();
        p.set("basePath", modelDir.getCanonicalPath());
        Datastore ds = new InMemoryBayesDatastore(p);
        Algorithm a = new BayesAlgorithm();
        ClassifierContext ctx = new ClassifierContext(a, ds);
        ctx.initialize();

        //TODO: make the analyzer configurable
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
        TokenStream ts = analyzer.tokenStream(null,
                new InputStreamReader(new FileInputStream(inputFile), "UTF-8"));

        ArrayList<String> tokens = new ArrayList<String>(1000);
        while (ts.incrementToken()) {
            tokens.add(ts.getAttribute(CharTermAttribute.class).toString());
        }
        String[] document = tokens.toArray(new String[tokens.size()]);

        ClassifierResult[] cr = ctx.classifyDocument(document, "unknown", 5);

        for (ClassifierResult r : cr) {
            System.err.println(r.getLabel() + "\t" + r.getScore());
        }
    } catch (OptionException e) {
        log.error("Exception", e);
        CommandLineUtil.printHelp(group);
    } catch (IOException e) {
        log.error("IOException", e);
    } catch (InvalidDatastoreException e) {
        log.error("InvalidDataStoreException", e);
    } finally {

    }
}

From source file:de.prozesskraft.pkraft.Wrap.java

public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException {

    //      try/* w  ww  .  ja v  a  2s. c  o m*/
    //      {
    //         if (args.length != 3)
    //         {
    //            System.out.println("Please specify processdefinition file (xml) and an outputfilename");
    //         }
    //         
    //      }
    //      catch (ArrayIndexOutOfBoundsException e)
    //      {
    //         System.out.println("***ArrayIndexOutOfBoundsException: Please specify processdefinition.xml, openoffice_template.od*, newfile_for_processdefinitions.odt\n" + e.toString());
    //      }

    /*----------------------------
      get options from ini-file
    ----------------------------*/
    File inifile = new java.io.File(
            WhereAmI.getInstallDirectoryAbsolutePath(Wrap.class) + "/" + "../etc/pkraft-wrap.ini");

    if (inifile.exists()) {
        try {
            ini = new Ini(inifile);
        } catch (InvalidFileFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        System.err.println("ini file does not exist: " + inifile.getAbsolutePath());
        System.exit(1);
    }

    /*----------------------------
      create boolean options
    ----------------------------*/
    Option ohelp = new Option("help", "print this message");
    Option ov = new Option("v", "prints version and build-date");

    /*----------------------------
      create argument options
    ----------------------------*/
    Option ooutput = OptionBuilder.withArgName("FILE").hasArg()
            .withDescription("[mandatory; default: .] file for generated wrapper process.")
            //            .isRequired()
            .create("output");

    Option odefinition = OptionBuilder.withArgName("FILE").hasArg()
            .withDescription("[mandatory] process definition file.")
            //            .isRequired()
            .create("definition");

    /*----------------------------
      create options object
    ----------------------------*/
    Options options = new Options();

    options.addOption(ohelp);
    options.addOption(ov);
    options.addOption(ooutput);
    options.addOption(odefinition);

    /*----------------------------
      create the parser
    ----------------------------*/
    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        commandline = parser.parse(options, args);

    } catch (Exception exp) {
        // oops, something went wrong
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
        exiter();
    }

    /*----------------------------
      usage/help
    ----------------------------*/
    if (commandline.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("wrap", options);
        System.exit(0);
    }

    else if (commandline.hasOption("v")) {
        System.out.println("web:     www.prozesskraft.de");
        System.out.println("version: [% version %]");
        System.out.println("date:    [% date %]");
        System.exit(0);
    }

    /*----------------------------
      ueberpruefen ob eine schlechte kombination von parametern angegeben wurde
    ----------------------------*/
    if (!(commandline.hasOption("definition"))) {
        System.err.println("option -definition is mandatory.");
        exiter();
    }

    if (!(commandline.hasOption("output"))) {
        System.err.println("option -output is mandatory.");
        exiter();
    }

    /*----------------------------
      die lizenz ueberpruefen und ggf abbrechen
    ----------------------------*/

    // check for valid license
    ArrayList<String> allPortAtHost = new ArrayList<String>();
    allPortAtHost.add(ini.get("license-server", "license-server-1"));
    allPortAtHost.add(ini.get("license-server", "license-server-2"));
    allPortAtHost.add(ini.get("license-server", "license-server-3"));

    MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1");

    // lizenz-logging ausgeben
    for (String actLine : (ArrayList<String>) lic.getLog()) {
        System.err.println(actLine);
    }

    // abbruch, wenn lizenz nicht valide
    if (!lic.isValid()) {
        System.exit(1);
    }

    /*----------------------------
      die eigentliche business logic
    ----------------------------*/
    Process p1 = new Process();
    java.io.File output = new java.io.File(commandline.getOptionValue("output"));

    if (output.exists()) {
        System.err.println("warn: already exists: " + output.getCanonicalPath());
        exiter();
    }

    p1.setInfilexml(commandline.getOptionValue("definition"));
    System.err.println("info: reading process definition " + commandline.getOptionValue("definition"));

    // dummy process
    Process p2 = null;

    try {
        p2 = p1.readXml();
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.err.println("error");
        exiter();
    }

    // den wrapper process generieren
    Process p3 = p2.getProcessAsWrapper();
    p3.setOutfilexml(output.getAbsolutePath());

    // den neuen wrap-process rausschreiben
    p3.writeXml();
}

From source file:edu.harvard.med.screensaver.io.Spammer.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {

    CommandLineApplication app = new CommandLineApplication(args);
    String[] option = MAIL_RECIPIENT_LIST_OPTION;
    app.addCommandLineOption(OptionBuilder.withType(Integer.class).hasArg().isRequired()
            .withArgName(option[SHORT_OPTION_INDEX]).withDescription(option[DESCRIPTION_INDEX])
            .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX]));

    option = MAIL_CC_LIST_OPTION;//from w ww  .  j a  v a2s .  c  om
    app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_REPLYTO_LIST_OPTION;
    app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_MESSAGE_OPTION;
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_FILE_ATTACHMENT;
    app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_SUBJECT_OPTION;
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_SERVER_OPTION;
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_USERNAME_OPTION;
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_USER_PASSWORD_OPTION;
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_FROM_OPTION;
    app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));

    option = MAIL_USE_SMTPS;
    app.addCommandLineOption(
            OptionBuilder.withArgName(option[SHORT_OPTION_INDEX]).withDescription(option[DESCRIPTION_INDEX])
                    .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX]));

    app.processOptions(true, true);

    String message = app.getCommandLineOptionValue(MAIL_MESSAGE_OPTION[SHORT_OPTION_INDEX]);

    File attachedFile = null;
    if (app.isCommandLineFlagSet(MAIL_FILE_ATTACHMENT[SHORT_OPTION_INDEX])) {
        attachedFile = new File(app.getCommandLineOptionValue(MAIL_FILE_ATTACHMENT[SHORT_OPTION_INDEX]));
        if (!attachedFile.exists()) {
            log.error("Specified file does not exist: " + attachedFile.getCanonicalPath());
            System.exit(1);
        }
    }

    String subject = app.getCommandLineOptionValue(MAIL_SUBJECT_OPTION[SHORT_OPTION_INDEX]);
    String recipientlist = app.getCommandLineOptionValue(MAIL_RECIPIENT_LIST_OPTION[SHORT_OPTION_INDEX]);
    String[] recipients = recipientlist.split(DELIMITER);

    String[] ccrecipients = null;
    if (app.isCommandLineFlagSet(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX])) {
        String cclist = app.getCommandLineOptionValue(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX]);
        ccrecipients = cclist.split(DELIMITER);
    }

    String replytos = null;
    if (app.isCommandLineFlagSet(MAIL_REPLYTO_LIST_OPTION[SHORT_OPTION_INDEX])) {
        replytos = app.getCommandLineOptionValue(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX]);
    }

    String mailHost = app.getCommandLineOptionValue(MAIL_SERVER_OPTION[SHORT_OPTION_INDEX]);
    String username = app.getCommandLineOptionValue(MAIL_USERNAME_OPTION[SHORT_OPTION_INDEX]);
    String password = app.getCommandLineOptionValue(MAIL_USER_PASSWORD_OPTION[SHORT_OPTION_INDEX]);
    boolean useSmtps = app.isCommandLineFlagSet(MAIL_USE_SMTPS[SHORT_OPTION_INDEX]);

    String mailFrom = username;
    if (app.isCommandLineFlagSet(MAIL_FROM_OPTION[SHORT_OPTION_INDEX])) {
        mailFrom = app.getCommandLineOptionValue(MAIL_FROM_OPTION[SHORT_OPTION_INDEX]);
    }

    SmtpEmailService service = new SmtpEmailService(mailHost, username, replytos, password, useSmtps);
    service.send(subject, message, mailFrom, recipients, ccrecipients, attachedFile);
}