Can I use the Java surfer servlet class from other referenced class libraries?

I have five web applications in my project and you want to filter HTTP requests, but I do not want to write a Filter class for each web application, because there will be no application behavior. What is the most practical way to do this?

I tried to create only one Filter in another class library called MyClassLibrary , but it does not work. Other classes in this library can be used by web applications, so I don't think there is a reference problem.

Part of the web.xml filter for one of the applications:

 <filter> <filter-name>SampleFilter</filter-name> <filter-class>MyClassLibrary.Filters.SampleFilter</filter-class> </filter> <filter-mapping> <filter-name>SampleFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 

This throws an exception:

java.lang.ClassNotFoundException: MyClassLibrary.Filters.SampleFilter

Platform: Windows, NetBeans, GlassFish

+4
source share
2 answers

Please check the following

  • Make sure your class compiled without errors.
  • Be sure to deploy these web applications to the project / jar that contains your library
  • From the name, it looks like SampleFilter is an inner class. If this is the case, make sure the filters and SampleFilter are static inner class MyClassLibrary and do not have an args constructor
  • Are you missing the package name before MyClassLibrary?
+1
source

If the exception is a ClassNotFoundException, it means that you did not specify the MyClassLibrary class in the classpath of your application.

Make sure your MyClassLibrary class is listed from the application of this web.xml.

Sincerely.

0
source

Source: https://habr.com/ru/post/1486858/


All Articles