logo
down
shadow

Using javax.tools.ToolProvider from a custom classloader?


Using javax.tools.ToolProvider from a custom classloader?

By : SpeedKnight
Date : October 26 2020, 11:51 AM
help you fix your problem I had exactly the same problem. I'm using a custom ant task to scan the AST for certain kinds of method invocations. My solution, which may not be appropriate for you, was to instantiate the compiler myself instead of using the ToolProvider.
I replaced
code :


Share : facebook icon twitter icon
Compiling classes with Toolprovider and loading them with ClassLoader

Compiling classes with Toolprovider and loading them with ClassLoader


By : user3458489
Date : March 29 2020, 07:55 AM
this one helps. Your last attempt should work. myUrl should refer to the directory (or Jar) containing the .class generated.
code :
myUrl = new URL("file:///myGeneratedCode/");
How to find classloader leak with free tools?

How to find classloader leak with free tools?


By : J Skinner
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can use the evaluation version of JProfiler to investigate the class loader leak. Go to the class loader probe, select one of the leaking class loaders and show them in the heap walker where you can investigate strong references to the classes that were loaded by the class loader.
There is a screen cast that shows you how to do this.
Intercepting ClassLoader.getResource(String) calls, with a custom ClassLoader

Intercepting ClassLoader.getResource(String) calls, with a custom ClassLoader


By : Jasmine Jackson
Date : March 29 2020, 07:55 AM
seems to work fine Yes. This works, in principal.
However, you've to account how the resource loading code get's to the class loader. Since the class don't show up, it looks like they use the parents class loader. You've to account different scenarios:
code :
Thread.currentThread().getContextClassLoader().getResource("via-context");
Thread.currentThread().setContextClassLoader(loader);
Method main = realAppClasss.getMethod("main", String[].class);
main.invoke(null, (Object) args);
MyRealAppClass.class.getResource("via-class");
MyRealAppClass.class.getClassLoader().getResource("via-class");
objectInfApp.getClass().getClassLoader().getResource("via-class");
// URL class loader to lookup in jars etc
private static class MyClassLoader extends URLClassLoader
{
    public MyClassLoader(URL[] urls) {
        // Use the given URLs and skip any parent class loader, directly go to the system loader
        super(urls,null);
    }

// ...

// Then setup the class path
    String[] classPath = System.getProperty("java.class.path").split(";");
    URL[] classPathUrls = new URL[classPath.length];
    for (int i = 0; i < classPath.length; i++) {
        classPathUrls[i] = new File(classPath[i]).toURL();

    }
    MyClassLoader loader = new MyClassLoader(classPathUrls);
How do I use JDK6 ToolProvider and JavaCompiler with the context classloader?

How do I use JDK6 ToolProvider and JavaCompiler with the context classloader?


By : user3742842
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further If you know the classpath to the files that are known to the contextclassloader you can pass them to the compiler:
Java Class cast exception, Classloader error on using javax xml providers?

Java Class cast exception, Classloader error on using javax xml providers?


By : Antony Raja
Date : March 29 2020, 07:55 AM
With these it helps You may need to set -Dorg.osgi.framework.bootdelegation=com.sun.*. See https://osgi.org/specification/osgi.core/7.0.0/framework.module.html#framework.module.parentdelegation. It is possible Equinox provides a common, useful default for boot delegation while Karaf does not.
Related Posts Related Posts :
  • Android Spinner nullpointer
  • Add result to int array every time you finish counting the occurrence
  • Android import java library
  • How to use LDAP Authentication in a corporate environment
  • adding item during iteration in java special usecase
  • How can I sort a map with string key? like (1 foo , 2 foo)
  • How to test an implementation of TLS based on SSLEngine?
  • Sorting a Linked List in alphabetical order
  • Can't make more than one request on java.net.http.HttpClient or will receive: javax.net.ssl.SSLHandshakeException
  • Java logic - strange things happening in while loop
  • Unable to replicate an encryption method from Java to PHP using AES/ECB/PKCS5Padding
  • How program arithmetics on general objects which become defined only later?
  • Make asynchronous call synchronous in Kotlin
  • Thread Pool with Spring @Value for Pool size doesnt run properly
  • How to substring before nth occurence of a separator?
  • Resume S3 multipart upload: PartETag
  • Mutable fields should not be "public static"
  • How to remove fragment from URI
  • Add a node in xml using java only if the node has an attribute
  • java streams: elegant way to filter according an exception is thrown
  • Exception in thread, java code wont execute properly. If/else statments
  • using the same UI instance inside access method
  • Single Linked List in reverse order Java
  • Is there a java api that will identify the ipv6 address fd00:: as local/private?
  • Clear a cache with JSR-107 annotations
  • Store data from an array for later comparison
  • Why BufferedWriter here is not writing to the file even though I close it in the end?
  • Three methods to search: name; name and surname; and age in an array
  • When do I have to create new instance while using @Autowired
  • ArrayList public constructor - "Constructs an empty list with an initial capacity of ten" - where?
  • How to make assignable, number-like class in Java?
  • How to make a query in Firebase similar to a SQL query?
  • How to inflate SupportActionBar menu from outside Activity
  • Is it good practice using two navigation (component architecture) in the same app?
  • Can a method annotation handle errors thrown by this method?
  • How does the javadoc know which method each documentation comment is for?
  • Refactoring/moving java package between intellij projects
  • Why lists pksc11-tool seven Objects but Java Keystore has Only one
  • How to update an entity with an element-collection of type Map<String,String>?
  • How to solve a "1 producer 2 consumers" problem in java
  • java selenium - Nav to a page number not shown on a Paginated Table
  • Add dependecies to runtime image with Gradle
  • How to reload application.properties in runtime which is not part of jar
  • How to stream, in java, over a key->collection map, where each streamed element is the key and every element in the c
  • Android Listview - Load each row on thread
  • Vaadin: value from DateField is null after conversion
  • Payara 5 compatibility with Java 9
  • Deleting an item from RecyclerView + SQLite
  • Calling a function when an activity is returned to from fragment
  • Functions with different signatures, but the same body
  • How to check which installed JDK used during Gradle build process
  • Creating a reusable class
  • What does static in front of nested interface mean?
  • ByteBuffer Missing Data When decoded As string
  • How to remove Handler from adapter
  • Sort only even numbers in array and do not touch odds
  • Simple Todo android app with mlab dont add or edit
  • Type inference seems to fail vavr's Try works on jOOQ's fetchOne() function
  • Google Dataflow "No filesystem found for scheme gs"
  • Sort file based on date in file name
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org