Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stucture for Java project with multiple main entry points and executables?

I'm writing a server in Java. To support the development of the server, I have a few classes with main() methods that I intend to run from a command line as development tools to do such things as diagnostics, simulate client connections and exercise modules in isolation from the rest of the server. Currently, these classes are part of the main server project.

What's the best approach for structuring my project to support these multiple executable tools? Should I create separate projects for these simulation / loading / diagnostic tools, or keep them in the main server project? If I keep them in the main project, should I configure the project to build multiple executable jars or a single jar with multiple entry points? If a single jar is used, would it be possible to specify the primary entry point for the server as the default?

like image 728
HolySamosa Avatar asked Feb 22 '23 20:02

HolySamosa


1 Answers

Unless the server and the utilities have completely different dependencies, I would make it simple, and put everything in a single jar. Provide shell scripts which wrap the calls to the appropriate classes:

# startServer.cmd
java -cp MyServer.jar;other.jar com.foo.myserver.Main

#showDiagniostics.cmd
java -cp MyServer.jar;other.jar com.foo.myserver.Diagnostics

You can make it an executable jar with the server startup class as the main class, but I find it easier to have an executable script than to have to use java -jar MyServer.jar

like image 51
JB Nizet Avatar answered Feb 24 '23 11:02

JB Nizet