1 /***
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.codehaus.activemq.spring;
19
20 import org.codehaus.activemq.broker.BrokerContainer;
21 import org.codehaus.activemq.broker.BrokerContext;
22 import org.springframework.core.io.ClassPathResource;
23 import org.springframework.core.io.FileSystemResource;
24
25 import javax.jms.JMSException;
26
27 /***
28 * A simple command line tool which runs a JMS Message Broker on the command line
29 * using a Spring XML deployment descriptor
30 *
31 * @version $Revision: 1.4 $
32 */
33 public class Main {
34
35 /***
36 * run the Message Broker as a standalone application
37 *
38 * @param args
39 */
40 public static void main(String args[]) {
41 try {
42 String version = "";
43 Package p = Package.getPackage("org.codehaus.activemq");
44 if (p != null) {
45 version = ": " + p.getImplementationVersion();
46 }
47 System.out.println("ActiveMQ Message Broker" + version);
48 System.out.println();
49
50 SpringBrokerContainerFactory factory = new SpringBrokerContainerFactory();
51 String file = null;
52 if (args.length <= 0) {
53 System.out.println("Loading Mesaage Broker from activemq.xml on the CLASSPATH");
54 factory.setResource(new ClassPathResource("activemq.xml"));
55 }
56 else {
57 file = args[0];
58
59 if (file.equals("-?") || file.equals("?") || file.equals("--help") || file.equals("-h")) {
60 System.out.println("Usage: Main [xmlConfigFile]");
61 System.out.println("If an XML config file is not specified then activemq.xml is used from the CLASSPAHT");
62 return;
63 }
64
65 System.out.println("Loading Message Broker from file: " + file);
66 factory.setResource(new FileSystemResource(file));
67 }
68
69
70 BrokerContainer container = factory.createBrokerContainer("DefaultBroker", BrokerContext.getInstance());
71 container.start();
72
73
74 Object lock = new Object();
75 synchronized (lock) {
76 lock.wait();
77 }
78 }
79 catch (JMSException e) {
80 System.out.println("Caught: " + e);
81 e.printStackTrace();
82 Exception le = e.getLinkedException();
83 System.out.println("Reason: " + le);
84 if (le != null) {
85 le.printStackTrace();
86 }
87 }
88 catch (Exception e) {
89 System.out.println("Caught: " + e);
90 e.printStackTrace();
91 }
92 }
93 }