0

我在scala中有一个应用程序。我需要将 AOP 用于其中一项功能。我使用了插件sbt-aspectj。当我使用 sbt 控制台运行时,一切正常。但是,在使用可执行 jar 时,我无法使其工作。我尝试了sbt-aspect git 页面中提供的示例代码。但是,我得到的错误是

[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 页面上发布了这个,并在那里等待回复。但我有点急于解决这个问题。您的帮助将不胜感激。

4

1 回答 1

0

终于问题解决了。我在build.scala. 但是,在运行时sbt-one-jar,它并没有占用那个罐子。所以我手动提供了 javaagent 作为 aspectweaver jar 文件并且它工作。但是,使用方面启动 jar 文件几乎需要 3-4 分钟。

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

于 2015-03-09T11:25:12.260 回答