[wildfly-dev] Dynamically attaching AspectJ LTW weaver from EAR
Brian Stansberry
brian.stansberry at redhat.com
Wed Oct 18 16:01:36 EDT 2017
My interpretation is you are not interested in weaving any classes that are
provided by the server, so the basic requirement is to be able to do your
integration before any processing of your deployment starts.
A possibility is to use some hooks we've added in WildFly 11 that allow you
to register listeners for process lifecycle events:
1) A JMX listener: https://developer.jboss.org/wiki/JMXServerLifecycleEvents
2) A non-jmx variant:
https://docs.jboss.org/author/display/WFLY/Core+Management+Subsystem+Configuration
The problem with using either of these to do your registration is the
events are asynchronous, so the server is moving on with boot while your
code is getting the notification. So you would have a race between your
code setting things up and the boot moving on to deployment.
A hacky workaround to that is to start the server suspended (also new in WF
11, done via e.g. bin/standalone.sh --start-mode=suspend) and without the
deployment in the config (if with it there but not enabled). So you get the
notification and do your stuff, and then add or enable the deployment and
finally use the CLI ":resume" operation to bring the server to normal
state. But, then you'd have to reverse that when stopping or reloading the
server.
On Tue, Oct 17, 2017 at 9:00 PM, Eric B <ebenzacar at gmail.com> wrote:
> Hi,
>
> I'm looking to use AspectJ Load Time Weaving with Wildfly 10. Looking
> around at some posts, it is a little complicated to get Wildfly launched
> properly with the AJ weaver due to the way the AJ library intializes the
> logging subsystem differently than WF.
>
> Digging around, I found a config that actually works. It is documented
> here (obviously some of the class names/versions have to change):
> https://github.com/ChienChingLee/How-to-launch-
> Wildfly-9.0-with-AspectJ-1.8-LTW
>
> But I'm not a fan of changing my conf file to something that has hardcoded
> paths/jar names in it - for example adding:
> -Xbootclasspath/p:$JBOSS_HOME/modules/system/layers/
> base/org/jboss/logmanager/main/jboss-logmanager-2.0.0.Final.jar
>
>
> Digging around some more in AJ, I saw that as of AJ 1.8.7, there is a way
> to dynamically attach the weaver to the JVM. Very cool.
> https://www.eclipse.org/aspectj/doc/released/README-187.html
> But in order to use the LTW effectively, I need to ensure that the weaver
> is loaded prior to WF scanning and loading any of my classes (EJB,
> annotated beans, pojos, etc). But I have no ideas how to do that.
>
> In the case of a console application, it is pretty straight forward - make
> it the first item in the application's main() method. But in the case of a
> JEE app, I don't know of any main() equivalent.
>
>
> Is there a way to hook into the classloading mechanism of WF instead to
> tell it to load the weaver if it isn't already loaded? Can this be done
> from within the EAR deployment? Or is there a single point of entry that
> WF accesses before scanning any of the classes in the EAR? Or is there a
> simpler way of configuring or attaching the AJ Weaver? I did find an old
> ticket (https://issues.jboss.org/browse/WFLY-895) that related to this
> issue, but it is marked as WONT FIX.
>
> Am not sure of the best approach at this point.
>
>
> Thanks,
>
> Eric
>
> _______________________________________________
> wildfly-dev mailing list
> wildfly-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/wildfly-dev
>
--
Brian Stansberry
Manager, Senior Principal Software Engineer
Red Hat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/wildfly-dev/attachments/20171018/b86b3408/attachment.html
More information about the wildfly-dev
mailing list