I'm am creating a VoIP client server pair in java using the netbeans IDE. I would like to use only 1 project but I am unfamiliar with with how netbeans would create the Jar file. I need a to if this is possible and if so, how to set it up.
Jar files can contain only one Main-Class attribute in the manifest, which means a jar can contain only one mainClassName.
From the above program, we can say that Java can have multiple main methods but with the concept of overloading. There should be only one main method with parameter as string[ ] arg.
We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …] As we can see, in this case, we'll have to include the main class name in the command line, followed by arguments.
The JAR File Specification allows only one Main-Class
attribute per JAR, but the JAR may have an arbitrary number of classes that declare a main()
method. Any such class will be included in the project's Build
Packaging
property, unless specifically excluded.
As a concrete example, H2 Database includes these classes with main()
:
org.h2.jdbcx.JdbcConnectionPool org.h2.tools.Backup org.h2.tools.ChangeFileEncryption org.h2.tools.Console org.h2.tools.ConvertTraceFile org.h2.tools.ConvertTraceFile org.h2.tools.CreateCluster org.h2.tools.DeleteDbFiles org.h2.tools.Recover org.h2.tools.Restore org.h2.tools.RunScript org.h2.tools.Script org.h2.tools.Server org.h2.tools.Shell
Addendum: Apparently, my junk-drawer project needs maintenance.
$ find scratch/src -name \*java | xargs -J % egrep 'main[ \t]*\(Str' % | wc -l 109
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With