简体   繁体   中英

Compilation error using scala classes in java maven project

I have a java maven project , i installed scala plugin for eclipse and added scala nature to my project . Now , i have written some custom scala Actors and some other utility classes .I am using these scala classes in my java code . while writing the code , it doesn't throw any errors .But , when i do maven clean /build , it throws compilation error's like below

11/8/11 10:45:23 AM : [ERROR] ............\Simple.java:[86,10] cannot find symbol
symbol  : variable ExecutorObject
location: class com.ms.scala.Simple
11/8/11 10:45:23 AM : [INFO] 2 errors 
11/8/11 10:45:23 AM : [INFO] -------------------------------------------------------------
11/8/11 10:45:23 AM : Build errors for Project; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project : Compilation failure

Eclipse IDE : helios -3.5 , Scala - 2.9.2 which comes with the plugin

i guess there is a custom compiler configuration for doing this ? i also have an other newbie question

how do you start scala actor directly in java and send a message to it ? all i can see is the act() method . i want to do this

actor {

CustomActor ! Message

}

in java

thank you sanre6

For the first part, have you added the scala compilation step to your maven pom? Have you added the maven-scala-plugin to your pom?

For the second part, as Mirco says, there is no simple way to define an Actor in Java. You'll have to define it in Scala, but you can then start it and send messages to it in Java.

Simply call start() on the instance, and then you should be able to pass messages to it using the ! method. This will be available in java, but it is called $bang .

Go to http://scala-tools.org/mvnsites/maven-scala-plugin/example_java.html and use the pom directly for a first test. I have done it with:

  1. A Scala class "ScalaUtils" inside src/main/scala
  2. A java class inside src/main/java which uses "ScalaUtils"

The important thing is to to add the scala compilation at the right phase, before java will be compiled:

<execution>
    <phase>process-resources</phase>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM