与Scala一起使用aspectj时出错

时间:2015-03-09 05:56:18

标签: scala sbt aspectj sbt-aspectj

我在scala中有一个应用程序。我需要使用AOP来实现其中一项功能。我使用了插件sbt-aspectj。当我使用sbt控制台运行时,一切正常。但是,在使用可执行jar时,我无法使其工作。我尝试了sbt-aspect git页面中提供的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页面中发布了这个,并在那里等待响应。但我有点急于解决这个问题。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

最后问题得到了解决。我在build.scala中添加了javaagent。但是,在使用sbt-one-jar运行时,它并没有使用那个jar。所以我手动提供了javaagent作为aspectweaver jar文件并且它有效。但是,使用方面启动jar文件几乎需要3-4分钟。

由于aspectjwaver,有时甚至花了15分钟来启动jar文件。我不确定这是facej或sbt-one-jar的问题,我猜它与一个jar。 还有其他人遇到过同样的问题吗?我没有在sbt-one-jar中看到任何活动,所以在这里问一下。