How can I host a .jar file directly inside a war in Wildfly/JBoss?
Question
So I have a very simple question. I've got a fairly trivial .war file that will happily host any type of file I throw at it - except for a .jar file.
Here's my .war file:
WEB-INF/web.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" />
META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.2
Created-By: 1.8.0_05-b13 (Oracle Corporation)
and the following four files:
index.html
folder/jar.jar
folder/jar.zip
folder/index.html
I'm deploying my war to a wildfly-8.1.0 server as "testwar.war". When I do so, I can access all of the files except folder/jar.jar via a perfectly normal URL:
http://localhost:8080/testwar/
http://localhost:8080/testwar/folder/
http://localhost:8080/testwar/folder/jar.zip
All of those work. But
http://localhost:8080/testwar/folder/jar.jar
returns a 404.
I can't for the life of me figure out why the jar file won't show up, or how to fix it. Any thoughts?
Solution
The default servlet of Wildfly/Undertow has a list of allowed and disallowed extensions which can be configured in web.xml
via init parameters. jar
is disallowed by default.
Add the following to your web.xml
to enable the jar
extension:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>io.undertow.servlet.handlers.DefaultServlet</servlet-class>
<init-param>
<param-name>default-allowed</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>allowed-extensions</param-name>
<param-value>jar</param-value>
</init-param>
<init-param>
<param-name>disallowed-extensions</param-name>
<param-value>exe,bat,sh</param-value>
</init-param>
</servlet>
OTHER TIPS
Found the answer here: JBoss community thread
Version 8.1.0 of WildFly by default refuses to serve out .jar files; you have to override that by adding the following block to your web.xml (by default, "jar" is a disallowed extension):
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>io.undertow.servlet.handlers.DefaultServlet</servlet-class>
<init-param>
<param-name>allowed-extensions</param-name>
<param-value>jar, js, css, png, jpg, gif, html, htm, txt, pdf, jpeg, xml, zip</param-value>
</init-param>
<init-param>
<param-name>disallowed-extensions</param-name>
<param-value>class, war</param-value>
</init-param>
</servlet>