1

I have a library that requires me to specify a javaagent using the aspectjweaver jar. eg.

java -jar  -javaagent:/some/location/aspectjweaver-1.8.2.jar myFatJar.jar

This works fine. However, the environment that my fatjar will be running on does not have aspectjweaver-1.8.2.jar and I can't put it there (getting a more configurable environment may be a route I go down later).

Is there a way, preferably using sbt-assembly, to package up aspectjweaver into my fatjar, and run it that way? If it matters, my application is a Spray one using Scala, built using sbt.

Constraints

  • Can't have a separate jar
  • Can specify an arbitrary java command
  • Have complete control of the build process
Ren
  • 3,395
  • 2
  • 27
  • 46

1 Answers1

2

If you have, as you say, complete control over the build process, why don't you use compile-time weaving instead of load-time weaving? Then you just package the AspectJ runtime library aspectjrt.jar into your fat jar and are done with the problem. You even avoid the overhead of runtime weaving on application start-up.

The only reason I can think of which makes this approach problematic is that you need to weave joinpoints outside the control of your build process.

kriegaex
  • 63,017
  • 15
  • 111
  • 202