axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/components/compiler Javac.java
Date Tue, 13 Jul 2004 18:40:40 GMT
dims        2004/07/13 11:40:40

  Modified:    java/src/org/apache/axis/components/compiler Javac.java
  Log:
  Make an educated guess on where the tools.jar resides.
  
  Revision  Changes    Path
  1.10      +26 -4     ws-axis/java/src/org/apache/axis/components/compiler/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/components/compiler/Javac.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Javac.java	25 Feb 2004 14:02:31 -0000	1.9
  +++ Javac.java	13 Jul 2004 18:40:40 -0000	1.10
  @@ -33,6 +33,9 @@
   import java.util.List;
   import java.util.NoSuchElementException;
   import java.util.StringTokenizer;
  +import java.net.URL;
  +import java.net.MalformedURLException;
  +import java.net.URLClassLoader;
   
   /**
    * This class wraps the Sun's Javac Compiler.
  @@ -54,9 +57,7 @@
       private boolean modern = false;
   
       public Javac() {
  -
  -        // Use reflection to be able to build on all JDKs
  -        ClassLoader cl = Thread.currentThread().getContextClassLoader();
  +        ClassLoader cl = getClassLoader();
           try {
               ClassUtils.forName(MODERN_CLASS, true, cl);
               modern = true;
  @@ -74,6 +75,26 @@
                   (modern ? MODERN_CLASS : CLASSIC_CLASS)));
       }
   
  +    private ClassLoader getClassLoader() {
  +        // Use reflection to be able to build on all JDKs
  +        ClassLoader cl = Thread.currentThread().getContextClassLoader();
  +
  +        URL toolsURL = null;
  +        String tools = System.getProperty("java.home");
  +        if (tools != null) {
  +            File f = new File(tools + "/../lib/tools.jar");
  +            if (f.exists()) {
  +                try {
  +                    toolsURL = f.toURL();
  +                    cl = new URLClassLoader(new URL[]{toolsURL}, cl);
  +                } catch (MalformedURLException e) {
  +                }
  +            }
  +        }
  +        
  +        return cl;
  +    }
  +
       /**
        * Compile a source file yielding a loadable class file.
        *
  @@ -85,7 +106,8 @@
   
           try {
               // Create an instance of the compiler, redirecting output to err
  -            Class c = ClassUtils.forName("sun.tools.javac.Main");
  +            Class c = ClassUtils.forName("sun.tools.javac.Main", true, getClassLoader());
  +            
               Constructor cons =
                   c.getConstructor(new Class[] { OutputStream.class,
                                                  String.class });
  
  
  

Mime
View raw message