use of org.apache.jackrabbit.standalone.cli.JcrClient in project jackrabbit by apache.
the class Main method run.
public void run() throws Exception {
String defaultFile = "jackrabbit-standalone.jar";
URL location = Main.class.getProtectionDomain().getCodeSource().getLocation();
if (location != null && "file".equals(location.getProtocol())) {
File file = new File(location.getPath());
if (file.isFile()) {
defaultFile = location.getPath();
}
}
File file = new File(command.getOptionValue("file", defaultFile));
if (command.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar " + file.getName(), options, true);
} else if (command.hasOption("notice")) {
copyToOutput("/META-INF/NOTICE.txt");
} else if (command.hasOption("license")) {
copyToOutput("/META-INF/LICENSE.txt");
} else if (command.hasOption("cli")) {
System.setProperty("logback.configurationFile", "logback-cli.xml");
String uri = command.getOptionValue("cli");
Repository repository = JcrUtils.getRepository(uri);
Context context = new ContextBase();
CommandHelper.setRepository(context, repository, uri);
try {
Session session = repository.login();
CommandHelper.setSession(context, session);
CommandHelper.setCurrentNode(context, session.getRootNode());
} catch (RepositoryException ignore) {
// anonymous login not possible
}
new JcrClient(context).runInteractive();
try {
CommandHelper.getSession(context).logout();
} catch (CommandException ignore) {
// already logged out
}
} else {
message("Welcome to Apache Jackrabbit!");
message("-------------------------------");
File repository = new File(command.getOptionValue("repo", "jackrabbit"));
message("Using repository directory " + repository);
repository.mkdirs();
File tmp = new File(repository, "tmp");
tmp.mkdir();
File log = new File(repository, "log");
log.mkdir();
message("Writing log messages to " + log);
prepareServerLog(log);
if (command.hasOption("backup")) {
backup(repository);
} else {
message("Starting the server...");
prepareWebapp(file, repository, tmp);
accessLog.setHandler(webapp);
prepareAccessLog(log);
server.setHandler(accessLog);
prepareConnector();
server.addConnector(connector);
prepareShutdown();
try {
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
message("Apache Jackrabbit is now running at " + "http://" + host + ":" + connector.getPort() + "/");
} catch (Throwable t) {
System.err.println("Unable to start the server: " + t.getMessage());
System.exit(1);
}
}
}
}
Aggregations