如何在构建中设置主类? [英] How to set main class in build?

查看:44
本文介绍了如何在构建中设置主类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sbt run 我有多种主类选择.

我想设置一个主类,所以我在build.sbt中写了:

I would like to set a main class so I've writen in build.sbt:

mainClass := Some("aMainClass")

但是 sbt 失败了:

But sbt fails with:

build.sbt:1: error: not found: value aMainClass

我也试过 project/Project.scala 文件:

import sbt._
  class ExecutableProject(info: ProjectInfo) extends DefaultProject(info)  {
  override def mainClass = Some("aMainClass")
}

错误:

 project/Project.scala:3: not found: type aMainClass

如何在构建中设置主类?

How to set the main class in a build?

推荐答案

主类必须完全符合包的要求:

The main Class must be fully qualified with the package:

Compile/mainClass := Some("myPackage.aMainClass")

这将适用于运行,它会在使用包任务时在清单中设置主类.这些任务的主类可以单独设置,如下所示:

This will work for run and it will set the Main-Class in the Manifest when using the package task. The main class for these tasks can be set separately as in:

mainClass in (Compile, run) := Some("myPackage.aMainClass")
mainClass in (Compile, packageBin) := Some("myPackage.anotherMainClass")

注意:

mainClass := Some("myPackage.aMainClass")

什么都不做.如果你把它放在你的构建文件中,你将不会收到它什么都不做的警告.

does nothing. If you put this in your build file you will receive no warning that it does nothing.

这篇关于如何在构建中设置主类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆