我有一个Java / Scala混合项目。在Intellij建设时,事情很好。但是,尝试从命令行运行Maven构建时,在运行“mvn clean install'”时会出现此错误:
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:12: error: object model is not a member of package com.test.userlib
[ERROR] import com.test.userlib.model.cte.{ItemResponse, CteUser}
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:13: error: object utils is not a member of package com.test.userlib
[ERROR] import com.test.userlib.utils.UserLibProperties
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:26: error: not found: value UserLibProperties
[ERROR] .hosts(UserLibProperties.CTE_USERSERVICE_HOST + ":" + UserLibProperties.CTE_USERSERVICE_PORT)
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:32: error: not found: value UserLibProperties
[ERROR] ClientAuthTlsConfigUtil.createSslContext(new File(UserLibProperties.CTE_USERSERVICE_KEYSTORE),UserLibProperties.CTE_USERSERVICE_KEYSTORE_PASSWORD,new File(UserLibProperties.CTE_USERSERVICE_TRUSTSTORE),UserLibProperties.CTE_USERSERVICE_TRUSTSTORE_PASSWORD)
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:35: error: not found: type CteUser
[ERROR] protected def getUser(dn :String) :CteUser = {
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:36: error: not found: value UserLibProperties
[ERROR] val rb = RequestBuilder().url(s"${UserLibProperties.CTE_USERSERVICE_ENDPOINT}/user?dn=${URLEncoder.encode(dn,"utf-8")}&aacAttribs=true").buildGet
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:42: error: not found: type ItemResponse
[ERROR] case HttpResponseStatus.OK => new ObjectMapper().readValue(respTry.get.getContent.toString("UTF-8"), classOf[ItemResponse]).getItem.getUser
[ERROR] ^
[ERROR] 7 errors found
所以,很明显我的Scala类没有找到它需要的Java依赖项。这是我项目的结构:
这是我的pom.xml的构建部分:
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我是否必须以某种方式将类路径添加到Scala编译器?
答案 0 :(得分:0)
我认为UserLibProperties文件应该在适当的文件扩展名UserLibProperties.scala中。请检查您的文件夹并执行列表命令并检查文件扩展名,在Intelij中它将无法正常扩展。
答案 1 :(得分:-3)
我认为,SBT是建立混合项目的最佳方式。
例如: https://github.com/databricks/learning-spark/blob/master/build.sbt
它没有什么学习曲线,但值得在SBT投入时间。