在 Scala 中使用 aspectj 时出错

Error while using aspectj with Scala

我在 scala 中有一个应用程序。我需要将 AOP 用于其中一项功能。我使用了 sbt-aspect git 页面中提供的插件 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。但是,我得到的错误是

[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]  

我的Build.scala如下:

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)
}

有谁知道如何解决这个问题?我将其发布在 sbt-aspectj github 页面中,并在那里等待回复。但我有点急于解决这个问题。非常感谢您的帮助。

问题终于解决了。我在 build.scala 中添加了 javaagent。但是,虽然 运行 sbt-one-jar,但它并没有拿走那个罐子。所以我手动提供了 javaagent 作为 aspectweaver jar 文件并且它有效。但是用aspect启动jar文件差不多要3-4分钟。

有时由于 aspectjwaver,启动 jar 文件甚至需要 15 分钟。我不确定这是 aspectj 还是 sbt-one-jar 的问题,我猜是 one-jar 的问题。 还有其他人面临同样的问题吗?我在 sbt-one-jar 中没有看到任何 activity,所以在这里问。