0

I have a Java web project which can't find the filter classes, I get this error:

java.lang.ClassNotFoundException: AuthFilter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at com.sun.grizzly.util.ClassLoaderUtil.load(ClassLoaderUtil.java:166)
    at com.sun.grizzly.util.ClassLoaderUtil.load(ClassLoaderUtil.java:154)
    at ____bootstrap.Deployer.setFilters(Deployer.java:277)
    at ____bootstrap.Deployer.deploy(Deployer.java:336)
    at ____bootstrap.Deployer.deployExpandedWar(Deployer.java:410)
    at ____bootstrap.Deployer.deployApplication(Deployer.java:405)
    at ____bootstrap.Deployer.deployApplications(Deployer.java:107)
    at ____bootstrap.Deployer.start(Deployer.java:203)
    at ____bootstrap.____Bootstrap._start(____Bootstrap.java:38)
    at ____bootstrap.____Bootstrap.start(____Bootstrap.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at ____embedded.____EntryPoint.invoke(____EntryPoint.java:273)
    at ____embedded.____EntryPoint.main(____EntryPoint.java:96)

The filters are in the classes dir: enter image description here

My web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>ApexMod</display-name>
     
    <context-param>
        <param-name>version</param-name>
        <param-value>1.1.4.195.00.12</param-value>
    </context-param>
    
    <listener>
        <listener-class>oracle.dbtools.rt.web.SCListener</listener-class>
    </listener>

    <filter>
        <filter-name>AuthFilter</filter-name>
        <filter-class>AuthFilter</filter-class>
        <init-param>
            <param-name>debug-mode</param-name>
            <param-value>true</param-value>
        </init-param>

I tried changing the class to classes.AuthFilter and WEB-INF.classes.AuthFilter

Is this the correct directory to put the filters?

user5507535
  • 1,580
  • 1
  • 18
  • 39
  • Does this answer your question? [Why am I getting a NoClassDefFoundError in Java?](https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – vaibhavsahu Aug 26 '21 at 23:29
  • The package name for `AuthFilter.java` is incorrect. It seems that this line can be removed (since your class is not in a package but at the root of your project) – blurfus Aug 27 '21 at 04:23

1 Answers1

2

package WEB-INF.classes; is incorrect; your 'root' is WEB-INF/classes, and then you have dirs for your packages inside that. Putting your source files in WEB-INF/classes is also not correct.

It sounds like your IDE configuration and/or build file is messed up. I'd start from the first page of the tutorial, set up a project properly, and then take that knowledge and fix your project here. The question doesn't include sufficient details (e.g. no mention of which web framework we're looking at here) to get into specifics, but as a general idea, your project structure should generally involve something along the lines of:

/home/user5507535/projects/MyCoolApp/src/main/java/com/foo/usersawesomething/AuthFilter.java

And then that source file should have package com.foo.usersawesomething; at the top. Gradle's build.gradle file would be in /home/user5507535/projects/MyCoolApp, and it would just know that sources live in src/main/java - you don't need to configure that.

Gradle would then (assuming you configured it properly, in accordance with your webapp needs) arrange for compilation to occur and for the class files to go in the appropriate WEB-INF/classes directory. Check your web framework's documentation and tutorial for more.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72