Example usage for java.lang ExceptionInInitializerError ExceptionInInitializerError

List of usage examples for java.lang ExceptionInInitializerError ExceptionInInitializerError

Introduction

In this page you can find the example usage for java.lang ExceptionInInitializerError ExceptionInInitializerError.

Prototype

public ExceptionInInitializerError(String s) 

Source Link

Document

Constructs an ExceptionInInitializerError with the specified detail message string.

Usage

From source file:org.lingcloud.molva.ocl.util.HibernateUtil.java

/**
 * init the configuration object it if neeed.
 *//*from  w w  w .j  a v a 2 s.  c o  m*/
private void initConfiguration() {
    // Create the initial SessionFactory from the default configuration
    // files
    if (configuration == null) {
        try {
            log.debug("Initializing Hibernate");

            // Read hibernate.properties, if present
            configuration = new Configuration();
            // Use annotations: configuration = new
            // AnnotationConfiguration();

            // Read hibernate.cfg.xml (has to be present)
            configuration.configure(getCfgXmlFile());

            log.debug("Hibernate initialized, call " + "HibernateUtil.getSessionFactory()");
        } catch (Throwable ex) {
            // We have to catch Throwable, otherwise we will miss
            // NoClassDefFoundError and other subclasses of Error
            log.error("Building SessionFactory failed.", ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
}

From source file:psidev.psi.mi.search.engine.impl.AbstractSearchEngine.java

public AbstractSearchEngine(Directory indexDirectory, IndexWriter indexWriter) throws IOException {
    if (indexDirectory == null) {
        throw new NullPointerException("indexDirectory cannot be null");
    }/*from   ww  w .  j  a  v a2 s  . c o  m*/

    this.indexDirectory = indexDirectory;

    try {
        IndexReader reader = IndexReader.open(indexDirectory);
        this.indexSearcher = new IndexSearcher(reader);
    }
    // directory is empty, needs to create the segment files manually because of a bug in lucene 3.6
    catch (IndexNotFoundException e) {
        if (indexWriter == null) {
            IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_30,
                    new StandardAnalyzer(Version.LUCENE_30));
            config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
            indexWriter = new IndexWriter(indexDirectory, config);
        }

        indexWriter.commit();

        try {
            IndexReader reader = IndexReader.open(indexDirectory);
            this.indexSearcher = new IndexSearcher(reader);
        } catch (Exception e2) {
            throw new ExceptionInInitializerError(e);
        }
    } catch (Exception e) {
        throw new ExceptionInInitializerError(e);
    }
}

From source file:org.jahia.test.SurefireJUnitXMLResultFormatter.java

private static DocumentBuilder getDocumentBuilder() {
    try {/*from  ww  w .java 2s.  co  m*/
        return DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (Exception exc) {
        throw new ExceptionInInitializerError(exc);
    }
}

From source file:org.paxle.data.db.impl.CommandProfileDB.java

/**
 * @param configURL an {@link URL} to the DB configuration
 * @param mappings a list of {@link URL} to the hibernate-mapping files to use
 *//*from www .ja va  2  s  .co m*/
public CommandProfileDB(URL configURL, List<URL> mappings, IDocumentFactory profileFactory) {
    if (configURL == null)
        throw new NullPointerException("The URL to the hibernate config file is null.");
    if (mappings == null)
        throw new NullPointerException("The list of mapping files was null.");

    try {
        this.profileFactory = profileFactory;

        /* ===========================================================================
         * Init Hibernate
         * =========================================================================== */
        try {
            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

            // Read the hibernate configuration from *.cfg.xml
            this.logger.info(String.format("Loading DB configuration from URL '%s'.", configURL));
            this.config = new Configuration().configure(configURL);

            // register an interceptor (required to support our interface-based command model)
            this.config.setInterceptor(new InterfaceInterceptor(this.profileFactory));

            // configure caching
            this.config.setProperty("hibernate.cache.provider_class",
                    "net.sf.ehcache.hibernate.SingletonEhCacheProvider");

            // post-processing of read properties
            ConnectionUrlTool.postProcessProperties(this.config);

            // load the various mapping files
            for (URL mapping : mappings) {
                if (this.logger.isDebugEnabled())
                    this.logger.debug(String.format("Loading mapping file from URL '%s'.", mapping));
                this.config.addURL(mapping);
            }

            // String[] sql = this.config.generateSchemaCreationScript( new org.hibernate.dialect.MySQLDialect());

            // create the session factory
            this.sessionFactory = this.config.buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            this.logger.error("Initial SessionFactory creation failed.", ex);
            throw new ExceptionInInitializerError(ex);
        }

    } catch (Throwable e) {
        this.logger.error(
                String.format("Unexpected '%s' while initializing command-profile DB", e.getClass().getName()),
                e);
        throw new RuntimeException(e);
    }
}

From source file:org.webical.manager.impl.EncryptionManagerImpl.java

public void afterPropertiesSet() throws Exception {
    if (passphraseFile == null) {
        log.fatal("Passphrasefile not configured");
        throw new ExceptionInInitializerError("Passphrasefile not configured");
    }//from ww w .  j av  a 2 s.  c  o m

    initialize();
}

From source file:org.viafirma.util.ConfigUtil.java

/**
 * Recupera el conjunto de propiedades que utiliza la aplicacin.
 * @param context//from  www  .  ja v a  2s . c  o m
 * @return
 */
public Properties readConfigPropertes() {
    Properties properties = new Properties();
    Context initCtx;
    try {
        initCtx = new InitialContext();
        Context contextInit = (Context) initCtx.lookup("java:comp/env");
        // recuperamos ahora todos los parametros JNDI que estan en el raiz de la aplicacin 
        NamingEnumeration<NameClassPair> propiedadesJDNI = contextInit.list("");
        while (propiedadesJDNI.hasMoreElements()) {
            NameClassPair propiedad = propiedadesJDNI.nextElement();
            Object temp = contextInit.lookup(propiedad.getName());
            if (temp instanceof String) {
                String valor = (String) temp;
                System.out.println("\t\t\t" + propiedad.getName() + "=" + valor);
                properties.put(propiedad.getName(), valor);
            }
        }
    } catch (Exception e) {
        log.fatal("No se pueden recuperar los parametros de configuracin. JNDI parece no estar disponible.",
                e);
        throw new ExceptionInInitializerError(
                "No se pueden recuperar los parametros de configuracin. JNDI parece no estar disponible."
                        + e.getMessage());
    }
    return properties;
}

From source file:com.flowpowered.commons.console.JLineConsole.java

public JLineConsole(CommandCallback callback, Completer completer, Logger logger, int inThreadSleepTime,
        OutputStream out, InputStream in) {
    this.callback = callback;
    if (logger == null) {
        this.logger = LoggerFactory.getLogger("JLineConsole");
    } else {/*w  w  w. j  a  va2 s . c  o m*/
        this.logger = logger;
    }
    if (out == null) {
        out = System.out;
    }
    if (in == null) {
        in = new FileInputStream(FileDescriptor.in);
    }

    if (inThreadSleepTime != INPUT_THREAD_BLOCK) {
        in = new InterruptableInputStream(in, inThreadSleepTime);
    }

    try {
        reader = new ConsoleReader(in, out);
    } catch (IOException e) {
        throw new ExceptionInInitializerError(e);
    }

    setupConsole(reader);

    @SuppressWarnings("unchecked")
    final Collection<Completer> oldCompleters = reader.getCompleters();
    for (Completer c : new ArrayList<>(oldCompleters)) {
        reader.removeCompleter(c);
    }
    reader.addCompleter(completer);

    commandThread = new ConsoleCommandThread();
    commandThread.start();
}

From source file:com.netxforge.oss2.core.utilsII.ExecRunner.java

/**
 * ExecRunner constructor which also conveniently runs exec(String).
 *
 * @param command/*from www  .ja  v  a  2  s.co  m*/
 *            The program or command to run
 * @throws java.lang.ExceptionInInitializerError
 *             thrown if a problem occurs
 */
public ExecRunner(final String command) throws ExceptionInInitializerError {
    this();
    try {
        exec(command);
    } catch (final Throwable e) {
        throw new ExceptionInInitializerError(e.getMessage());
    }

}

From source file:es.ua.datos.cad.CAD.java

public CAD(String db) {

    try {//from  w ww.  ja  va2  s . co  m
        if (sessionFactory == null || sessionFactory.isClosed()) {

            Configuration configuration = new Configuration();
            configuration.configure("hibernate_" + db + ".cfg.xml");
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
                    .applySettings(configuration.getProperties()).buildServiceRegistry();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);

        }
        /*else{
           sessionFactory.getCurrentSession();
           System.out.println("GET CURRENT SESSION (CAD)");
        }*/

        /*if(session.isOpen())
           session = sessionFactory.getCurrentSession();
        else
           session = sessionFactory.openSession();
        */
        //return sessionFactory;

    } catch (HibernateException he) {
        System.err.println("Ocurrio un error en la inicializacion de la SessionFactory: " + he);
        throw new ExceptionInInitializerError(he);
    } finally {

        //Poner en el finally
        stats = sessionFactory.getStatistics();
        stats.setStatisticsEnabled(true);
        writeStatisticsLog(stats);

    }

}

From source file:org.wisdom.test.internals.RunnerUtils.java

/**
 * Checks whether the Wisdom server was correctly unpacked. If so, return the base directory.
 *
 * @return the Wisdom base directory if there, {@literal null} otherwise.
 *///from w ww  .  j  ava 2  s .  c om
public static File checkWisdomInstallation() {
    File directory = new File("target/wisdom");
    if (!directory.isDirectory()) {
        throw new ExceptionInInitializerError("Wisdom is not installed in " + directory.getAbsolutePath()
                + " - "
                + "please check your execution directory, and that Wisdom is prepared correctly. To setup Wisdom, "
                + "run 'mvn pre-integration-test' from your application directory");
    }
    File conf = new File(directory, "conf/application.conf");
    if (!conf.isFile()) {
        throw new ExceptionInInitializerError("Wisdom is not correctly installed in "
                + directory.getAbsolutePath()
                + " - the configuration file does not exist. Please check your Wisdom runtime. To setup Wisdom, "
                + "run 'mvn clean pre-integration-test' from your application directory");
    }
    return directory;
}