Mixing AspectJ and Scala in an Eclipse Project

久未见 提交于 2019-12-05 10:14:13

Based on your comment above, it looks like you want a single project to use both the AspectJ builder and the Scala builder. This is not possible. Each one delegates to its own compiler and the two compilers are not (yet) compatible. The Scala compiler can build Java and Scala code together, and the AspectJ compiler can build AspectJ and Java code together, but that's it.

If you want aspects to apply to your Scala code, you must separate your AspectJ and Scala code into different projects and then add the Scala project to the inpath of your AspectJ project.

This is the same thing that you would need to do if you were compiling from ant or the command line.

Right now, the recommended version is still Eclipse3.5.2.

Tickets like 1000075 or 3251 mention:

If you're desperate there's an experimental nightly build update site at http://download.scala-ide.org/nightly-update-wip-helios-2.8.0.final.

Today, the current nightly you could try with Helios 3.6 would be:

http://download.scala-ide.org/nightly-update-master-2.8.1.final

I've been struggling with this for some time now. Here is my Solution:

First, separate your Scala and your AspectJ code into different projects.

Then add an Ant builder to your Scala project. It runs whenever the scala builder runs and does the weaving. It uses ant4eclipse to extract the classpath, but you'll have to supply the location of the scala library.

Build.xml:

<project name="simple-example" default="compile"
xmlns:ant4eclipse="antlib:org.ant4eclipse"
         xmlns:antcontrib="antlib:net.sf.antcontrib">

<ant4eclipse:jdtClassPathLibrary name="org.scala-ide.sdt.launching.SCALA_CONTAINER">
  <fileset file="../lib/scala-library.jar"/>
</ant4eclipse:jdtClassPathLibrary >

<ant4eclipse:getJdtClassPath 
    workspacedirectory=".."
    projectName="lpfExample"
    property="classpath"/>

<target name="compile">
    <iajc sourceroots="src" destdir="bin">
        <inpath>
            <pathelement location="bin" />
        </inpath>
        <aspectpath>
            <pathelement location="../aspects/bin"/>
        </aspectpath>
        <classpath path="${classpath}"/>
    </iajc>
</target>
</project>

Do you mean having both the Scala plug-in and AJDT installed simultaneously? This is definitely doable -- it's needed for developing the Scala plug-in itself, for example.

I do the following:

  • Install the AspectJ dev tools + eclipse weaving service feature
  • Install Scala IDE, but omit JDT Weaving for Scala
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!