Example usage for java.lang ClassNotFoundException printStackTrace

List of usage examples for java.lang ClassNotFoundException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:module.entities.NameFinder.DB.java

public static void initPostgres() throws IOException {
    if (connection == null) {
        try {//ww w . java2s  .c om
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Where is your PostgreSQL JDBC Driver? " + "Include in your library path!");
            e.printStackTrace();
            return;
        }

        try {
            BufferedReader br = null;
            String line = "";
            String splitBy = "=";
            String ip_address = null;
            String user = null;
            String pass = null;
            //                configFile = "files/config.txt";
            try {
                br = new BufferedReader(new FileReader(Config.configFile));
                while ((line = br.readLine()) != null) {
                    if (line.startsWith("IP_ADDRESS")) {
                        String[] lineParts = line.split(splitBy, 2);
                        ip_address = lineParts[1];
                    } else if (line.startsWith("USERNAME")) {
                        String[] lineParts = line.split(splitBy, 2);
                        user = lineParts[1];
                    } else if (line.startsWith("PASSWORD")) {
                        String[] lineParts = line.split(splitBy, 2);
                        pass = lineParts[1];
                    } else if (line.startsWith("LEXICONS_LANG")) {
                        String[] lineParts = line.split(splitBy, 2);
                        Config.lang = lineParts[1];
                    }
                }
            } catch (FileNotFoundException e) {
            }
            String DB_url = "jdbc:postgresql://" + ip_address;
            connection = DriverManager.getConnection(DB_url, user, pass);
        } catch (SQLException e) {
            System.out.println("Connection Failed! Check output console.");
            e.printStackTrace();
            return;
        }
        if (connection != null) {
            System.out.println("Connection to the database created succesfully!");
        } else {
            System.out.println("Failed to make connection!");
        }
    }
}

From source file:module.entities.NameFinder.DB.java

/**
 * Initiates the database connection./*from   w w w  .  j  a v  a  2 s.co m*/
 *
 * @throws java.io.FileNotFoundException
 * @throws java.io.IOException
 */
public static void init() throws IOException {
    if (connection == null) {
        try {
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Where is your PostgreSQL JDBC Driver? " + "Include in your library path!");
            e.printStackTrace();
            return;
        }

        try {
            BufferedReader br = null;
            String line = "";
            String splitBy = "=";
            String ip_address = null;
            String user = null;
            String pass = null;
            //                configFile = "files/config.txt";
            try {
                br = new BufferedReader(new FileReader(Config.configFile));
                while ((line = br.readLine()) != null) {
                    if (line.startsWith("IP_ADDRESS")) {
                        String[] lineParts = line.split(splitBy, 2);
                        ip_address = lineParts[1];
                    } else if (line.startsWith("USERNAME")) {
                        String[] lineParts = line.split(splitBy, 2);
                        user = lineParts[1];
                    } else if (line.startsWith("PASSWORD")) {
                        String[] lineParts = line.split(splitBy, 2);
                        pass = lineParts[1];
                    } else if (line.startsWith("LEXICONS_LANG")) {
                        String[] lineParts = line.split(splitBy, 2);
                        Config.lang = lineParts[1];
                    }
                }
            } catch (FileNotFoundException e) {
            }
            String DB_url = "jdbc:mysql://" + ip_address + "?characterEncoding=UTF-8";
            connection = DriverManager.getConnection(DB_url, user, pass);
        } catch (SQLException e) {
            System.out.println("Connection Failed! Check output console.");
            e.printStackTrace();
            return;
        }
        if (connection != null) {
            System.out.println("Connection to the database created succesfully!");
        } else {
            System.out.println("Failed to make connection!");
        }
    }
}

From source file:edu.ku.brc.af.ui.forms.FormHelper.java

/**
  * Creates a new data object and initializes it.
  * @param newDataClass class of new Object to be created and initialized
  * @param overrideAddKids whether to override the business rules as to whether to add children
  * @param busRules the business rules from the view
 *//*from   w  w w. j av  a 2  s .c o m*/
public static FormDataObjIFace createAndNewDataObj(final String newDataClassName, final Boolean overrideAddKids,
        final BusinessRulesIFace busRules) {
    try {
        return createAndNewDataObj(Class.forName(newDataClassName).asSubclass(FormDataObjIFace.class),
                overrideAddKids, busRules);

    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);
    }

    return null;

}

From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java

private static Permission parsePermission(AuthorizationTokenStream ats)
        throws AuthorizationSyntaxParseException, IOException {
    String perm = ats.nextUsefulToken();
    if (perm == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", permission syntax error");
    } else if (!perm.toLowerCase().equals("permission")) {
        String rightBracket = perm;
        if (rightBracket == null || !rightBracket.contains("}")) {
            throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", no right bracket");
        } else if (!rightBracket.contains(";")) {
            throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", no \";\" sign finded");
        }//w  w w . ja va2 s.  c o m
        return null;
    }
    String className = ats.nextUsefulToken();
    String isEnd = ats.nextUsefulToken();
    if (className == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", className is null");
    }
    if (isEnd == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", no operate object defined");
    } else {
        try {
            if (!isEnd.contains(";")) {
                String oper = isEnd;
                oper = oper.replace("\"", "");
                oper = oper.replace(",", "");
                isEnd = ats.nextUsefulToken();
                if (isEnd != null && isEnd.contains(";")) {
                    String actions = isEnd.replace(";", "");
                    actions = actions.replace("\"", "");
                    Class<?> clazz = Class.forName(className, false, VWBPermission.class.getClassLoader());
                    return ((Permission) clazz
                            .getDeclaredConstructor(new Class[] { String.class, String.class })
                            .newInstance(oper, actions));
                } else {
                    throw new AuthorizationSyntaxParseException(
                            "Line " + ats.getLineNum() + ", no \";\" sign finded");
                }
            } else {
                String oper = isEnd.replace(";", "");
                oper = oper.replace("\"", "");
                Class<?> clazz = Class.forName(className);
                return ((Permission) clazz.getDeclaredConstructor(String.class).newInstance(oper));
            }
        } catch (ClassNotFoundException e) {
            throw new AuthorizationSyntaxParseException(
                    "Line " + ats.getLineNum() + ", ClassNotFoundException, " + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new AuthorizationSyntaxParseException(
                    "Line " + ats.getLineNum() + ", Exception happens, " + e.getMessage());
        }
    }
}

From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java

public static Class<?> getCraftClass(String ClassName) {
    String className = "net.minecraft.server." + version + ClassName;
    Class<?> c = null;//from w ww.j  a  v a 2s  .c o  m
    try {
        c = Class.forName(className);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return c;
}

From source file:com.connectsdk.service.DeviceService.java

@SuppressWarnings("unchecked")
public static DeviceService getService(JSONObject json) {
    Class<DeviceService> newServiceClass;

    try {/*from  ww w  .  j  a v a2s.c o m*/
        String className = json.optString(KEY_CLASS);

        if (className.equalsIgnoreCase("DLNAService"))
            return null;

        if (className.equalsIgnoreCase("Chromecast"))
            return null;

        newServiceClass = (Class<DeviceService>) Class
                .forName(DeviceService.class.getPackage().getName() + "." + className);
        Constructor<DeviceService> constructor = newServiceClass.getConstructor(ServiceDescription.class,
                ServiceConfig.class);

        JSONObject jsonConfig = json.optJSONObject(KEY_CONFIG);
        ServiceConfig serviceConfig = null;
        if (jsonConfig != null)
            serviceConfig = ServiceConfig.getConfig(jsonConfig);

        JSONObject jsonDescription = json.optJSONObject(KEY_DESC);
        ServiceDescription serviceDescription = null;
        if (jsonDescription != null)
            serviceDescription = ServiceDescription.getDescription(jsonDescription);

        if (serviceConfig == null || serviceDescription == null)
            return null;

        return constructor.newInstance(serviceDescription, serviceConfig);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:edu.cornell.med.icb.goby.modes.DiscoverSequenceVariantsMode.java

public static RandomAccessSequenceInterface configureGenome(RandomAccessSequenceInterface testGenome,
        JSAPResult jsapResult) throws IOException {
    if (testGenome != null) {
        return testGenome;
    }// w ww.  j a v a2s.c om
    String startOffsetArgument = jsapResult.getString("start-position");
    String endOffsetArgument = jsapResult.getString("end-position");
    String minIndex = getReferenceId(startOffsetArgument, "min");
    String maxIndex = getReferenceId(endOffsetArgument, "max");

    final String genome = jsapResult.getString("genome");
    RandomAccessSequenceCache cache = null;
    if (genome != null) {
        try {
            System.err.println("Loading genome cache " + genome);
            cache = new RandomAccessSequenceCache();
            cache.load(genome, minIndex, maxIndex);
            System.err.println("Done loading genome. ");
        } catch (ClassNotFoundException e) {
            System.err.println("Could not load genome cache");
            e.printStackTrace();
            System.exit(1);
        }
    }
    return cache;
}

From source file:com.xhsoft.framework.common.utils.ClassUtil.java

/**
 * @param writer/*from  w w w .  j  a  va2 s .c  om*/
 * @param className
 * @param expression
 * @author lizj
 */
public static void write(final java.io.Writer writer, final String className, final String expression) {
    try {
        Class<?> type = ClassUtil.getClass(className);

        write(writer, type, expression);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:org.alfresco.repo.dictionary.ModelUtils.java

/**
 * This method doesn't seem to work due to possible spring bug in 3.0.0?
 * https://jira.springsource.org/browse/SPR-6592?page=com.atlassian.jirafisheyeplugin%3Afisheye-issuepanel
 * /*from w w w.j a  v  a 2 s .  co  m*/
 * @return
 */
@SuppressWarnings("unchecked")
public static HashMap<String, AbstractConstraint> getAllConstrainTypesAuto() {
    HashMap<String, AbstractConstraint> classList = new HashMap<String, AbstractConstraint>();

    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
            true);
    provider.addIncludeFilter(new AssignableTypeFilter(AbstractConstraint.class));

    // scan in org.example.package
    Set<BeanDefinition> components = provider
            .findCandidateComponents("org/alfresco/repo/dictionary/constraint");
    for (BeanDefinition component : components) {
        try {
            Class clazz = Class.forName(component.getBeanClassName());
            AbstractConstraint object = (AbstractConstraint) clazz.newInstance();
            String name = object.getType();
            classList.put(name, object);
        } catch (ClassNotFoundException e) {

        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return classList;
}

From source file:com.aliyun.openservices.odps.console.utils.CommandParserUtils.java

public static void printHelpInfo(List<String> keywords) {
    Map<String, Integer> matched = new HashMap<String, Integer>() {
    };//  ww  w. j av  a  2 s  .  c o  m
    List<String> allCommands = new ArrayList<String>();

    if (ecList == null) {
        ecList = PluginUtil.getExtendCommandList();
    }

    for (PluginPriorityCommand command : ecList) {
        allCommands.add(command.getCommandName());
    }

    for (String commandName : allCommands) {
        try {
            Class<?> commandClass = Class.forName(commandName, false, classLoader);
            Field tags_field = commandClass.getField(HELP_TAGS_FIELD);
            String[] tags = (String[]) tags_field.get(null);

            int count = 0;
            for (String tag : tags) {
                for (String keyword : keywords) {
                    if (tag.equalsIgnoreCase(keyword)) {
                        count++;
                        break;
                    }
                }
            }
            if (count != 0) {
                matched.put(commandName, count);
            }
        } catch (ClassNotFoundException e) {
            // Console??AssertionError
            //throw new AssertionError("Cannot find the command:" + commandName);
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            // Ignore
        } catch (IllegalAccessException e) {
            // Ignore
        }
    }

    // Print the help info of the command(s) whose tags match most keywords
    boolean found = false;
    System.out.println();
    for (int i = keywords.size(); i >= 1; i--) {
        for (Map.Entry<String, Integer> entry : matched.entrySet()) {
            if (i == entry.getValue()) {
                try {
                    Class<?> commandClass = Class.forName(entry.getKey(), false, classLoader);
                    Method printMethod = commandClass.getDeclaredMethod(HELP_PRINT_METHOD,
                            new Class<?>[] { PrintStream.class });
                    printMethod.invoke(null, System.out);
                    found = true;
                } catch (ClassNotFoundException e) {
                    // Console??AssertionError
                    throw new AssertionError("Cannot find the command:" + entry.getKey());
                } catch (NoSuchMethodException e) {
                    // Ignore
                } catch (IllegalAccessException e) {
                    // Ignore
                } catch (InvocationTargetException e) {
                    // Ignore
                }
            }
        }
        if (found) {
            break;
        }
    }
    System.out.println();
}