SBT 0.13 프로젝트에서 메인 클래스를 설정하는 방법
SBT 프로젝트에서 메인 클래스를 설정하는 방법을 설명해 주시겠습니까? 버전 0.13을 사용하려고합니다.
내 디렉토리 구조는 매우 간단합니다 (SBT의 문서와 달리). 루트 폴더에는 build.sbt다음 내용이 있습니다.
name := "sbt_test"
version := "1.0"
scalaVersion := "2.10.1-local"
autoScalaLibrary := false
scalaHome := Some(file("/Program Files (x86)/scala/"))
mainClass := Some("Hi")
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.10" % "2.0.M5b" % "test"
)
EclipseKeys.withSource := true
그리고 다음 코드가 포함 된 project단일 파일 Hi.scala이 있는 하위 폴더 가 있습니다.
object Hi {
def main(args: Array[String]) = println("Hi!")
}
호출하여 컴파일 할 수 sbt compile있지만 sbt run반환
The system cannot find the file C:\work\externals\sbt\bin\sbtconfig.txt.
[info] Loading project definition from C:\work\test_projects\sbt_test\project
[info] Set current project to sbt_test (in build file:/C:/work/test_projects/sbt_test/)
java.lang.RuntimeException: No main class detected.
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) No main class detected.
[error] Total time: 0 s, completed Apr 8, 2013 6:14:41 PM
애플리케이션의 소스를 src/main/scala/, project/빌드 정의 코드 에 넣어야합니다 .
클래스를 사용하는 대신 객체를 사용하고 App에서 확장하십시오.
object Main extends App {
println("Hello from main scala object")
}
메인 클래스도 메인 메소드를 실행해야하기 때문에
메인 클래스를 지정하는 방법은 다음과 같습니다.
mainClass in (Compile,run) := Some("my.fully.qualified.MainClassName")
SBT (0.13)의 사용자 정의 모듈의 경우 SBT 콘솔에 다음을 입력하십시오.
project moduleX
[info] Set current project to moduleX (in build file:/path/to/Projects/)
> run
[info] Running main
Built.scala에 정의 된대로 범위를 moduleX로 전환합니다. 해당 범위 내의 모든 기본 클래스가 자동으로 감지됩니다. 그렇지 않으면 메인 클래스가 감지되지 않는 동일한 오류가 발생합니다. 제발, SBT는 기본 범위가 설정되지 않았 음을 알려주지 않습니다. 기본 소스 폴더와 기본이 아닌 소스 폴더와는 아무런 관련이 없지만 SBT는 기본적으로 사용할 모듈을 알지 못한다는 것을 알려주지 않습니다.
typesafe에 대한 큰 힌트 : 다음과 같은 기본 출력을 추가하십시오.
[info] Project module is not set. Please use ''project moduleX'' set scope
or set in Built file (LinkToDocu)
SBT가 끝나면 다중 모듈 프로젝트에서 SBT를 사용하는 동안 좌절의 수준을 낮추기 시작합니다 .....
프로젝트에 여러 기본 메서드가있는 경우 build.sbt 파일에 다음 줄을 추가 할 수 있습니다.
val projectMainClass = "com.saeed.ApplicationMain"
mainClass in (Compile, run) := Some(projectMainClass)
If you want to specify the class that will be added to the manifest when your application is packaged as a JAR file, add this line to your build.sbt file:
mainClass in (Compile, packageBin) := Some(projectMainClass)
You can also specify main class using run-main command in sbt and activator to run:
sbt "run-main com.saeed.ApplicationMain"
or
activator "run-main com.saeed.ApplicationMain"
I had the same issue: was mode following the tutorial at http://www.scala-sbt.org/0.13/docs/Hello.html, and in my opinion, as a build tool sbt's interaction and error messages can be quite misleading to a newcomer.
It turned out, hours of head scratching later, that I missed the critical cd hello line in the example each time. :-(
There are 4 options
you have 1 main class
sbt runand sbt will find main for you
you have 2 or more main classes
sbt runand sbt will propose to select which one you want to run.
Multiple main classes detected, select one to run:
[1] a.b.DummyMain1
[2] a.b.DummyMain2
Enter number:
You want to set main class manually.
mainClass in run := Some("a.b.DummyMain1")You could run with main class as parameter
sbt runMain a.b.DummyMain1
If the Main class is in a different project then by setting the below command in build.sbt would work:
addCommandAlias("run", "; project_folder/run")
참고URL : https://stackoverflow.com/questions/15891708/how-to-set-main-class-in-sbt-0-13-project
'Program Club' 카테고리의 다른 글
| Java 8의 java.time API에서 시간 조롱 (0) | 2020.10.19 |
|---|---|
| java : "최종"System.out, System.in 및 System.err? (0) | 2020.10.19 |
| 이동 : 패닉 : 런타임 오류 : 유효하지 않은 메모리 주소 또는 포인터 역 참조 없음 (0) | 2020.10.19 |
| Django와 ReactJS-실제 사용 (0) | 2020.10.19 |
| Javascript의 sort ()는 어떻게 작동합니까? (0) | 2020.10.19 |