Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple main classes in a single module #80

Closed
sclasen opened this issue Nov 19, 2013 · 10 comments
Closed

support multiple main classes in a single module #80

sclasen opened this issue Nov 19, 2013 · 10 comments

Comments

@sclasen
Copy link

sclasen commented Nov 19, 2013

While it is possible to get native packager to output start scripts for each of a multi-module project, it would be nice if there was an optional way to pass the main class to the bin script, target/universal/stage/bin/<module> -m some.main.Clazz

this might also bring for free a repl without sbt needed? (not sure of the mechanics)
target/universal/stage/bin/<module> -m the.scala.repl.main.Clazz

@jsuereth
Copy link
Member

Great idea and patches welcome :)

So for the latter, the issue with the REPL is that you'd need the scala-compiler and dependencies to be in the lib/*.jar somewhere. By default, this doesn't happen unless you explicitly depend on the compiler in your project.

Otherwise, neat idea. Repl is scala.tools.MainGenericRunner or some such. You know, great names lead to great things....

@hellojinjie
Copy link

I am looking this feathure

@jsuereth
Copy link
Member

Great! Look forward to seeing what yu produce. Let me know if you need help.

@kardapoltsev
Copy link
Member

And don't forget about server applications where we need to specify exact
main class in start script)

Regards, Alexey
On Dec 25, 2013 8:51 PM, "Josh Suereth" [email protected] wrote:

Great! Look forward to seeing what yu produce. Let me know if you need
help.


Reply to this email directly or view it on GitHubhttps://github.com//issues/80#issuecomment-31200388
.

@divijan
Copy link

divijan commented Nov 5, 2015

Hi, I have come across this issue searching for a way to package a project with two main classes. The OP states it is possible, but more recent StackOverflow discussion suggests the opposite. I am confused.

@tpunder
Copy link

tpunder commented Nov 5, 2015

The sbt-native-packager generated script allows you to pass in a -main argument to specify the main class you want to run. Here's what I do for a project named foo:

Create a run.sh script with whatever common options you want that calls the sbt-native-packager generated script:

#!/bin/bash

./target/universal/stage/bin/foo -main "$@"

Then I create a separate script for each main class I want to run. For example first.sh:

#!/bin/bash

export JAVA_OPTS="-Xms512m -Xmx512m"

./run.sh com.example.FirstApp -- "$@"

and second.sh:

#!/bin/bash

export JAVA_OPTS="-Xms2048m -Xmx2048m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC"

./run.sh com.example.SecondApp -- "$@"

@divijan
Copy link

divijan commented Nov 5, 2015

that makes sense. Can I then package the two scripts into two upstart services, or one which would run both scripts?

@tpunder
Copy link

tpunder commented Nov 5, 2015

Not sure about upstart. I'm usually packaging up my stuff using docker (although I don't use the sbt-native-packager docker functionality for that).

@muuki88
Copy link
Contributor

muuki88 commented Nov 5, 2015

@tpunder thanks for sharing! saw your SO answer, too late before suggesting an edit.

@divijan So your use-case is starting two different applications, right? The recommended way would be to package two applications by adding two submodules for each package. This way you have redudant code, but a clear separation.

@divijan
Copy link

divijan commented Nov 5, 2015

@muuki88 not sure I understand your suggestion. I have one sbt project with two main classes I would like to run. Should I package my project twice with different main class selected in build.sbt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants