Assets NOT Found with Jooby 2.0 WAR in Tomcat!

12 views
Skip to first unread message

niko...@brightminds.org

unread,
Oct 19, 2021, 4:42:28 AM10/19/21
to jooby-project
Hi,

I used a Servlet wrapper to kick-off the Jooby main however the Assets are not working properly.  I have a folder called "assets" at /assets (root of WAR) yet I get this exception:

Anyone have any clue on how to get Assets to work with Tomcat.  Anyone using Jooby 2?

[2021-10-19 08:22:56,500]-[main] ERROR io.jooby.Jooby - Application initialization resulted in exception
java.io.FileNotFoundException: /assets
at io.jooby.AssetSource.create(AssetSource.java:104)
at com.digitalstore.base.App.<init>(App.java:76)
at io.jooby.Jooby.createApp(Jooby.java:1143)
at io.jooby.Jooby.runApp(Jooby.java:1113)
at io.jooby.Jooby.runApp(Jooby.java:1077)
at com.digitalstore.base.App.main(App.java:200)
at com.digitalstore.base.AppServlet.init(AppServlet.java:10)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1164)
...
19-Oct-2021 08:22:56.502 SEVERE [main] org.apache.catalina.core.ApplicationContext.log Servlet.init() for servlet [AppServlet] threw exception
io.jooby.exception.StartupException: Application initialization resulted in exception
at io.jooby.Jooby.createApp(Jooby.java:1148)
at io.jooby.Jooby.runApp(Jooby.java:1113)
at io.jooby.Jooby.runApp(Jooby.java:1077)
at com.digitalstore.base.App.main(App.java:200)
at com.digitalstore.base.AppServlet.init(AppServlet.java:10)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1164)
...
19-Oct-2021 08:22:56.504 SEVERE [main] org.apache.catalina.core.StandardContext.loadOnStartup Servlet [AppServlet] in web application [] threw load() exception
java.io.FileNotFoundException: /assets
at io.jooby.AssetSource.create(AssetSource.java:104)
at com.digitalstore.base.App.<init>(App.java:76)
at io.jooby.Jooby.createApp(Jooby.java:1143)
at io.jooby.Jooby.runApp(Jooby.java:1113)
at io.jooby.Jooby.runApp(Jooby.java:1077)
at com.digitalstore.base.App.main(App.java:200)
at com.digitalstore.base.AppServlet.init(AppServlet.java:10)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
...
19-Oct-2021 08:22:56.585 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
19-Oct-2021 08:22:56.596 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["https-openssl-apr-8443"]
19-Oct-2021 08:22:56.598 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [3769] milliseconds

Thank You,

--Nikolaos

István Mészáros

unread,
Oct 19, 2021, 5:03:31 AM10/19/21
to niko...@brightminds.org, jooby-project
Hey Niko,

the docs for Jobby v2 dont mention it can be built/deployed as WAR. Im unsure wether it's possible. How did you generate the WAR? does it have the descriptor file WEB-INF/web.xml? I might be wrong, but getting it working through Jooby main sounds not right for me.. I suspect asset resolution fails because of this.

regards,
István

--
You received this message because you are subscribed to the Google Groups "jooby-project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooby-projec...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooby-project/89b63fec-34b7-4d14-a4c1-dbf86642a948n%40googlegroups.com.

niko...@brightminds.org

unread,
Oct 19, 2021, 5:18:51 AM10/19/21
to jooby-project
Hi

Actually... I seem to almost have it working (fingers crossed)... I have a Hikari/DB issue to now work through on a new server but that is expected.

Yes - normally a web app / WAR does not have a main() method that is called but where there is a will there is a way :-)

Essentially I created a servlet that loads right away and bootstraps my main() class method that extends Jooby by including in web.xml the following:
 
<!-- Servlet used to simply Bootstrap Jooby 2 main class -->
<servlet>
<servlet-name>AppServlet</servlet-name>
<servlet-class>com.digitalstore.base.AppServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>AppServlet</servlet-name>
<url-pattern>/appServlet</url-pattern>
</servlet-mapping>

Then the issue with Assets is actually b/c of the parameter passed to Assets.create() which up until now was an Absolute path.

So I changed the code as follows:

AssetSource ui;
try {
// Assume asset is available via absolute path
ui = AssetSource.create(Paths.get("assets"));
}
catch (Exception ex) {
// Otherwise running inside a WAR so need to load path via class loader
ui = AssetSource.create(App.class.getClassLoader(), "assets");
}

Ultimately, this kind of feels like a hack but I need this to run in Tomcat - I am support many virtual hosts with SSL on single IP (via SNI) and Tomcat just works.

If you know of an easier way OR see any not yet discovered issues please let me know.

--Nikolaos

Reply all
Reply to author
Forward
0 new messages