plugins - Java: Adding classes from external source to classpath -


So my point here is that I am creating a piece of software that is similar to a DOS command line. Except a jar file would like to add other commands, in which a command class is being expanded into a folder I have not tried to do anything.

Here's what I have tried:

  1. Using the Reflections Library to add a jar file for classes while increasing the command class
    It has thrown many errors and did not find most sections in my jar. I think there is something to do with all the SomeClass $ 1.class stuff.
  2. Read again through each file in a jar and add it to the class
    I could not find any way to work for it because I just got to ZipEntry Iterations of can be added to the squares, such as URL.
  3. Adding a whole jar to classpath
    This was not a work because the program will not know the names of these sections, therefore, they can not change these commands.

    I will get some help here. Any suggestions on how I can make my program more extensible will be very welcome. +1 for those people with code;)
    If you need more information just let me know

    Edit:
    New Code:

      URL class loader UCL = (URL class loader) Classloader .getSystemClassLoader (); (File file: filehaller.zet protected file ("/ package /"). Catalog files ()) {if (file.getName (). EndsWith (".jar")) {set < Class & lt ;? & Gt; & Gt; Set = new hashet & lt; Classroom & lt ;? & Gt; & Gt; (); Jarfile jar = null; {Jar = Try new jarfile (file); Calculation & LT; JarEntry & gt; Entries = Ger.Aritz (); While (entries are more prominent elements ()) {Gentry Entry = Entries.NXElment (); If (! Entry.getName (.) Ends (".cloud")) continues; Class & lt ;? & Gt; Clazz; Try {replace claz = ucl.loadClass (entry.getName (). Replace ("/", "."). ("Class", "")); // this lease 71} catches (classicautound expression e) {e.printStackTrace (); to continue; } If (in "entry.getName (.)." ("$ 1") is in progress; If (clazz.getName (). StartWith ("CMD_")) set.add (clazz); Jar.close (); }} Hold (exception e) {// try the undiscovered file {jar.close (); } Hold (IOException e1) {/ * Do not worry too much about it ... * Output Helper.log ("There was an error adding package" + output style. ITILIC + file .getName () + output style DEFAULT + " . "+ E.getMessage () +" Delete package ... ", error); E.printStackTrace (); File.delete (); }   

    Error thrown:

      java.lang.ClassNotFoundException: com.example.MyCommands.CMD_eggtimer at java.net.URLClassLoader $ 1.run ( Unknown source) at java.net.URLClassLoader $ 1.run (unknown source) at java.security.AccessController Java.lang.ClassLoader at sun.mis.Launcher $ AppClassLoader.loadClass (unknown source) on privileged (original method) on java.net.URLClassLoader.findClass (unknown source) at Java.lang.ClassLoader.loadClass. Com.MyWebsite.MyApplication.Commands.CommandList.update (CommandList.java:71)   

    line 71 is mentioned in the code above on the loadClass (unknown source).

    When I need to do this in the past, I used the combination of your points 2 and 3 That is, I add a jar file near the class, and then through it, to list the names of the classes, to list the files and to repeat the class to use. ForName (...) to load them, so I can check if they are the classes I want to process.

    Another option requires classes to be identified in the jar file's manifest, or through any other metadata mechanism.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -