List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException()
ClassNotFoundException
with no detail message. From source file:egovframework.rte.itl.webservice.service.impl.EgovWebServiceClassLoaderImpl.java
public Class<?> loadClass(final Type type) throws ClassNotFoundException { LOG.debug("loadClass of Type (" + type + ")"); if (type == EgovWebServiceMessageHeader.TYPE) { LOG.debug("Type is EgovWebServiceMessageHeader."); return EgovWebServiceMessageHeader.class; }/*from w w w .j a v a2 s. co m*/ if (type instanceof PrimitiveType) { LOG.debug("Type is a Primitive Type"); Class<?> clazz = primitiveClasses.get((PrimitiveType) type); if (clazz == null) { LOG.error("No such primitive type"); throw new ClassNotFoundException(); } return clazz; } else if (type instanceof ListType) { LOG.debug("Type is a List Type"); ListType listType = (ListType) type; Class<?> elementClass = loadClass(listType.getElementType()); return Array.newInstance(elementClass, 0).getClass(); } else if (type instanceof RecordType) { LOG.debug("Type is a Record Type"); RecordType recordType = (RecordType) type; String className = getRecordTypeClassName(recordType.getName()); try { LOG.debug("Check the class \"" + className + "\" is already loaded."); return loadClass(className); } catch (ClassNotFoundException e) { LOG.debug("Create a new class \"" + className + "\""); byte[] byteCode = createRecordClass(className, recordType); return defineClass(className, byteCode, 0, byteCode.length); } } LOG.error("Type is invalid"); throw new ClassNotFoundException(); }
From source file:org.jtransfo.internal.ConverterHelperTest.java
@Test public void testGetDeclaredTypeConverterCnfe() throws Exception { MappedBy mappedBy = mock(MappedBy.class); when(mappedBy.typeConverterClass()).thenReturn(MappedBy.DefaultTypeConverter.class); when(mappedBy.typeConverter()).thenReturn(NoConversionTypeConverter.class.getName()); when(mappedBy.field()).thenReturn(MappedBy.DEFAULT_FIELD); when(reflectionHelper.newInstance(NoConversionTypeConverter.class.getName())) .thenThrow(new ClassNotFoundException()); exception.expect(JTransfoException.class); exception.expectMessage(/*from ww w . j a va 2 s . c o m*/ "Declared TypeConverter class org.jtransfo.NoConversionTypeConverter cannot be found."); converterHelper.getDeclaredTypeConverter(mappedBy); }
From source file:org.trianacode.taskgraph.tool.ClassLoaders.java
public static Class loadClass(String name) throws ClassNotFoundException { final String className = name; // Get the class within a doPrivleged block Object ret = AccessController.doPrivileged(new PrivilegedAction() { public Object run() { log.debug("trying to find " + className); try { // Check if the class is a registered class then // use the classloader for that class. ClassLoader classLoader = getClassLoader(className); if (classLoader == null) { throw new ClassNotFoundException(); }//from ww w . j a v a2 s. c o m return Class.forName(className, true, classLoader); } catch (ClassNotFoundException cnfe) { } //check the list of loaders for (int i = 0; i < loaders.size(); i++) { ClassLoader classLoader = loaders.get(i); log.debug("next class loader:" + classLoader); try { return Class.forName(className, true, classLoader); } catch (ClassNotFoundException cnfe) { } } try { // Try the context class loader ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); return Class.forName(className, true, classLoader); } catch (ClassNotFoundException cnfe2) { try { // Try the classloader that loaded this class. ClassLoader classLoader = ClassLoaders.class.getClassLoader(); return Class.forName(className, true, classLoader); } catch (ClassNotFoundException cnfe3) { // Try the default class loader. try { return Class.forName(className); } catch (Throwable e) { // Still not found, return exception return e; } } } } }); // If the class was located, return it. Otherwise throw exception if (ret instanceof Class) { return (Class) ret; } else if (ret instanceof ClassNotFoundException) { throw (ClassNotFoundException) ret; } else { throw new ClassNotFoundException(name); } }
From source file:org.jactr.eclipse.runtime.ui.tabs.normal.StartStopTab.java
private void testProject(String className, ILaunchConfiguration configuration) throws ClassNotFoundException, IllegalArgumentException { try {/*w ww. j a va2 s . c o m*/ IProject project = ACTRLaunchConfigurationUtils.getProject(configuration); IJavaProject jProject = JavaCore.create(project); IType type = jProject.findType(className); if (type == null) { RuntimePlugin.info("Could not find " + className + " on classpath of " + project.getName() + ". Checked : " + Arrays.toString(jProject.getResolvedClasspath(false))); throw new ClassNotFoundException(); } } catch (CoreException ce) { throw new IllegalArgumentException(); } }
From source file:org.sakaiproject.util.conversion.UpgradeSchema.java
/** * Make it easy to target the local database. Data source properties * are searched in the following order, with the first match winning: * <ul>/*from ww w. j a va 2s.c om*/ * <li> A Java system property named "sakai.properties" which will be used to load a * properties file containing property names such as "url@javax.sql.BaseDataSource". * <li> Input configProperties named "dbDriver", "dbURL", "dbUser", and "dbPass". * </ul> * (Side note: this configuration logic would be easy to externalize with Spring.) * @param configProperties */ private DriverAdapterCPDS getDataSource(Properties configProperties) throws ClassNotFoundException { String dbDriver = null; String dbUrl = null; String dbUser = null; String dbPassword = null; String sakaiPropertiesPath = System.getProperty("sakai.properties"); if (sakaiPropertiesPath != null) { File sakaiPropertiesFile = new File(sakaiPropertiesPath); if (sakaiPropertiesFile.exists()) { FileInputStream sakaiPropertiesInput = null; try { sakaiPropertiesInput = new FileInputStream(sakaiPropertiesFile); Properties sakaiProperties = new Properties(); sakaiProperties.load(sakaiPropertiesInput); sakaiPropertiesInput.close(); dbDriver = sakaiProperties.getProperty("driverClassName@javax.sql.BaseDataSource"); dbUrl = sakaiProperties.getProperty("url@javax.sql.BaseDataSource"); dbUser = sakaiProperties.getProperty("username@javax.sql.BaseDataSource"); dbPassword = sakaiProperties.getProperty("password@javax.sql.BaseDataSource"); } catch (IOException e) { log.info("Error loading properties from " + sakaiPropertiesFile.getAbsolutePath()); } finally { if (sakaiPropertiesInput != null) { try { sakaiPropertiesInput.close(); } catch (IOException e) { } } } } } if (dbDriver == null) dbDriver = configProperties.getProperty("dbDriver"); if (dbUrl == null) dbUrl = configProperties.getProperty("dbURL"); if (dbUser == null) dbUser = configProperties.getProperty("dbUser"); if (dbPassword == null) dbPassword = configProperties.getProperty("dbPass"); DriverAdapterCPDS cpds = new DriverAdapterCPDS(); try { cpds.setDriver(dbDriver); } catch (ClassNotFoundException e) { throw new ClassNotFoundException(); } cpds.setUrl(dbUrl); cpds.setUser(dbUser); cpds.setPassword(dbPassword); return cpds; }
From source file:br.gov.frameworkdemoiselle.internal.implementation.ConfigurationLoader.java
private ConfigurationValueExtractor getValueExtractor(Field field) { Collection<ConfigurationValueExtractor> candidates = new HashSet<ConfigurationValueExtractor>(); ConfigurationBootstrap bootstrap = Beans.getReference(ConfigurationBootstrap.class); for (Class<? extends ConfigurationValueExtractor> extractorClass : bootstrap.getCache()) { ConfigurationValueExtractor extractor = Beans.getReference(extractorClass); if (extractor.isSupported(field)) { candidates.add(extractor);//from w ww .jav a 2 s . co m } } ConfigurationValueExtractor elected = StrategySelector.selectInstance(ConfigurationValueExtractor.class, candidates); if (elected == null) { throw new ConfigurationException(getBundle().getString("configuration-extractor-not-found", field.toGenericString(), ConfigurationValueExtractor.class.getName()), new ClassNotFoundException()); } return elected; }
From source file:org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests.java
@SuppressWarnings("unchecked") private <T extends DataSource> T testDataSourceFallback(Class<T> expectedType, final String... hiddenPackages) { EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.driverClassName:org.hsqldb.jdbcDriver", "spring.datasource.url:jdbc:hsqldb:mem:testdb"); this.context.setClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader()) { @Override/*from ww w . j av a 2s .c o m*/ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { for (String hiddenPackage : hiddenPackages) { if (name.startsWith(hiddenPackage)) { throw new ClassNotFoundException(); } } return super.loadClass(name, resolve); } }); this.context.register(DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); DataSource bean = this.context.getBean(DataSource.class); assertThat(bean, instanceOf(expectedType)); return (T) bean; }
From source file:org.clever.administration.CLI.java
private Class classFromCommand(final String command) throws ClassNotFoundException { String className = commands.get(command.split(" ")[0]); if (className == null) throw new ClassNotFoundException(); Class cl = Class.forName(className); return cl;/*from w ww. j av a2 s . c om*/ }
From source file:org.apache.hadoop.hbase.CompoundConfiguration.java
@Override public Class<?> getClassByName(String name) throws ClassNotFoundException { if (mutableConf != null) { Class<?> value = mutableConf.getClassByName(name); if (value != null) { return value; }/*from w w w . ja v a 2 s . com*/ } for (ImmutableConfigMap m : this.configs) { Class<?> value = m.getClassByName(name); if (value != null) { return value; } } throw new ClassNotFoundException(); }
From source file:at.treedb.util.SevenZip.java
/** * Modified class cloader to load Java classes from the archive. *///from w w w . jav a 2 s . c o m @Override public Class<?> findClass(String name) throws ClassNotFoundException { byte clazzData[] = null; try { String path = classPath + name.replace(".", "/") + ".class"; clazzData = getData(path); if (clazzData != null) { return defineClass(name, clazzData, 0, clazzData.length); } } catch (Exception e) { e.printStackTrace(); throw new ClassNotFoundException(); } return Class.forName(name); }