xxx is already defined as object xxx+intellij新建一个scala的maven项目+找不到或无法载入主要类别hello问题解决
------------------------------------------------------------------------------------------------------------------------------------------
先說xxx is already defined as object xxx的問題:
工程目錄結構不對
------------------------------------------------------------------------------------------------------------------------------------------
注意刪除現有的.idea文件夾
?
設置好JDK
?
?
關于intellij新建scala項目的問題(下面選擇的是maven,不是scala):
一路next后得到工程目錄如下:
刪除java文件夾,新建scala文件夾,新建hello.scala文件,然后得到下面的提示:
?
然后File->Settings->Plugin中的scala插件已經安裝。
?
確保文件名和object名是一樣的。
?
然后運行的時候會碰到下面的問題:
錯誤: 找不到或無法載入主要類別hello
解決方案:
右鍵工程文件夾標記為Sources Root
?
運行:
運行結果如下:
上面也可以是把src右鍵Mark Directory as Sources Root
#----------------------------------------------------------------附錄--------------------------------------------------------------------------------------------------------
src/main/scala/hello.scala
object hello {def main(args: Array[String]){println("Hello World")} }pom.xml
<?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><groupId>hello</groupId><artifactId>hello</artifactId><version>1.0-SNAPSHOT</version></project>?
?
?
總結
以上是生活随笔為你收集整理的xxx is already defined as object xxx+intellij新建一个scala的maven项目+找不到或无法载入主要类别hello问题解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cf手游m4a1电音如何觉醒 CF正版官
- 下一篇: uc浏览器 极速版(UC浏览器官网)