1

Marvin Framework is running perfectly in my Java project in Eclipse. I have copied the whole marvin folder to the project root folder, following the readme file. All good.

Now, when setting up the same app as dynamic web project in Eclipse and try to run it on Eclipses tomcat 9, I get a HTTP Status 500 – Internal Server Error caused by java.lang.ClassNotFoundException (see 'ERROR 1'below).

It seems, in a dynamic web project the jars should be in WEB-INF/lib. When copying marvin_1.5.5.jar to WEB-INF/lib the class marvin.image.MarvinImage is found correctly (ERROR 1 disappears).

But unfortunately the Marvin image plugins are not found. I have tried to copy the whole marvin folder to WEB-INF/lib - did not work. I got another HTTP Status 500 – Internal Server Error with java.lang.NullPointerException (see 'ERROR 2' below). I have tried to set the MarvinDefinitions.setImagePluginPath to myproject/WebContent/WEB-INF/lib/plugins/ - did not work. I got an error in the console: java.nio.file.NoSuchFileException: \myproject\WebContent\WEB-INF\lib\plugins\org.marvinproject.image.transform.scale.jar.

-> Does anyone know how to implement Marvin in a dynamic web project properly?

ERROR 1

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Servlet execution threw an exception

Beschreibung The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception
javax.servlet.ServletException: Servlet execution threw an exception
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


Root Cause
java.lang.NoClassDefFoundError: marvin/image/MarvinImage
    controller.HomeController.doPost(HomeController.java:58)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


Root Cause
java.lang.ClassNotFoundException: marvin.image.MarvinImage
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
    controller.HomeController.doPost(HomeController.java:58)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

ERROR 2

HTTP Status 500 – Internal Server Error
Type Exception Report

Beschreibung The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception
java.lang.NullPointerException
    marvin.util.MarvinJarLoader.getClass(MarvinJarLoader.java:69)
    marvin.util.MarvinJarLoader.getObject(MarvinJarLoader.java:51)
    marvin.util.MarvinPluginLoader.loadPlugin(MarvinPluginLoader.java:55)
    marvin.util.MarvinPluginLoader.loadImagePlugin(MarvinPluginLoader.java:37)
    marvin.MarvinPluginCollection.checkAndLoadImagePlugin(MarvinPluginCollection.java:1225)
    marvin.MarvinPluginCollection.scale(MarvinPluginCollection.java:956)
    marvin.MarvinPluginCollection.scale(MarvinPluginCollection.java:973)
    controller.HomeController.doPost(HomeController.java:60)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Archy
  • 13
  • 2

1 Answers1

0

The problem with the way the Marvin zip distribution works is that it loads the JAR files at runtime as files. So you'll have to find out where the plugins were deployed. Retrieving a reference to the ServletContext and setting:

MarvinDefinitions.setImagePluginPath(servletContext.getRealPath("/WEB-INF/lib/plugins"));

might work if the WAR archive was unpacked to a directory (as Eclipse does). But it won't work in every situation.

A better solution is to download the Marvin jars (MarvinFramework and MarvinPlugins) from Maven and put them into your WEB-INF/lib folder (or add them as dependencies of the project if you are using Maven). In this distribution all the plugins will be already loaded and available through the static methods in the marvinplugins.MarvinPluginCollection class.

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
  • Thanks Piotr for yor reply, I really appreciate it. I did download all Marvin jars and copied the whole marvin folder, including subfolders containing the jars to my WEB-INF/lib. But then I got ERROR 2 mentioned above. Seemingly the plugins are not loaded correctly. Any other idea? PS: the app runs on local Eclipse tomcat, no WAR has been created. – Archy Jan 28 '21 at 07:54
  • I downloaded the Marvin jars (MarvinFramework and MarvinPlugins) from Maven and put them into my WEB-INF/lib folder. Additionally I have set up the project as Maven and added the (MarvinFramework and MarvinPlugins) as dependencies. In both cases the marvin plugin collection is not available from my servlet using import static marvin.MarvinPluginCollection.*; Error: The import marvin.MarvinPluginCollection cannot be resolved. – Archy Jan 28 '21 at 09:56
  • The full name of the class is `marvinplugins.MarvinPluginCollection` not `marvin.MarvinPluginCollection`. – Piotr P. Karwasz Jan 28 '21 at 10:31
  • Many thanks Piotr. Your systematic advice worked perfectly well. Both versions (Java and Maven) are running without any issues now! Great, thanks again! – Archy Jan 28 '21 at 13:47