0

I am having an application in scala. I need to use AOP for one of the functionality. I used the plugin sbt-aspectj . Everything is working fine when I run using the sbt console. However, I am not able to make it work when using the executable jar. I tried the the sample code provided in the sbt-aspect git page. But, I am getting the errors as

[warn] warning incorrect classpath: D:\source\jvm\modules\scala\frameworks\aspectjTracer\target\scala-2.11\classes
[warn] Missing message: configure.invalidClasspathSection in: org.aspectj.ajdt.ajc.messages
[error] error no sources specified

.

[trace] Stack trace suppressed: run 'last aspectjTracer/aspectj:ajc' for the full output.
[error] (aspectjTracer/aspectj:ajc) org.aspectj.bridge.AbortException: ABORT
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: aspectjTracker (similar: aspectjSource, aspectj-source, aspectjDirectory)
[error] last aspectjTracker/aspectj:ajc
[error]  

My Build.scala is given below :

object frameworkBuild extends Build {

  import Dependencies._
  val akkaV = "2.3.6"
  val sprayV = "1.3.1"
  val musterV = "0.3.0"

  val common_settings = Defaults.defaultSettings ++
    Seq(version := "1.3-SNAPSHOT",
      organization := "com.reactore",
      scalaVersion in ThisBuild := "2.11.2",
      scalacOptions ++= Seq("-unchecked", "-feature", "-deprecation"),

      libraryDependencies := frameworkDependencies ++ testLibraryDependencies,
      publishMavenStyle := true,

    )

  connectInput in run := true

  lazy val aspectJTracer = Project(
    "aspectjTracer",
    file("aspectjTracer"),
    settings = common_settings ++ aspectjSettings ++ Seq(
      // input compiled scala classes
      inputs in Aspectj <+= compiledClasses,

      // ignore warnings
      lintProperties in Aspectj += "invalidAbsoluteTypeName = ignore",
      lintProperties in Aspectj += "adviceDidNotMatch = ignore",

      // replace regular products with compiled aspects
      products in Compile <<= products in Aspectj
    )
  )
  // test that the instrumentation works
  lazy val instrumented = Project(
    "instrumented",
    file("instrumented"),
    dependencies = Seq(aspectJTracer),
    settings = common_settings ++ aspectjSettings ++ Seq(
      // add the compiled aspects from tracer
      binaries in Aspectj <++= products in Compile in aspectJTracer,

      // weave this project's classes
      inputs in Aspectj <+= compiledClasses,
      products in Compile <<= products in Aspectj,
      products in Runtime <<= products in Compile
    )
  )
  lazy val frameworks = Project(id = "frameworks", base = file("."), settings = common_settings).aggregate( core, baseDomain,aspectJTracer,instrumented)

  lazy val core = Project(id = "framework-core", base = file("framework-core"), settings = common_settings)
  lazy val baseDomain = Project(id = "framework-base-domain", base = file("framework-base-domain"), settings = common_settings).dependsOn(core,aspectJTracer,instrumented)
}

Does anyone know how to fix this? I posted this in the sbt-aspectj github page and waiting for a response there as well. But I am in a little hurry to fix this. Your help will be really appreciated.

Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80

1 Answers1

0

Finally the problem is resolved. I had added javaagent in the build.scala. But, while running with the sbt-one-jar, it was not taking that jar. So I have manually provided the javaagent as the aspectweaver jar file and it worked. However, it is almost taking 3-4 minutes to start the jar file with the aspect.

Sometime it is even taking 15 min to start the jar file due to the aspectjwaver. I am not sure if this is problem with aspectj or sbt-one-jar, I guess its with the one-jar. has anyone else faced the same issue ? I don't see any activity in sbt-one-jar, so asking it here.

Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80
  • Well, if you want to know why it is slow, test both variants, with one-jar and with small JAR and dependencies on the classpath. Either way, make sure that your aspects are not woven into every class but just into the ones you are interested in. The way the pointcuts are defined can make a big difference in performance. Furthermore, the *aop.xml* can specify which classes or packages you want to target and which ones wou want to exclude from weaving. – kriegaex Apr 05 '15 at 10:41
  • Oh, by the way: If you think your own answer is correct and solves the problem, please accept it in order to close the question. – kriegaex Apr 05 '15 at 10:42
  • As for one-jar solutions, I remember from a big Java project that we had to switch from one-jar with nested JARs to shaded JAR with unpacked dependencies. This was much faster when starting up the application. Because sbt-one-jar uses one-jar, this might be the problem. But please test this hypothesis instead of just buying it. – kriegaex Apr 05 '15 at 10:43
  • @kriegaex : Thank you very much, I shall try that out as well. We are having some other issues when using one-jar. I guess, I should some alternatives. – Yadu Krishnan Apr 06 '15 at 05:27