kumuluz / kumuluzee

Lightweight open-source framework for developing microservices using standard Java EE technologies and migrating Java EE to cloud-native architecture.
https://ee.kumuluz.com
MIT License
291 stars 71 forks source link

Uberjar returns 404 if the JAX-RS resources are in a jar #118

Closed andref closed 6 years ago

andref commented 6 years ago

I have a multimodule maven project organized such that one module is the JAX-RS application and another module is the KumuluzEE app itself. The latter depends on the former. I have pushed a very small repo to demonstrate the issue at https://github.com/andref/kumuluzee-uberjar-bug.

The app runs fine from any IDE or from the command line:

java -cp $(ls application/target/classes/lib/*.jar | paste -s -d":" -) \
     com.kumuluz.ee.EeApplication

During the start-up process, it notes:

INFO -- KumuluzEE running in an exploded class and dependency runtime.

The app responds as expected:

$ curl -X HEAD -I http://localhost:8080/v1/hello
HTTP/1.1 200 OK
Date: Sat, 01 Sep 2018 17:21:08 GMT
X-Powered-By: KumuluzEE/2.5.3
Content-Type: application/json
Content-Length: 11
Server: Jetty(9.4.8.v20171121)

Now, if I run the uberjar generated by the kumuluzee-maven-plugin, things go wrong. The app notes:

INFO -- KumuluzEE running inside a JAR runtime.

And although it appears to be running, it does not respond:

$ curl -X HEAD -I http://localhost:8080/v1/hello
HTTP/1.1 404 Not Found
Date: Sat, 01 Sep 2018 17:21:56 GMT
X-Powered-By: KumuluzEE/2.5.3
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=iso-8859-1
Content-Length: 324
Server: Jetty(9.4.8.v20171121)

As there's nothing really weird about packaging the JAX-RS resources and application in a jar (since the equivalent war webapp would run just fine), I believe this must be a bug in either the maven plugin or the class loading mechanism used by the uberjar.

urbim commented 6 years ago

Hi!

KumuluzEE Uber JAR packaging does not support annotation scanning in project's dependencies. It only scans application classes.

You have some options. We recommend keeping the JAX-RS classes in main application. Or you can run your application as exploded, which supports dependency scanning.

Another option is creating a JAX-RS dynamic feature class in your main application and registering resources from libraries manually.

andref commented 6 years ago

@urbim is it just not implemented or is there a fundamental reason why it's not supported? If you point me at the right direction, I might be able to contribute a patch to add support for that.

urbim commented 6 years ago

We decided not to support it. If I recall correctly, the main reason was it slowed down our start-up times significantly.

andref commented 6 years ago

@urbim of course! that makes sense.