Example usage for java.lang NoClassDefFoundError getMessage

List of usage examples for java.lang NoClassDefFoundError getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.github.kongchen.swagger.docgen.mavenplugin.SpringMavenDocumentSource.java

@Override
public void loadDocuments() throws GenerateException {
    Map<String, SpringResource> resourceMap = new HashMap<String, SpringResource>();
    SwaggerConfig swaggerConfig = new SwaggerConfig();
    swaggerConfig.setApiVersion(apiSource.getApiVersion());
    swaggerConfig.setSwaggerVersion(SwaggerSpec.version());
    List<ApiListingReference> apiListingReferences = new ArrayList<ApiListingReference>();
    List<AuthorizationType> authorizationTypes = new ArrayList<AuthorizationType>();

    //relate all methods to one base request mapping if multiple controllers exist for that mapping
    //get all methods from each controller & find their request mapping
    //create map - resource string (after first slash) as key, new SpringResource as value
    for (Class<?> c : apiSource.getValidClasses()) {
        RequestMapping requestMapping = (RequestMapping) c.getAnnotation(RequestMapping.class);
        String description = "";
        if (c.isAnnotationPresent(Api.class)) {
            description = ((Api) c.getAnnotation(Api.class)).value();
        }/*from  w w  w  .ja  v  a2s.  c o  m*/
        if (requestMapping != null && requestMapping.value().length != 0) {
            //This try/catch block is to stop a bamboo build from failing due to NoClassDefFoundError
            //This occurs when a class or method loaded by reflections contains a type that has no dependency
            try {
                resourceMap = analyzeController(c, resourceMap, description);
                List<Method> mList = new ArrayList<Method>(Arrays.asList(c.getMethods()));
                if (c.getSuperclass() != null) {
                    mList.addAll(Arrays.asList(c.getSuperclass().getMethods()));
                }
                for (Method m : mList) {
                    if (m.isAnnotationPresent(RequestMapping.class)) {
                        RequestMapping methodReq = m.getAnnotation(RequestMapping.class);
                        //isolate resource name - attempt first by the first part of the mapping
                        if (methodReq != null && methodReq.value().length != 0) {
                            for (int i = 0; i < methodReq.value().length; i++) {
                                String resourceKey = "";
                                String resourceName = Utils.parseResourceName(methodReq.value()[i]);
                                if (!(resourceName.equals(""))) {
                                    String version = Utils.parseVersion(requestMapping.value()[0]);
                                    //get version - first try by class mapping, then method
                                    if (version.equals("")) {
                                        //class mapping failed - use method
                                        version = Utils.parseVersion(methodReq.value()[i]);
                                    }
                                    resourceKey = Utils.createResourceKey(resourceName, version);
                                    if ((!(resourceMap.containsKey(resourceKey)))) {
                                        resourceMap.put(resourceKey,
                                                new SpringResource(c, resourceName, resourceKey, description));
                                    }
                                    resourceMap.get(resourceKey).addMethod(m);
                                }
                            }
                        }
                    }
                }
            } catch (NoClassDefFoundError e) {
                LOG.error(e.getMessage());
                LOG.info(c.getName());
                //exception occurs when a method type or annotation is not recognized by the plugin
            } catch (ClassNotFoundException e) {
                LOG.error(e.getMessage());
                LOG.info(c.getName());
            }

        }
    }
    for (String str : resourceMap.keySet()) {
        ApiListing doc = null;
        SpringResource resource = resourceMap.get(str);

        try {
            doc = getDocFromSpringResource(resource, swaggerConfig);
            setBasePath(doc.basePath());
        } catch (Exception e) {
            LOG.error("DOC NOT GENERATED FOR: " + resource.getResourceName());
            e.printStackTrace();
        }
        if (doc == null)
            continue;
        ApiListingReference apiListingReference = new ApiListingReference(doc.resourcePath(), doc.description(),
                doc.position());
        apiListingReferences.add(apiListingReference);
        acceptDocument(doc);

    }
    // sort apiListingRefernce by position
    Collections.sort(apiListingReferences, new Comparator<ApiListingReference>() {
        @Override
        public int compare(ApiListingReference o1, ApiListingReference o2) {
            if (o1 == null && o2 == null)
                return 0;
            if (o1 == null && o2 != null)
                return -1;
            if (o1 != null && o2 == null)
                return 1;
            return o1.position() - o2.position();
        }
    });
    serviceDocument = new ResourceListing(swaggerConfig.apiVersion(), swaggerConfig.swaggerVersion(),
            scala.collection.immutable.List
                    .fromIterator(JavaConversions.asScalaIterator(apiListingReferences.iterator())),
            scala.collection.immutable.List.fromIterator(
                    JavaConversions.asScalaIterator(authorizationTypes.iterator())),
            swaggerConfig.info());
}

From source file:org.beangle.model.persist.hibernate.internal.BundleDelegatingClassLoader.java

protected Class<?> findClass(String name) throws ClassNotFoundException {
    try {//  w w  w .j  av a2 s.co  m
        return this.backingBundle.loadClass(name);
    } catch (ClassNotFoundException cnfe) {
        // DebugUtils.debugClassLoading(backingBundle, name, null);
        throw new ClassNotFoundException(
                name + " not found from bundle [" + backingBundle.getSymbolicName() + "]", cnfe);
    } catch (NoClassDefFoundError ncdfe) {
        // This is almost always an error
        // This is caused by a dependent class failure,
        // so make sure we search for the right one.
        String cname = ncdfe.getMessage().replace('/', '.');
        // DebugUtils.debugClassLoading(backingBundle, cname, name);
        NoClassDefFoundError e = new NoClassDefFoundError(
                cname + " not found from bundle [" + backingBundle + "]");
        e.initCause(ncdfe);
        throw e;
    }
}

From source file:com.net2plan.cli.CLINet2Plan.java

/**
 * Default constructor./*w  w  w  .j  a v a2s .  c  o  m*/
 *
 * @param args Command-line arguments
 */
public CLINet2Plan(String args[]) {
    try {
        SystemUtils.configureEnvironment(CLINet2Plan.class, UserInterface.CLI);

        for (Class<? extends Plugin> plugin : PluginSystem.getPlugins(ICLIModule.class)) {
            try {
                ICLIModule instance = ((Class<? extends ICLIModule>) plugin).newInstance();
                modes.put(instance.getModeName(), instance.getClass());
            } catch (NoClassDefFoundError e) {
                e.printStackTrace();
                throw new Net2PlanException("Class " + e.getMessage() + " cannot be found. A dependence for "
                        + plugin.getSimpleName() + " is missing?");
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }

        Option helpOption = new Option("help", true,
                "Show the complete help information. 'modeName' is optional");
        helpOption.setArgName("modeName");
        helpOption.setOptionalArg(true);

        Option modeOption = new Option("mode", true,
                "Mode: " + StringUtils.join(StringUtils.toArray(modes.keySet()), ", "));
        modeOption.setArgName("modeName");
        modeOption.setOptionalArg(true);

        OptionGroup group = new OptionGroup();
        group.addOption(modeOption);
        group.addOption(helpOption);

        options.addOptionGroup(group);

        CommandLineParser parser = new CommandLineParser();
        CommandLine cli = parser.parse(options, args);

        if (cli.hasOption("help")) {
            String mode = cli.getOptionValue("help");
            System.out.println(mode == null ? getCompleteHelp() : getModeHelp(mode));
        } else if (!cli.hasOption("mode")) {
            System.out.println(getMainHelp());
        } else {
            String mode = cli.getOptionValue("mode");

            if (modes.containsKey(mode)) {
                ICLIModule modeInstance = modes.get(mode).newInstance();

                try {
                    modeInstance.executeFromCommandLine(args);
                } catch (Net2PlanException | JOMException ex) {
                    if (ErrorHandling.isDebugEnabled())
                        ErrorHandling.printStackTrace(ex);

                    System.out.println("Execution stopped");
                    System.out.println();
                    System.out.println(ex.getMessage());
                } catch (ParseException ex) {
                    System.out.println("Bad syntax: " + ex.getMessage());
                    System.out.println();
                    System.out.println(getModeHelp(mode));
                } catch (Throwable ex) {
                    Throwable ex1 = ErrorHandling.getInternalThrowable(ex);
                    if (ex1 instanceof Net2PlanException || ex1 instanceof JOMException) {
                        if (ErrorHandling.isDebugEnabled())
                            ErrorHandling.printStackTrace(ex);

                        System.out.println("Execution stopped");
                        System.out.println();
                        System.out.println(ex1.getMessage());
                    } else if (ex1 instanceof ParseException) {
                        System.out.println("Bad syntax: " + ex1.getMessage());
                        System.out.println();
                        System.out.println(getModeHelp(mode));
                    } else {
                        System.out.println("Execution stopped. An unexpected error happened");
                        System.out.println();
                        ErrorHandling.printStackTrace(ex1);
                    }
                }
            } else {
                throw new IllegalModeException("Bad mode - " + mode);
            }
        }
    } catch (IllegalModeException e) {
        System.out.println(e.getMessage());
        System.out.println();
        System.out.println(getMainHelp());
    } catch (ParseException e) {
        System.out.println("Bad syntax: " + e.getMessage());
        System.out.println();
        System.out.println(getMainHelp());
    } catch (Net2PlanException e) {
        if (ErrorHandling.isDebugEnabled())
            ErrorHandling.printStackTrace(e);
        System.out.println(e.getMessage());
    } catch (Throwable e) {
        ErrorHandling.printStackTrace(e);
    }
}

From source file:org.pentaho.reporting.libraries.base.boot.PackageState.java

/**
 * Configures the module and raises the state to STATE_CONFIGURED if the module is not yet configured.
 *
 * @param subSystem the sub-system./*from w  w w.  java  2s.  com*/
 * @return true, if the module was configured, false otherwise.
 */
public boolean configure(final SubSystem subSystem) {
    if (subSystem == null) {
        throw new NullPointerException();
    }

    if (this.state == STATE_NEW) {
        try {
            this.module.configure(subSystem);
            this.state = STATE_CONFIGURED;
            return true;
        } catch (NoClassDefFoundError noClassDef) {
            LOGGER.warn("Unable to load module classes for " + this.module.getName() + ':'
                    + noClassDef.getMessage());
            this.state = STATE_ERROR;
        } catch (Exception e) {
            if (LOGGER.isDebugEnabled()) {
                // its still worth a warning, but now we are more verbose ...
                LOGGER.warn("Unable to configure the module " + this.module.getName(), e);
            } else if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Unable to configure the module " + this.module.getName());
            }
            this.state = STATE_ERROR;
        }
    }
    return false;
}

From source file:org.pentaho.reporting.libraries.base.boot.PackageState.java

/**
 * Initializes the contained module and raises the set of the module to STATE_INITIALIZED, if the module was not yet
 * initialized. In case of an error, the module state will be set to STATE_ERROR and the module will not be
 * available./* w  w w.j  a va  2s . c o m*/
 *
 * @param subSystem the sub-system.
 * @return true, if the module was successfully initialized, false otherwise.
 */
public boolean initialize(final SubSystem subSystem) {
    if (subSystem == null) {
        throw new NullPointerException();
    }

    if (this.state == STATE_CONFIGURED) {
        try {
            this.module.initialize(subSystem);
            this.state = STATE_INITIALIZED;
            return true;
        } catch (NoClassDefFoundError noClassDef) {
            LOGGER.warn("Unable to load module classes for " + this.module.getName() + ':'
                    + noClassDef.getMessage());
            this.state = STATE_ERROR;
        } catch (ModuleInitializeException me) {
            if (LOGGER.isDebugEnabled()) {
                // its still worth a warning, but now we are more verbose ...
                LOGGER.warn("Unable to initialize the module " + this.module.getName(), me);
            } else if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Unable to initialize the module " + this.module.getName());
            }
            this.state = STATE_ERROR;
        } catch (Exception e) {
            if (LOGGER.isDebugEnabled()) {
                // its still worth a warning, but now we are more verbose ...
                LOGGER.warn("Unable to initialize the module " + this.module.getName(), e);
            } else if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Unable to initialize the module " + this.module.getName());
            }
            this.state = STATE_ERROR;
        }
    }
    return false;
}

From source file:org.eclipse.gemini.blueprint.util.BundleDelegatingClassLoader.java

protected Class<?> findClass(String name) throws ClassNotFoundException {
    try {//  www.jav  a 2s  .  co m
        return this.backingBundle.loadClass(name);
    } catch (ClassNotFoundException cnfe) {
        DebugUtils.debugClassLoading(backingBundle, name, null);
        throw new ClassNotFoundException(
                name + " not found from bundle [" + backingBundle.getSymbolicName() + "]", cnfe);
    } catch (NoClassDefFoundError ncdfe) {
        // This is almost always an error
        // This is caused by a dependent class failure,
        // so make sure we search for the right one.
        String cname = ncdfe.getMessage().replace('/', '.');
        DebugUtils.debugClassLoading(backingBundle, cname, name);
        NoClassDefFoundError e = new NoClassDefFoundError(name + " not found from bundle ["
                + OsgiStringUtils.nullSafeNameAndSymName(backingBundle) + "]");
        e.initCause(ncdfe);
        throw e;
    }
}

From source file:org.ebayopensource.turmeric.eclipse.functional.test.ft.wsdlsvc.ConsumerFromIntfTest.java

@Test
@Ignore("failing")
public void testConsumeCalculatorSvc() throws Exception {

    // Turn on the auto-build for the builders to kick-in
    SimpleTestUtil.setAutoBuilding(true);

    try {//from  w  w  w  . j  a  v a2s  . co m
        Boolean b = createServiceFromWsdl(new File(WSDL_FILE).toURI().toURL(), namespacePart);

        Assert.assertTrue(adminName + "  creation failed", b);

        StringBuffer failMessages = ProjectArtifactValidator.getErroredFileMessage();

        ProjectArtifactValidator.getErroredFileMessage().setLength(0);
        // validate artifacts
        boolean intfMatch = ServiceSetupCleanupValidate
                .validateIntfArtifacts(WorkspaceUtil.getProject(adminName), adminName);
        Assert.assertTrue(" --- Service artifacts validation failed for " + failMessages, intfMatch);

        String consumerId = "CalcConsumer_Id";
        List<String> environment = new ArrayList<String>();
        environment.add("production");
        ConsumerFromJavaParamModel model = new ConsumerFromJavaParamModel();
        model.setBaseConsumerSrcDir("src");
        model.setClientName(adminName + "Consumer");
        ArrayList<String> list = new ArrayList<String>();
        list.add(adminName);
        model.setServiceNames(list);
        model.setParentDirectory(PARENT_DIR);
        model.setConsumerId(consumerId);
        model.setEnvironments(environment);

        SimpleTestUtil.setAutoBuilding(false);

        ServiceCreator.createConsumerFromJava(model, ProgressUtil.getDefaultMonitor(null));
        SimpleTestUtil.setAutoBuilding(true);
        // Add validation for the expected artifacts and contents..
        boolean consumerMatch = ServiceSetupCleanupValidate.validateConsumerArtifacts(
                WorkspaceUtil.getProject(adminName + "Consumer"), adminName + "Consumer");

        System.out.println(failMessages.toString());
        Assert.assertTrue(" --- Service artifacts validation failed for " + failMessages.toString(),
                consumerMatch);
        ProjectArtifactValidator.getErroredFileMessage().setLength(0);

        // we know that the CC.xml or GCC.xml is the last artifact to be
        // created
        // The project exists as
        IProject consProject = WorkspaceUtil.getProject(model.getClientName());

        consProject.build(IncrementalProjectBuilder.FULL_BUILD, ProgressUtil.getDefaultMonitor(null));
        // if project build goes through, its a successful test
    } catch (NoClassDefFoundError ex) {
        assumeNoException(ex);
    } catch (Exception ex) {
        System.out.println("--- Exception in consumeCalculatorSvc() - " + ex.getMessage());
        System.out.println("--- Exception in consumeCalculatorSvc() toString - " + ex.toString());
        System.out.println("--- Exception in consumeCalculatorSvc() getCause - " + ex.getCause().getMessage());
        Assert.fail("Exception in consumeCalculatorSvc() - " + ex.getLocalizedMessage());
    }
}

From source file:org.ops4j.pax.web.extender.samples.whiteboard.internal.Activator.java

public void start(final BundleContext bundleContext) throws Exception {
    Dictionary props;//from  w w w. ja v a2s. c  om

    // register a custom http context that forbids access
    props = new Hashtable();
    props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden");
    m_httpContextReg = bundleContext.registerService(HttpContext.class.getName(), new WhiteboardContext(),
            props);
    // and an servlet that cannot be accessed due to the above context
    props = new Hashtable();
    props.put(ExtenderConstants.PROPERTY_ALIAS, "/forbidden");
    props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden");
    m_forbiddenServletReg = bundleContext.registerService(Servlet.class.getName(),
            new WhiteboardServlet("/forbidden"), props);

    props = new Hashtable();
    props.put("alias", "/whiteboard");
    m_servletReg = bundleContext.registerService(Servlet.class.getName(), new WhiteboardServlet("/whiteboard"),
            props);

    props = new Hashtable();
    props.put("alias", "/root");
    m_rootServletReg = bundleContext.registerService(HttpServlet.class.getName(),
            new WhiteboardServlet("/root"), props);

    DefaultResourceMapping resourceMapping = new DefaultResourceMapping();
    resourceMapping.setAlias("/whiteboardresources");
    resourceMapping.setPath("/images");
    m_resourcesReg = bundleContext.registerService(ResourceMapping.class.getName(), resourceMapping, null);

    try {
        // register a filter
        props = new Hashtable();
        props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/whiteboard/filtered/*");
        m_filterReg = bundleContext.registerService(Filter.class.getName(), new WhiteboardFilter(), props);
    } catch (NoClassDefFoundError ignore) {
        // in this case most probably that we do not have a servlet version >= 2.3
        // required by our filter
        LOG.warn("Cannot start filter example (javax.servlet version?): " + ignore.getMessage());
    }

    try {
        // register a servlet request listener
        m_listenerReg = bundleContext.registerService(EventListener.class.getName(), new WhiteboardListener(),
                null);
    } catch (NoClassDefFoundError ignore) {
        // in this case most probably that we do not have a servlet version >= 2.4
        // required by our request listener
        LOG.warn("Cannot start filter example (javax.servlet version?): " + ignore.getMessage());
    }

    // servlet to test exceptions and error pages
    props = new Hashtable();
    props.put("alias", "/exception");
    m_exceptionServletRegistration = bundleContext.registerService(HttpServlet.class.getName(),
            new ExceptionServlet(), props);

    // register resource at root of bundle
    DefaultResourceMapping rootResourceMapping = new DefaultResourceMapping();
    rootResourceMapping.setAlias("/");
    rootResourceMapping.setPath("");
    m_rootResourceMappingRegistration = bundleContext.registerService(ResourceMapping.class.getName(),
            rootResourceMapping, null);

    // register welcome page - interesting how it will work with the root servlet, i.e. will it showdow it
    DefaultWelcomeFileMapping welcomeFileMapping = new DefaultWelcomeFileMapping();
    welcomeFileMapping.setRedirect(true);
    welcomeFileMapping.setWelcomeFiles(new String[] { "index.html", "welcome.html" });
    m_welcomeFileRegistration = bundleContext.registerService(WelcomeFileMapping.class.getName(),
            welcomeFileMapping, null);

    // register error pages for 404 and java.lang.Exception
    DefaultErrorPageMapping errorpageMapping = new DefaultErrorPageMapping();
    errorpageMapping.setError("404");
    errorpageMapping.setLocation("/404.html");

    m_404errorpageRegistration = bundleContext.registerService(ErrorPageMapping.class.getName(),
            errorpageMapping, null);

    // java.lang.Exception
    DefaultErrorPageMapping exceptionErrorMapping = new DefaultErrorPageMapping();
    exceptionErrorMapping.setError(java.lang.Exception.class.getName());
    exceptionErrorMapping.setLocation("/uncaughtException.html");
    m_uncaughtExceptionRegistration = bundleContext.registerService(ErrorPageMapping.class.getName(),
            exceptionErrorMapping, null);
}

From source file:org.apache.axis2.jaxws.framework.JAXWSDeployer.java

protected void deployServicesInWARClassPath() {
    String dir = DeploymentEngine.getWebLocationString();
    if (dir != null) {
        File file = new File(dir + "/WEB-INF/classes/");
        URL repository = axisConfig.getRepository();
        if (!file.isDirectory() || repository == null)
            return;
        ArrayList<String> classList = getClassesInWebInfDirectory(file);
        ClassLoader threadClassLoader = null;
        try {// ww w.j av  a 2 s .  c om
            threadClassLoader = Thread.currentThread().getContextClassLoader();
            ArrayList<URL> urls = new ArrayList<URL>();
            urls.add(repository);
            String webLocation = DeploymentEngine.getWebLocationString();
            if (webLocation != null) {
                urls.add(new File(webLocation).toURL());
            }
            ClassLoader classLoader = Utils.createClassLoader(urls, axisConfig.getSystemClassLoader(), true,
                    (File) axisConfig.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR),
                    axisConfig.isChildFirstClassLoading());
            Thread.currentThread().setContextClassLoader(classLoader);
            deployClasses("JAXWS-Builtin", file.toURL(), Thread.currentThread().getContextClassLoader(),
                    classList);
        } catch (NoClassDefFoundError e) {
            if (log.isDebugEnabled()) {
                log.debug(Messages.getMessage("deployingexception", e.getMessage()), e);
            }
        } catch (Exception e) {
            log.info(Messages.getMessage("deployingexception", e.getMessage()), e);
        } finally {
            if (threadClassLoader != null) {
                Thread.currentThread().setContextClassLoader(threadClassLoader);
            }
        }
    }
}

From source file:org.hyperic.hq.product.PluginManager.java

protected String classNotFoundMessage(NoClassDefFoundError e) {
    return "Plugin class not found: " + e.getMessage() + " (invalid classpath or corrupt plugin jar)";
}