001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 package org.activemq.spring; 019 020 import org.activemq.broker.BrokerContainer; 021 import org.activemq.broker.BrokerContext; 022 import org.activemq.util.IdGenerator; 023 import org.springframework.core.io.ClassPathResource; 024 import org.springframework.core.io.FileSystemResource; 025 026 import javax.jms.JMSException; 027 028 /** 029 * A simple command line tool which runs a JMS Message Broker on the command line 030 * using a Spring XML deployment descriptor 031 * 032 * @version $Revision$ 033 */ 034 public class Main { 035 036 /** 037 * run the Message Broker as a standalone application 038 * 039 * @param args 040 */ 041 public static void main(String args[]) { 042 try { 043 String version = ""; 044 Package p = Package.getPackage("org.activemq"); 045 if (p != null) { 046 version = ": " + p.getImplementationVersion(); 047 } 048 System.out.println("ActiveMQ Message Broker (http://activemq.org/) " + version); 049 System.out.println(); 050 051 SpringBrokerContainerFactory factory = new SpringBrokerContainerFactory(); 052 String file = null; 053 if (args.length <= 0) { 054 System.out.println("Loading Message Broker from activemq.xml on the CLASSPATH"); 055 factory.setResource(new ClassPathResource("activemq.xml")); 056 } 057 else { 058 file = args[0]; 059 060 if (file.equals("-?") || file.equals("?") || file.equals("--help") || file.equals("-h")) { 061 System.out.println("Usage: Main [xmlConfigFile]"); 062 System.out.println("If an XML config file is not specified then activemq.xml is used from the CLASSPAHT"); 063 return; 064 } 065 066 System.out.println("Loading Message Broker from file: " + file); 067 factory.setResource(new FileSystemResource(file)); 068 } 069 070 IdGenerator idgen = new IdGenerator(); 071 BrokerContainer container = factory.createBrokerContainer(idgen.generateId(), BrokerContext.getInstance()); 072 container.start(); 073 074 // lets wait until we're killed. 075 Object lock = new Object(); 076 synchronized (lock) { 077 lock.wait(); 078 } 079 } 080 catch (JMSException e) { 081 System.out.println("Caught: " + e); 082 e.printStackTrace(); 083 Exception le = e.getLinkedException(); 084 System.out.println("Reason: " + le); 085 if (le != null) { 086 le.printStackTrace(); 087 } 088 } 089 catch (Exception e) { 090 System.out.println("Caught: " + e); 091 e.printStackTrace(); 092 } 093 } 094 }