1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support;
14
15 import hermes.JAXBHermesLoader;
16
17 import java.io.File;
18 import java.io.IOException;
19 import java.lang.reflect.Method;
20 import java.net.URL;
21 import java.net.URLClassLoader;
22
23 import com.eviware.soapui.SoapUI;
24
25 public class HermesJMSClasspathHacker
26 {
27
28 private static final Class<?>[] parameters = new Class[] { URL.class };
29
30 public static void addFile( String s ) throws IOException
31 {
32 File f = new File( s );
33 addFile( f );
34 }
35
36 public static void addFile( File f ) throws IOException
37 {
38 addURL( f.toURI().toURL() );
39 }
40
41 public static void addURL( URL u ) throws IOException
42 {
43
44 try
45 {
46 ClassLoader classLoader = JAXBHermesLoader.class.getClassLoader();
47 if( !( classLoader instanceof URLClassLoader ) )
48 {
49 SoapUI.log.error( "SoapUI classloader is not an URLClassLoader, failed to add external library" );
50 return;
51 }
52
53 URLClassLoader sysloader = ( URLClassLoader )classLoader;
54 Class<URLClassLoader> sysclass = URLClassLoader.class;
55 Method method = sysclass.getDeclaredMethod( "addURL", parameters );
56 method.setAccessible( true );
57 method.invoke( sysloader, new Object[] { u } );
58
59 SoapUI.log.info( "Added [" + u.toString() + "] to classpath" );
60
61 }
62 catch( Throwable t )
63 {
64 SoapUI.logError( t );
65 throw new IOException( "Error, could not add URL to system classloader" );
66 }
67
68 }
69
70 }