Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Dynamically loading a @ServerEndpoint class at runtime

If the classes don't exist to be scanned then they cannot be discovered and loaded at startup/init of the Web app that needs them.

You are left with manually adding the ServerEndpoint's using the techniques described in JSR-356.

This must happen during the WebApp deploy/init phase (it is against the spec to add endpoints after deploy/init during the execution of the WebApp).
Best approach is to create a ServletContainerInitializer that obtains a reference to the javax.websocket.server.ServerContainer (see javadoc on how), then use one of the two addEndpoint() methods.

Joakim Erdfelt / joakim@xxxxxxxxxxx


On Fri, May 3, 2019 at 8:17 AM Adam Retter <adam.retter@xxxxxxxxxxxxxx> wrote:
Hi Joakim,

Thanks for the quick reply, however I am not sure if I quite explained
my need in enough detail...

We need to do this after Jetty has already been configured and started.

> The class MUST be a class accessible via a JAR or FileSystem (no dynamic classes or purely runtime classes supported).
> This is because the only way we can scan for Annotations is via the ASM library.

The class is in a Jar file which we have loaded using our custom
classloader named org.exist.start.EXistClassLoader. I am not sure how
Jetty would know about this class loader? Do we need to tell Jetty
about it somehow?

> If these classes are on the Server / System classpath, then the `org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern` context attribute can be modified (hint: it's a regex) to include the server jars (of filesystem paths) that have your classes that you are interested in.
>

The classes are NOT on the Server or the System classpath, they are
loaded on-demand at runtime via our EXistClassLoader. So I don't think
changing `ContainerIncludeJarPattern` will help here.

Does that make more sense now?

--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top