Source Code Cross Referenced for JavaRunner.java in  » Testing » jumble » com » reeltwo » jumble » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jumble » com.reeltwo.jumble.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.reeltwo.jumble.util;
002:
003:        import java.io.IOException;
004:        import java.util.Properties;
005:
006:        /**
007:         * Class to run a java process with the same settings as this JRE.
008:         * 
009:         * @author Tin Pavlinic
010:         * @version $Revision: 516 $
011:         */
012:        public class JavaRunner {
013:
014:            private final String mJvmBin;
015:
016:            private String mClassName;
017:
018:            private String[] mArgs;
019:
020:            private String[] mJvmArgs;
021:
022:            /**
023:             * Constructor.
024:             * 
025:             * @param className
026:             *          The name of the class to run
027:             */
028:            public JavaRunner(String className) {
029:                this (className, new String[0]);
030:            }
031:
032:            /**
033:             * Constructor
034:             * 
035:             * @param className
036:             *          of the class to run
037:             * @param arguments
038:             *          the arguments to pass to the main method.
039:             */
040:            public JavaRunner(String className, String[] arguments) {
041:                mClassName = className;
042:                mArgs = arguments;
043:
044:                Properties props = System.getProperties();
045:                String ls = props.getProperty("file.separator");
046:                mJvmBin = props.getProperty("java.home") + ls + "bin" + ls
047:                        + "java";
048:                final int initialLength = (JumbleUtils.isAssertionsEnabled() ? 3
049:                        : 2);
050:
051:                mJvmArgs = new String[initialLength];
052:                mJvmArgs[0] = "-cp";
053:                mJvmArgs[1] = props.getProperty("java.class.path");
054:                if (JumbleUtils.isAssertionsEnabled()) {
055:                    mJvmArgs[2] = "-ea";
056:                }
057:            }
058:
059:            /**
060:             * Gets the name of the class to run
061:             * 
062:             * @return the class name
063:             */
064:            public String getClassName() {
065:                return mClassName;
066:            }
067:
068:            /**
069:             * Sets the class to run
070:             * 
071:             * @param newName
072:             *          name of the new class to run. Must contain a main method.
073:             */
074:            public void setClassName(String newName) {
075:                mClassName = newName;
076:            }
077:
078:            /**
079:             * Gets the arguments to pass to the JVM.
080:             * 
081:             * @return the arguments
082:             */
083:            public String[] getJvmArguments() {
084:                return mJvmArgs;
085:            }
086:
087:            /**
088:             * Sets the arguments to pass to the JVM. The default JVM arguments includes
089:             * the classpath for the JVM to use, so if you supply new JVM arguments, you
090:             * should probably include classpath settings.
091:             * 
092:             * @param args
093:             *          the new arguments.
094:             */
095:            public void setJvmArguments(String[] args) {
096:                mJvmArgs = args;
097:            }
098:
099:            /**
100:             * Gets the arguments to pass to the main method
101:             * 
102:             * @return the arguments
103:             */
104:            public String[] getArguments() {
105:                return mArgs;
106:            }
107:
108:            /**
109:             * Sets the arguments to pass to the main method
110:             * 
111:             * @param args
112:             *          the new arguments.
113:             */
114:            public void setArguments(String[] args) {
115:                mArgs = args;
116:            }
117:
118:            /**
119:             * Starts the java process.
120:             * 
121:             * @return the running java process
122:             * @throws IOException
123:             *           if something goes wrong.
124:             */
125:            public Process start() throws IOException {
126:                String[] command = getExecArgs();
127:                //System.err.println(toString(command));
128:                return Runtime.getRuntime().exec(command);
129:            }
130:
131:            /**
132:             * Creates the actual arguments used to start the process. This incorporates
133:             * the user-supplied arguments plus the explicit location of the JVM, and the
134:             * classpath to supply.
135:             * 
136:             * @return a <code>String[]</code> value
137:             */
138:            private String[] getExecArgs() {
139:                final int baseArgs = 2 + (mJvmArgs == null ? 0
140:                        : mJvmArgs.length);
141:
142:                // create the java command
143:                String[] command = new String[baseArgs + getArguments().length];
144:                int idx = 0;
145:                command[idx++] = mJvmBin;
146:                if (mJvmArgs != null) {
147:                    for (int i = 0; i < mJvmArgs.length; i++) {
148:                        command[idx++] = mJvmArgs[i];
149:                    }
150:                }
151:                command[idx++] = getClassName();
152:                for (int i = 0; i < getArguments().length; i++) {
153:                    command[idx++] = getArguments()[i];
154:                }
155:                return command;
156:            }
157:
158:            private String toString(String[] command) {
159:                StringBuffer sb = new StringBuffer();
160:                for (int i = 0; i < command.length; i++) {
161:                    if (i != 0) {
162:                        sb.append(' ');
163:                    }
164:                    sb.append(command[i]);
165:                }
166:                return sb.toString();
167:            }
168:
169:            public String toString() {
170:                return toString(getExecArgs());
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.