I'm trying to add webapp folder with static HTML pages to JAXRSArchive with Wildfly Swarm. But unfortunately it was not successful. How can I do that?
Wildfly Swarm JAXRSArchive add webapp directory
626 views Asked by Nikita At
3
There are 3 answers
3
On
Copy all your static files in src/main/webapp
and in you main method add the call staticContenet
as follows
public static void main(String... args) throws Exception {
Swarm container = new Swarm();
JAXRSArchive jaxrsDeployment = ShrinkWrap.create(JAXRSArchive.class);
jaxrsDeployment.addAsLibrary(container.createDefaultDeployment());
jaxrsDeployment.addAllDependencies();
jaxrsDeployment.staticContent();
container.start();
container.deploy(jaxrsDeployment);
0
On
This question is outdated. But I post this solution for those who run into the same issue.
The problem might happen if you're using JAX-RS
without specifying @ApplicationPath
.
By default JAX-RS listens to the root /
of your app and overrides standard mapping.
In this case you have to add configuration like this:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/api")
public class JaxRSConfiguration extends Application {
}
This will prefix all your JAX-RS
endpoints with /api
and let you work with static content.
Can you elaborate on why you need a custom main()?
The preferred option is to not use a custom main(), or if you must have a custom main() to not customize the deployment.
You can just call Swarm.deploy() and it will create a default deployment, which if your project is of type war, will work fine