-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Main.java
117 lines (113 loc) · 3.43 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.management;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
class Main
{
private static final String JCONSOLE = "sun.tools.jconsole.JConsole";
private Main()
{
// no instances
}
public static void main( String[] args ) throws Throwable
{
Throwable failure = null;
Class<?> jconsole = null;
try
{
jconsole = Class.forName( JCONSOLE );
}
catch ( ClassNotFoundException ex )
{
File jar = new File( new File( System.getProperty( "java.home" ), "lib" ), "jconsole.jar" );
if ( !jar.exists() )
{
jar = new File( new File( new File( System.getProperty( "java.home" ) ).getParentFile(), "lib" ),
"jconsole.jar" );
}
ClassLoader loader = null;
if ( jar.exists() )
{
try
{
loader = new URLClassLoader( new URL[] { jar.toURI().toURL() }, Main.class.getClassLoader() );
}
catch ( MalformedURLException e )
{
// Handled by null check
}
}
if ( loader == null )
{
System.err.println( "Could not find jconsole.jar" );
return;
}
try
{
jconsole = loader.loadClass( JCONSOLE );
}
catch ( ClassNotFoundException e )
{
failure = ex;
}
}
Method main = null;
if ( jconsole != null )
{
try
{
main = jconsole.getDeclaredMethod( "main", String[].class );
}
catch ( Exception ex )
{
failure = ex;
}
}
if ( main != null )
{
try
{
main.invoke( null, new Object[] { args } );
return;
}
catch ( InvocationTargetException e )
{
throw e.getTargetException();
}
catch ( Exception ex )
{
failure = ex;
}
}
if ( failure != null )
{
System.err.println( "Failed to launch jconsole: " + failure );
if ( !( failure instanceof ClassNotFoundException ) )
{
failure.printStackTrace();
}
}
}
}