Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set main class in build?

Tags:

sbt

Upon sbt run I have multiple choices of main class.

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

mainClass := Some("aMainClass") 

But sbt fails with:

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

I've also tried with project/Project.scala file :

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

error :

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

How to set the main class in a build?

like image 306
user312728 Avatar asked Jun 24 '11 11:06

user312728


People also ask

How do I set main class?

To change the main class being used, go to the File menu and choose Project Properties. This dialog gives all the options that can be changed in a NetBeans project. Click on the Run category. On this page, there is a Main-Class option.

What is main class in Maven project?

maventest. App class in the project is the main class that should be executed if someone attempts to execute the jar file. Additional options that can be configured for the Maven Archiver can be found at http://maven.apache.org/shared/maven-archiver/index.html.


1 Answers

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") 

Note:

mainClass := Some("myPackage.aMainClass") 

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

like image 60
Rich Oliver Avatar answered Oct 13 '22 08:10

Rich Oliver