Scala导入编译器错误

时间:2012-02-24 16:15:52

标签: eclipse scala maven compiler-errors

我使用Maven + Eclipse + M2e + Scala,我注意到eclipse和maven命令行中编译器的不同行为。

例如maven(命令行)抱怨如下:

[ERROR] /home/julien/Documents/donnees/projets/site-garde-enfants/java/service/src/test/scala/com/bignibou/dao/DAOTest.scala:18: error: AdvertisementService is not a member of com.bignibou.service.advertisement
[INFO] import com.bignibou.service.advertisement.AdvertisementService
[INFO]        ^

而我在eclipse中没有得到任何编译器错误......

任何人都可以帮忙吗?

这是我的POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.bignibou</groupId>
        <artifactId>bignibou</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.bignibou</groupId>
    <artifactId>bignibou-service</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>bignibou-service</name>

    <!-- Shared version number properties -->
    <properties>
        <org.springframework.version>3.1.0.RELEASE</org.springframework.version>
    </properties>

    <dependencies>
        <!-- Core utilities used by other modules. Define this if you use Spring 
            Utility APIs (org.springframework.core.*/org.springframework.util.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Expression Language (depends on spring-core) Define this if you use 
            Spring Expression APIs (org.springframework.expression.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Bean Factory and JavaBeans utilities (depends on spring-core) Define 
            this if you use Spring Bean APIs (org.springframework.beans.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Aspect Oriented Programming (AOP) Framework (depends on spring-core, 
            spring-beans) Define this if you use Spring AOP APIs (org.springframework.aop.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Application Context (depends on spring-core, spring-expression, spring-aop, 
            spring-beans) This is the central artifact for Spring's Dependency Injection 
            Container and is generally always defined -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Various Application Context utilities, including EhCache, JavaMail, 
            Quartz, and Freemarker integration Define this if you need any of these integrations -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Transaction Management Abstraction (depends on spring-core, spring-beans, 
            spring-aop, spring-context) Define this if you use Spring Transactions or 
            DAO Exception Hierarchy (org.springframework.transaction.*/org.springframework.dao.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, 
            spring-tx) Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, 
            and iBatis. (depends on spring-core, spring-beans, spring-context, spring-tx) 
            Define this if you need ORM (org.springframework.orm.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Object-to-XML Mapping (OXM) abstraction and integration with JAXB, 
            JiBX, Castor, XStream, and XML Beans. (depends on spring-core, spring-beans, 
            spring-context) Define this if you need OXM (org.springframework.oxm.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Web application development utilities applicable to both Servlet and 
            Portlet Environments (depends on spring-core, spring-beans, spring-context) 
            Define this if you use Spring MVC, or wish to use Struts, JSF, or another 
            web framework with Spring (org.springframework.web.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!-- Support for testing Spring applications with tools such as JUnit and 
            TestNG This artifact is generally always defined with a 'test' scope for 
            the integration testing framework and unit testing stubs -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.0.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>com.bignibou</groupId>
            <artifactId>bignibou-domain</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.9.1</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.htm</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.scala-tools</groupId>
                                        <artifactId>maven-scala-plugin</artifactId>
                                        <versionRange>[2.15.0,)</versionRange>
                                        <goals>
                                            <goal>test-compile</goal>
                                            <goal>compile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*Test.*</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

和我的scala类:

package com.bignibou.dao

import java.sql.Timestamp
import java.util.ArrayList
import java.util.Collection
import java.util.Date
import java.util.List

import javax.inject.Inject

import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner

import com.bignibou.domain._
import com.bignibou.oldDao.DAO
import com.bignibou.service.advertisement.AdvertisementService

@RunWith(classOf[SpringJUnit4ClassRunner])
@ContextConfiguration(Array("classpath:bignibou-configuration-context.xml"))
class DAOTest {

  @Inject
  val dao: DAO

  @Inject
  val advertisementService: AdvertisementService

  @Test
  def testPersistChildminderAdvertisement = {
    val childminderAdvertisement: ChildminderAdvertisement = new ChildminderAdvertisement

    val availabilities = new ArrayList[AdvertisementToTimeSlotToDayJoin]

    val avail_1: AdvertisementToTimeSlotToDayJoin = new AdvertisementToTimeSlotToDayJoin
    avail_1.setAdvertisement(childminderAdvertisement)
    avail_1.setDay(new Day(2))
    avail_1.setTimeSlot(new TimeSlot(3))

    val avail_2: AdvertisementToTimeSlotToDayJoin = new AdvertisementToTimeSlotToDayJoin
    avail_2.setAdvertisement(childminderAdvertisement)
    avail_2.setDay(new Day(1))
    avail_2.setTimeSlot(new TimeSlot(1))

    availabilities.add(avail_1)
    availabilities.add(avail_2)

    childminderAdvertisement.setAdvertisementToTimeSlotToDayJoinCollection(availabilities)

    // childcarelocation
    val childCareLocation: ChildCareLocation = new ChildCareLocation(2)
    childminderAdvertisement.setChildcarelocationID(childCareLocation)

    // childcaretype
    val childCareType_one: ChildCareType = new ChildCareType
    childCareType_one.setChildcaretypeID(1)
    val childCareType_two: ChildCareType = new ChildCareType()
    childCareType_two.setChildcaretypeID(3)
    val col: Collection[ChildCareType] = new ArrayList[ChildCareType]()

    col.add(childCareType_one)
    col.add(childCareType_two)

    childminderAdvertisement.setChildCareTypeCollection(col)

    // misc
    childminderAdvertisement.setAdvertisementTitle("titre mlqkjflmkqsdf")
    childminderAdvertisement.setAdvertisementBody("sdlkfj toto est beau")
    childminderAdvertisement.setAdvertisementCreationDate(new Timestamp(new Date().getTime()))
    val childminderAccount: Account = dao.loadAccountFromAccountEmailAddress("balteo@yahoo.fr")
    childminderAdvertisement.setAccountID(childminderAccount)

    advertisementService.persistChildminderAdvertisement(childminderAdvertisement)
  }
}

1 个答案:

答案 0 :(得分:1)

如果您希望在Maven中编译Scala类,则必须添加适当的插件。没有插件,类不会被编译。 Maven在提供的POM方面表现正确......

 <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.15.2</version>
            <configuration>
                <args>
                    <arg>-optimise</arg>

                </args>
                <scalaVersion>2.9.1</scalaVersion>
                <!--fork>false</fork-->

            </configuration>
            <executions>


                <execution>
                    <id>compile</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                    <phase>compile</phase>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                    <phase>test-compile</phase>
                </execution>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>