Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource ClassPathResource.

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:de.uniwue.dmir.heatmap.util.Test.java

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

    GeoPolygonFactoryBean geoPolygonFactoryBean = new GeoPolygonFactoryBean(
            new ClassPathResource("spring/example/points/areas/polygon-turin-p3.json"));

    GeoPolygon geoPolygon = geoPolygonFactoryBean.getObject();

    IDistanceFunction<GeoCoordinates> distanceFunction = new GreatCircleDistance.Haversine();

    EquidistantProjectionTileSizeFactoryBean equidistantProjectionTileSizeFactoryBean = new EquidistantProjectionTileSizeFactoryBean(
            10., 10., false, geoPolygon.getGeoBoundingBox(), distanceFunction);

    TileSize tileSize = equidistantProjectionTileSizeFactoryBean.getObject();

    EquidistantProjection equidistantProjection = new EquidistantProjection(geoPolygon.getGeoBoundingBox(),
            tileSize);/* w w w  .  j ava  2  s .  c o m*/

    PolygonFromGeoPolygonFacoryBean polygonFromGeoPolygonFacoryBean = new PolygonFromGeoPolygonFacoryBean(
            geoPolygon, new TileCoordinates(0, 0, 0), equidistantProjection);

    Polygon polygon = polygonFromGeoPolygonFacoryBean.getObject();

    int pixelsInsidePolygon = 0;
    for (int x = 0; x < tileSize.getWidth(); x++) {
        for (int y = 0; y < tileSize.getHeight(); y++) {
            if (polygon.contains(x, y)) {
                pixelsInsidePolygon++;
            }
        }
    }

    System.out.println(pixelsInsidePolygon + " / " + tileSize.getWidth() * tileSize.getHeight());

    System.out.println(pixelsInsidePolygon * 10. * 10 / 1000 / 1000 + " / "
            + tileSize.getWidth() * tileSize.getHeight() * 10. / 1000 / 1000);
}

From source file:demo.wssec.client.Client.java

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

    if (args.length == 0) {
        System.out.println("please specify wsdl");
        System.exit(1);//from  w ww.ja v  a2 s  .  c  o m
    }

    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = new ClassPathResource("wssec-client.xml").getURL();

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    Service service = Service.create(wsdlURL, SERVICE_NAME);
    Greeter port = service.getPort(PORT_NAME, Greeter.class);

    System.out.println("Invoking greetMe...");
    try {
        String resp = port.greetMe(System.getProperty("user.name"));
        System.out.println("Server responded with: " + resp);
        System.out.println();

    } catch (Exception e) {
        System.out.println("Invocation failed with the following: " + e.getCause());
        System.out.println();
    }

    System.exit(0);
}

From source file:com.baomidou.mybatisplus.test.MybatisMapperRefreshTest.java

/**
 *  Mybatis XML /*ww w . j av a 2s .c om*/
 */
public static void main(String[] args) throws IOException, InterruptedException {
    InputStream in = UserMapperTest.class.getClassLoader().getResourceAsStream("mysql-config.xml");
    MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();
    mf.setGlobalConfig(new GlobalConfiguration(new MySqlInjector()));
    Resource[] resource = new ClassPathResource[] { new ClassPathResource("mysql/UserMapper.xml") };
    SqlSessionFactory sessionFactory = mf.build(in);
    new MybatisMapperRefresh(resource, sessionFactory, 0, 5, true);
    boolean isReturn = false;
    SqlSession session = null;
    while (!isReturn) {
        try {
            session = sessionFactory.openSession();
            UserMapper userMapper = session.getMapper(UserMapper.class);
            userMapper.selectListRow(new Pagination(1, 10));
            resource[0].getFile().setLastModified(SystemClock.now());
            session.commit();
            session.close();
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null) {
                session.close();
            }
            Thread.sleep(5000);
        }
    }
    System.exit(0);
}

From source file:org.esupportail.lecture.domain.DomainTest.java

/**
 * @param args non argumet needed//from ww  w  .  ja  v a2  s .  c om
 * @throws InternalDomainException 
 */
public static void main(final String[] args) throws InternalDomainException {
    ClassPathResource res = new ClassPathResource("properties/applicationContext.xml");
    XmlBeanFactory factory = new XmlBeanFactory(res);
    //      org.springframework.beans.factory.config.PropertyPlaceholderConfigurer prop = (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) factory.getBean("propertyConfigurer");
    facadeService = (FacadeService) factory.getBean("facadeService");

    try {
        /* Test alternative behavior */

        /* Test normal behavior */
        testGetConnectedUser();
        testGetContext();
        testGetDisplayedCategories();
        testGetVisibleCategories();
        testGetDisplayedSources();
        testGetVisibleSources();
        testGetItems();

        /* small actions */
        //         testMarkItemReadMode();
        //         testSetTreeSize();
        //         testFoldCategory();
        //         testSetItemDisplayMode();

        /* test mode EDIT */
        //         testGetConnectedUser();
        //         testGetContext();
        //         testGetVisibleCategories();
        //         testGetVisibleSources();
        //         testSubUnSubscribeToSource();

        //         testGetConnectedUser();
        //         testGetContext();
        //         testGetVisibleCategories();
        //         testSubUnSubscribeToCategory();

        /* test timeout values */
        //         testGetConnectedUser();
        //         testGetContext();
        //         testGetDisplayedCategories();
        //         testGetDisplayedSources();
        //         testTimeOutValues();

        // TODO (GB later) : tester pour un user OBLIGED et ALLOWED opour une source : 
        // le OBLIGED est prioritaire

    } catch (InternalExternalException e) {
        System.out.println("\n!!! EXCEPTION !!!");
        System.out.println("\n!!! Catching InternalExternalException");
        e.printStackTrace();
    } catch (InfoDomainException e) {
        System.out.println("\n!!! EXCEPTION !!!");
        System.out.println("\n!!! Catching InfoDomainException");
        e.printStackTrace();
    }
}

From source file:org.mzd.shap.spring.cli.ConfigSetup.java

public static void main(String[] args) {
    // check args
    if (args.length != 1) {
        exitOnError(1, null);//from ww  w  . java  2s .co  m
    }

    // check file existance
    File analyzerXML = new File(args[0]);
    if (!analyzerXML.exists()) {
        exitOnError(1, "'" + analyzerXML.getPath() + "' did not exist\n");
    }

    // prompt user whether existing data should be purged
    boolean isPurged = false;
    String ormContext = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
        System.out.println("\nDo you wish to purge the database before running setup?");
        System.out.println("WARNING: all existing data in SHAP will be lost!");
        System.out.println("Really purge? yes/[NO]");
        String ans = br.readLine();
        if (ans.toLowerCase().equals("yes")) {
            System.out.println("Purging enabled");
            ormContext = "orm-purge-context.xml";
            isPurged = true;
        } else {
            System.out.println("Purging disabled");
            ormContext = "orm-context.xml";
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }

    // run tool
    try {
        // Using a generic application context since we're referencing
        // both classpath and filesystem resources.
        GenericApplicationContext ctx = new GenericApplicationContext();
        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
        xmlReader.loadBeanDefinitions(new ClassPathResource("datasource-context.xml"),
                new ClassPathResource(ormContext), new FileSystemResource(analyzerXML));
        ctx.refresh();

        /*
         * Create an base admin user.
         */
        if (isPurged) {
            //only attempted if we've wiped the old database.
            RoleDao roleDao = (RoleDao) ctx.getBean("roleDao");
            Role adminRole = roleDao.saveOrUpdate(new Role("admin", "ROLE_ADMIN"));
            Role userRole = roleDao.saveOrUpdate(new Role("user", "ROLE_USER"));
            UserDao userDao = (UserDao) ctx.getBean("userDao");
            userDao.saveOrUpdate(new User("admin", "admin", "shap01", adminRole, userRole));
        }

        /*
         * Create some predefined analyzers. Users should have modified
         * the configuration file to suit their environment.
         */
        AnnotatorDao annotatorDao = (AnnotatorDao) ctx.getBean("annotatorDao");
        DetectorDao detectorDao = (DetectorDao) ctx.getBean("detectorDao");

        ConfigSetup config = (ConfigSetup) ctx.getBean("configuration");

        for (Annotator an : config.getAnnotators()) {
            System.out.println("Adding annotator: " + an.getName());
            annotatorDao.saveOrUpdate(an);
        }

        for (Detector dt : config.getDetectors()) {
            System.out.println("Adding detector: " + dt.getName());
            detectorDao.saveOrUpdate(dt);
        }

        System.exit(0);
    } catch (Throwable t) {
        System.err.println(t.getMessage());
        System.exit(1);
    }
}

From source file:io.s4.MainApp.java

public static void main(String args[]) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));

    options.addOption(/*ww w . j av  a  2s .co m*/
            OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a"));

    options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d"));

    options.addOption(OptionBuilder.withArgName("seedtime").hasArg()
            .withDescription("event clock initialization time").create("s"));

    options.addOption(
            OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e"));

    options.addOption(
            OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i"));

    options.addOption(
            OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t"));

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;
    String clockType = "wall";

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }

    int instanceId = -1;
    if (commandLine.hasOption("i")) {
        String instanceIdStr = commandLine.getOptionValue("i");
        try {
            instanceId = Integer.parseInt(instanceIdStr);
        } catch (NumberFormatException nfe) {
            System.err.println("Bad instance id: %s" + instanceIdStr);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("c")) {
        coreHome = commandLine.getOptionValue("c");
    }

    if (commandLine.hasOption("a")) {
        appsHome = commandLine.getOptionValue("a");
    }

    if (commandLine.hasOption("d")) {
        clockType = commandLine.getOptionValue("d");
    }

    if (commandLine.hasOption("e")) {
        extsHome = commandLine.getOptionValue("e");
    }

    String configType = "typical";
    if (commandLine.hasOption("t")) {
        configType = commandLine.getOptionValue("t");
    }

    long seedTime = 0;
    if (commandLine.hasOption("s")) {
        seedTime = Long.parseLong(commandLine.getOptionValue("s"));
    }

    File coreHomeFile = new File(coreHome);
    if (!coreHomeFile.isDirectory()) {
        System.err.println("Bad core home: " + coreHome);
        System.exit(1);
    }

    File appsHomeFile = new File(appsHome);
    if (!appsHomeFile.isDirectory()) {
        System.err.println("Bad applications home: " + appsHome);
        System.exit(1);
    }

    if (instanceId > -1) {
        System.setProperty("instanceId", "" + instanceId);
    } else {
        System.setProperty("instanceId", "" + S4Util.getPID());
    }

    List loArgs = commandLine.getArgList();

    if (loArgs.size() < 1) {
        // System.err.println("No bean configuration file specified");
        // System.exit(1);
    }

    // String s4ConfigXml = (String) loArgs.get(0);
    // System.out.println("s4ConfigXml is " + s4ConfigXml);

    ClassPathResource propResource = new ClassPathResource("s4-core.properties");
    Properties prop = new Properties();
    if (propResource.exists()) {
        prop.load(propResource.getInputStream());
    } else {
        System.err.println("Unable to find s4-core.properties. It must be available in classpath");
        System.exit(1);
    }

    ApplicationContext coreContext = null;
    String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType;
    String configPath = "";
    List<String> coreConfigUrls = new ArrayList<String>();
    File configFile = null;

    // load clock configuration
    configPath = configBase + File.separatorChar + clockType + "-clock.xml";
    coreConfigUrls.add(configPath);

    // load core config xml
    configPath = configBase + File.separatorChar + "s4-core-conf.xml";
    configFile = new File(configPath);
    if (!configFile.exists()) {
        System.err.printf("S4 core config file %s does not exist\n", configPath);
        System.exit(1);
    }

    coreConfigUrls.add(configPath);
    String[] coreConfigFiles = new String[coreConfigUrls.size()];
    coreConfigUrls.toArray(coreConfigFiles);

    String[] coreConfigFileUrls = new String[coreConfigFiles.length];
    for (int i = 0; i < coreConfigFiles.length; i++) {
        coreConfigFileUrls[i] = "file:" + coreConfigFiles[i];
    }

    coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext);
    ApplicationContext context = coreContext;

    Clock s4Clock = (Clock) context.getBean("clock");
    if (s4Clock instanceof EventClock && seedTime > 0) {
        EventClock s4EventClock = (EventClock) s4Clock;
        s4EventClock.updateTime(seedTime);
        System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime());
    }

    PEContainer peContainer = (PEContainer) context.getBean("peContainer");

    Watcher w = (Watcher) context.getBean("watcher");
    w.setConfigFilename(configPath);

    // load extension modules
    String[] configFileNames = getModuleConfigFiles(extsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
    }

    // load application modules
    configFileNames = getModuleConfigFiles(appsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
        // attach any beans that implement ProcessingElement to the PE
        // Container
        String[] processingElementBeanNames = context.getBeanNamesForType(ProcessingElement.class);
        for (String processingElementBeanName : processingElementBeanNames) {
            Object bean = context.getBean(processingElementBeanName);
            try {
                Method getS4ClockMethod = bean.getClass().getMethod("getS4Clock");

                if (getS4ClockMethod.getReturnType().equals(Clock.class)) {
                    if (getS4ClockMethod.invoke(bean) == null) {
                        Method setS4ClockMethod = bean.getClass().getMethod("setS4Clock", Clock.class);
                        setS4ClockMethod.invoke(bean, coreContext.getBean("clock"));
                    }
                }
            } catch (NoSuchMethodException mnfe) {
                // acceptable
            }
            System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id "
                    + ((ProcessingElement) bean).getId());
            peContainer.addProcessor((ProcessingElement) bean, processingElementBeanName);
        }
    }
}

From source file:org.ensembl.gti.seqstore.server.MetaDataServer.java

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

    final Logger log = LoggerFactory.getLogger(MetaDataServer.class);

    Properties properties = new Properties();
    properties.load(new ClassPathResource("metadata_server.properties").getInputStream());

    MetaDataServerOptions opts = new MetaDataServerOptions(properties);

    new JCommander(opts, args);

    log.info("Starting ENA submission handler");
    EnaCramSubmissionHandler enaHandler = new EnaCramSubmissionHandler(opts.getFtpUri(), opts.getSubmitUri(),
            opts.getCentre(), opts.getSubmitUser(), opts.getSubmitPass());

    log.info("Starting server on " + opts.getPort());
    new MetaDataServer(opts.getPort(), buildDataSource(opts.getDbUri(), opts.getDbUser(), opts.getDbPass()),
            enaHandler).run();// w w  w .jav a 2s  . co  m

}

From source file:org.apache.s4.MainApp.java

public static void main(String args[]) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));

    options.addOption(//from w  w w . ja va 2s  .com
            OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a"));

    options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d"));

    options.addOption(OptionBuilder.withArgName("seedtime").hasArg()
            .withDescription("event clock initialization time").create("s"));

    options.addOption(
            OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e"));

    options.addOption(
            OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i"));

    options.addOption(
            OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t"));

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;
    String clockType = "wall";

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }

    int instanceId = -1;
    if (commandLine.hasOption("i")) {
        String instanceIdStr = commandLine.getOptionValue("i");
        try {
            instanceId = Integer.parseInt(instanceIdStr);
        } catch (NumberFormatException nfe) {
            System.err.println("Bad instance id: %s" + instanceIdStr);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("c")) {
        coreHome = commandLine.getOptionValue("c");
    }

    if (commandLine.hasOption("a")) {
        appsHome = commandLine.getOptionValue("a");
    }

    if (commandLine.hasOption("d")) {
        clockType = commandLine.getOptionValue("d");
    }

    if (commandLine.hasOption("e")) {
        extsHome = commandLine.getOptionValue("e");
    }

    String configType = "typical";
    if (commandLine.hasOption("t")) {
        configType = commandLine.getOptionValue("t");
    }

    long seedTime = 0;
    if (commandLine.hasOption("s")) {
        seedTime = Long.parseLong(commandLine.getOptionValue("s"));
    }

    File coreHomeFile = new File(coreHome);
    if (!coreHomeFile.isDirectory()) {
        System.err.println("Bad core home: " + coreHome);
        System.exit(1);
    }

    File appsHomeFile = new File(appsHome);
    if (!appsHomeFile.isDirectory()) {
        System.err.println("Bad applications home: " + appsHome);
        System.exit(1);
    }

    if (instanceId > -1) {
        System.setProperty("instanceId", "" + instanceId);
    } else {
        System.setProperty("instanceId", "" + S4Util.getPID());
    }

    List loArgs = commandLine.getArgList();

    if (loArgs.size() < 1) {
        // System.err.println("No bean configuration file specified");
        // System.exit(1);
    }

    // String s4ConfigXml = (String) loArgs.get(0);
    // System.out.println("s4ConfigXml is " + s4ConfigXml);

    ClassPathResource propResource = new ClassPathResource("s4-core.properties");
    Properties prop = new Properties();
    if (propResource.exists()) {
        prop.load(propResource.getInputStream());
    } else {
        System.err.println("Unable to find s4-core.properties. It must be available in classpath");
        System.exit(1);
    }

    ApplicationContext coreContext = null;
    String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType;
    String configPath = "";
    List<String> coreConfigUrls = new ArrayList<String>();
    File configFile = null;

    // load clock configuration
    configPath = configBase + File.separatorChar + clockType + "-clock.xml";
    coreConfigUrls.add(configPath);

    // load core config xml
    configPath = configBase + File.separatorChar + "s4-core-conf.xml";
    configFile = new File(configPath);
    if (!configFile.exists()) {
        System.err.printf("S4 core config file %s does not exist\n", configPath);
        System.exit(1);
    }

    coreConfigUrls.add(configPath);
    String[] coreConfigFiles = new String[coreConfigUrls.size()];
    coreConfigUrls.toArray(coreConfigFiles);

    String[] coreConfigFileUrls = new String[coreConfigFiles.length];
    for (int i = 0; i < coreConfigFiles.length; i++) {
        coreConfigFileUrls[i] = "file:" + coreConfigFiles[i];
    }

    coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext);
    ApplicationContext context = coreContext;

    Clock clock = (Clock) context.getBean("clock");
    if (clock instanceof EventClock && seedTime > 0) {
        EventClock s4EventClock = (EventClock) clock;
        s4EventClock.updateTime(seedTime);
        System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime());
    }

    PEContainer peContainer = (PEContainer) context.getBean("peContainer");

    Watcher w = (Watcher) context.getBean("watcher");
    w.setConfigFilename(configPath);

    // load extension modules
    String[] configFileNames = getModuleConfigFiles(extsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
    }

    // load application modules
    configFileNames = getModuleConfigFiles(appsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
        // attach any beans that implement ProcessingElement to the PE
        // Container
        String[] processingElementBeanNames = context.getBeanNamesForType(AbstractPE.class);
        for (String processingElementBeanName : processingElementBeanNames) {
            AbstractPE bean = (AbstractPE) context.getBean(processingElementBeanName);
            bean.setClock(clock);
            try {
                bean.setSafeKeeper((SafeKeeper) context.getBean("safeKeeper"));
            } catch (NoSuchBeanDefinitionException ignored) {
                // no safe keeper = no checkpointing / recovery
            }
            // if the application did not specify an id, use the Spring bean name
            if (bean.getId() == null) {
                bean.setId(processingElementBeanName);
            }
            System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id "
                    + ((AbstractPE) bean).getId());
            peContainer.addProcessor((AbstractPE) bean);
        }
    }
}

From source file:ca.uhn.hunit.run.TestRunner.java

/**
 * @param args//from   w ww.  ja  v a  2s  .  com
 * @throws URISyntaxException
 * @throws JAXBException
 * @throws ConfigurationException
 * @throws InterfaceWontStartException
 * @throws FileNotFoundException
 * @throws ParseException
 */
public static void main(String[] theArgs) throws URISyntaxException, JAXBException, InterfaceWontStartException,
        ConfigurationException, FileNotFoundException, ParseException {
    Options options = new Options();

    OptionGroup fileOptionGroup = new OptionGroup();
    fileOptionGroup.setRequired(false);

    Option option = new Option("f", "file", true, "The path to the file to load the test battery from");
    option.setValueSeparator('=');
    fileOptionGroup.addOption(option);
    option = new Option("c", "classpath", true, "The classpath path to the file to load the test battery from");
    option.setValueSeparator('=');
    fileOptionGroup.addOption(option);
    options.addOptionGroup(fileOptionGroup);

    OptionGroup uiOptionGroup = new OptionGroup();
    option = new Option("g", "gui", false, "Start hUnit in GUI mode (default)");
    uiOptionGroup.addOption(option);
    option = new Option("x", "text", false, "Start hUnit in Text mode");
    uiOptionGroup.addOption(option);
    options.addOptionGroup(uiOptionGroup);

    option = new Option("t", "tests", true, "A comma separated list of tests to execute (default is all)");
    option.setValueSeparator('=');
    option.setRequired(false);
    options.addOption(option);

    Resource defFile = null;
    CommandLine parser;
    boolean textMode = false;

    try {
        parser = new PosixParser().parse(options, theArgs);

        if (parser.hasOption("f")) {
            defFile = new FileSystemResource(parser.getOptionValue("f"));
        } else if (parser.hasOption("c")) {
            defFile = new ClassPathResource(parser.getOptionValue("c"));
        }

        if (parser.hasOption("x")) {
            textMode = true;
        }
    } catch (Exception e) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("java -jar hunit-[version]-jar-with-dependencies.jar [-c FILE|-f FILE] [options]",
                options);

        return;
    }

    String[] testsToExecute = null;

    if (parser.hasOption("t")) {
        testsToExecute = parser.getOptionValue("t").split(",");
    }

    if (textMode) {
        executeInTextMode(defFile, testsToExecute);
    } else {
        executeInGuiMode(defFile, testsToExecute);
    }
}

From source file:org.opennms.mock.snmp.MockSnmpAgent.java

public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println(/*from   w  w w.  j  av a  2 s. co m*/
                "Usage: MockSnmpAgent props-file listen-addr\n\nWhere props-file is relative to CLASSPATH\nand listen-addr is of the form 10.11.12.13/1161 to listen on port 1161");
        System.exit(1);
    }
    ClassPathResource moFile = new ClassPathResource(args[0]);
    String bindAddress = args[1];

    try {
        MockSnmpAgent agt = MockSnmpAgent.createAgentAndRun(moFile, bindAddress);
    } catch (InterruptedException e) {
        System.exit(0);
    }
}