Source Code Cross Referenced for JavaExecutor.java in  » IDE » tIDE » tide » execute » 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 » IDE » tIDE » tide.execute 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tide.execute;
002:
003:        import tide.project.ProjectUtils;
004:        import java.io.*;
005:        import java.util.*;
006:
007:        /** Executes a given class and gobble the output to the execution tab
008:         *  TODO: system.err should NOT be buffered...
009:         */
010:        public final class JavaExecutor {
011:            public final static String JMX_ENABLE_JVM_ARG = "-Dcom.sun.management.jmxremote";
012:
013:            private JavaExecutor() {
014:
015:            } // Constructor
016:
017:            /** Execute the given class.
018:             *  The class must have a static main method to be started.
019:             *  REMARK: the returned process must be gobbled ! and in a very tolerant manner (buffered)
020:             */
021:            public static JProcess executeClass(File sourceBase,
022:                    File javaExecutor, File classesDest, String mainClassName,
023:                    List<File> classPath, String jvmOptions, String appOptions,
024:                    File jpsTool, // use to parse pid for the lsunched java process
025:                    boolean enableRemoteJMXAccess, // add if not already present, but let if present.
026:                    String hprofCommand, boolean launchDebugger)
027:                    throws Exception {
028:                if (!javaExecutor.exists())
029:                    throw new Exception("Java executor no found: "
030:                            + javaExecutor);
031:
032:                List<String> execCommand = new ArrayList<String>();
033:                execCommand.add(javaExecutor.getAbsolutePath());
034:
035:                boolean isEnableRemoteJMXAccessAlreadyPresent = false;
036:                if (jvmOptions != null && jvmOptions.length() > 0) {
037:                    if (jvmOptions.indexOf(JMX_ENABLE_JVM_ARG) >= 0) {
038:                        isEnableRemoteJMXAccessAlreadyPresent = true;
039:                    }
040:                    execCommand.addAll(ProjectUtils
041:                            .splitArgs(jvmOptions, false));
042:                }
043:
044:                boolean isJMXPresent = isEnableRemoteJMXAccessAlreadyPresent;
045:                if (!isJMXPresent && enableRemoteJMXAccess) {
046:                    execCommand.add(JMX_ENABLE_JVM_ARG);
047:                    isJMXPresent = true;
048:                }
049:
050:                if (hprofCommand != null && hprofCommand.length() > 0) {
051:                    execCommand.add(hprofCommand);
052:                }
053:
054:                if (launchDebugger) {
055:                    execCommand
056:                            .add("-agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n");
057:                }
058:
059:                // Classpath
060:                execCommand.add("-classpath");
061:                List<File> cp = new ArrayList<File>();
062:                cp.add(classesDest); // IMPORTANT: the classes are in the CP.
063:
064:                if (classPath != null) {
065:                    cp.addAll(classPath);
066:                }
067:
068:                StringBuilder cpsb = new StringBuilder();
069:                for (int i = 0; i < cp.size(); i++) {
070:                    cpsb.append(cp.get(i).getAbsolutePath());
071:                    if (i < cp.size() - 1)
072:                        cpsb.append(";");
073:                }
074:                execCommand.add(cpsb.toString());
075:
076:                execCommand.add(mainClassName);
077:
078:                if (appOptions != null && appOptions.length() > 0) {
079:                    execCommand.addAll(ProjectUtils
080:                            .splitArgs(appOptions, false));
081:                }
082:
083:                long startTime = System.currentTimeMillis();
084:                // start the process in the sourceBase directory
085:                System.out.println("Execute command " + execCommand);
086:
087:                List<JProcess> jprocessesBefore = null;
088:                if (jpsTool != null) {
089:                    jprocessesBefore = JProcess
090:                            .getAllRunningJavaProcesses(jpsTool);
091:                }
092:
093:                ProcessBuilder pb = new ProcessBuilder(execCommand);
094:                pb.directory(sourceBase);
095:                JProcess jp = JProcess.recognizeRunningProcess(pb.start(),
096:                        mainClassName, isJMXPresent, jprocessesBefore, jpsTool);
097:                return jp;
098:            }
099:
100:            /*test
101:             public static void main(String[] args)
102:             {
103:             try
104:             {
105:             File sourceBase = new File("C:/sources/other/Script/src");
106:
107:             final Vector<File> classPath = new Vector<File>();
108:             classPath.add(new File("C:/Java/jython-2.1/jython.jar"));
109:             classPath.add(new File("C:/Java/jython-2.1/jython.jar;C:/Java/antlr/antlr-2.7.5.jar"));
110:
111:             JProcess proc = executeClass(
112:             sourceBase,
113:             new File(System.getenv("JAVA_HOME"), "bin/java.exe"),
114:             new File("C:/sources/other/Script/classes"),
115:             "script.editor.ScriptEditor",
116:             classPath,
117:             "-Xmx256m",
118:             "",
119:             null, true,
120:             null );
121:
122:             StreamGobbler sg1 = new StreamGobbler(proc.process.getInputStream(), System.out);
123:             sg1.start();
124:             StreamGobbler sg2 = new StreamGobbler(proc.process.getErrorStream(), System.err);
125:             sg2.start();
126:
127:             sg1.join();
128:             sg2.join();
129:             }
130:             catch(Exception e)
131:             {
132:             e.printStackTrace();
133:             }
134:             }*/
135:
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.