new LongOpt("mcast_port", LongOpt.REQUIRED_ARGUMENT, null, 'm'),
new LongOpt("hostname", LongOpt.REQUIRED_ARGUMENT, null, 'H'),
new LongOpt("nodename", LongOpt.REQUIRED_ARGUMENT, null, 'N'),
};
Getopt getopt = new Getopt(programName, args, sopts, lopts);
int code;
String arg;
while ((code = getopt.getopt()) != -1)
{
switch (code)
{
case ':' :
case '?' :
// for now both of these should exit with error status
System.exit(1);
break; // for completeness
case 1 :
// this will catch non-option arguments
// (which we don't currently care about)
System.err.println(programName + ": unused non-option argument: " + getopt.getOptarg());
break; // for completeness
case 'h' :
// show command line help
System.out.println("usage: " + programName + " [options]");
System.out.println();
System.out.println("options:");
System.out.println(" -h, --help Show this help message");
System.out.println(" -V, --version Show version information");
System.out.println(" -- Stop processing options");
System.out.println(" -D<name>[=<value>] Set a system property");
System.out
.println(" -d, --bootdir=<dir> Set the boot patch directory; Must be absolute or url");
System.out.println(" -p, --patchdir=<dir> Set the patch directory; Must be absolute or url");
System.out.println(" -n, --netboot=<url> Boot from net with the given url as base");
System.out.println(" -c, --configuration=<name> Set the server configuration name");
System.out.println(" -B, --bootlib=<filename> Add an extra library to the front bootclasspath");
System.out.println(" -L, --library=<filename> Add an extra library to the loaders classpath");
System.out.println(" -C, --classpath=<url> Add an extra url to the loaders classpath");
System.out.println(" -P, --properties=<url> Load system properties from the given url");
System.out.println(" -b, --host=<host or ip> Bind address for all JBoss services");
System.out.println(" -g, --partition=<name> HA Partition name (default=DefaultDomain)");
System.out.println(" -m, --mcast_port=<ip> UDP multicast port; only used by JGroups");
System.out.println(" -u, --udp=<ip> UDP multicast address");
System.out.println(" -H, --hostname=<name> Set the host name");
System.out.println(" -N, --nodename=<name> Set the node name to use");
System.out.println();
System.exit(0);
break; // for completeness
case 'D' : {
// set a system property
arg = getopt.getOptarg();
String name, value;
int i = arg.indexOf("=");
if (i == -1)
{
name = arg;
value = "true";
}
else
{
name = arg.substring(0, i);
value = arg.substring(i + 1, arg.length());
}
System.setProperty(name, value);
// Ensure setting the old bind.address property also sets the new
// jgroups.bind_addr property, otherwise jgroups may ignore it
if ("bind.address".equals(name))
{
System.setProperty("jgroups.bind_addr", value);
}
break;
}
case 'd' :
// set the boot patch URL
bootURL = makeURL(getopt.getOptarg());
break;
case 'p' : {
// set the patch URL
URL patchURL = makeURL(getopt.getOptarg());
//TODO
// props.put(ServerConfig.PATCH_URL, patchURL.toString());
break;
}
case 'n' :
// set the net boot url
arg = getopt.getOptarg();
// make sure there is a trailing '/'
if (!arg.endsWith("/"))
arg += "/";
props.put(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME_URL, new URL(arg).toString());
break;
case 'c' :
// set the server name
arg = getopt.getOptarg();
props.put(JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_NAME, arg);
break;
case 'V' : {
// Package information for org.jboss
Package jbossPackage = Package.getPackage("org.jboss");
// show version information
System.out.println("JBoss " + jbossPackage.getImplementationVersion());
System.out.println();
System.out.println("Distributable under LGPL license.");
System.out.println("See terms of license at gnu.org.");
System.out.println();
System.exit(0);
break; // for completness
}
case 'j' :
// Show an error and exit
System.err.println(programName + ": option '-j, --jaxp' no longer supported");
System.exit(1);
break; // for completness
case 'B' :
arg = getopt.getOptarg();
bootLibraries.add(new File(arg).toURI().toURL());
break;
case 'L' :
arg = getopt.getOptarg();
extraLibraries.add(new File(arg).toURI().toURL());
break;
case 'C' : {
URL url = makeURL(getopt.getOptarg());
extraClasspath.add(url);
break;
}
case 'P' : {
// Set system properties from url/file
URL url = makeURL(getopt.getOptarg());
Properties props = System.getProperties();
props.load(url.openConnection().getInputStream());
break;
}
case 'b' :
arg = getopt.getOptarg();
final String bindAddressPropName = JBossASServerConfig.PROP_KEY_JBOSSAS_BIND_ADDRESS;
props.put(bindAddressPropName, arg);
System.setProperty(bindAddressPropName, arg);
// used by JGroups; only set if not set via -D so users
// can use a different interface for cluster communication
// There are 2 versions of this property, deprecated bind.address
// and the new version, jgroups.bind_addr
String bindAddress = System.getProperty("bind.address");
if (bindAddress == null)
{
System.setProperty("bind.address", arg);
}
bindAddress = System.getProperty("jgroups.bind_addr");
if (bindAddress == null)
{
System.setProperty("jgroups.bind_addr", arg);
}
// Set the java.rmi.server.hostname if not set
String rmiHost = System.getProperty("java.rmi.server.hostname");
if (rmiHost == null)
{
System.setProperty("java.rmi.server.hostname", arg);
}
break;
case 'g' :
arg = getopt.getOptarg();
final String partitionNamePropName = JBossASServerConfig.PROP_KEY_JBOSSAS_PARTITION_NAME;
props.put(partitionNamePropName, arg);
System.setProperty(partitionNamePropName, arg);
break;
case 'u' :
arg = getopt.getOptarg();
final String udpGroupPropName = JBossASServerConfig.PROP_KEY_JBOSSAS_PARTITION_UDP_GROUP;
props.put(udpGroupPropName, arg);
System.setProperty(udpGroupPropName, arg);
// the new jgroups property name
System.setProperty("jgroups.udp.mcast_addr", arg);
break;
case 'm' :
arg = getopt.getOptarg();
final String udpPortPropName = JBossASServerConfig.PROP_KEY_JBOSSAS_PARTITION_UDP_PORT;
props.put(udpPortPropName, arg);
System.setProperty(udpPortPropName, arg);
break;
case 'H' : {
arg = getopt.getOptarg();
System.setProperty("jboss.qualified.host.name", arg.trim().toLowerCase());
break;
}
case 'N' : {
arg = getopt.getOptarg();
System.setProperty("jboss.node.name", arg.trim());
break;
}
default :