Searches the class path for implementations of the given type, returning a list of all plugins that were found Note: If you want to load JARs dynamically, you need to call #loadJAR or #loadJARs methods with the proper file or directory first, otherwise this will only searc
(final Class<T> type)
| 134 | * instantiated |
| 135 | */ |
| 136 | public static <T> List<T> loadPlugins(final Class<T> type) { |
| 137 | ServiceLoader<T> serviceLoader = ServiceLoader.load(type); |
| 138 | Iterator<T> it = serviceLoader.iterator(); |
| 139 | if (!it.hasNext()) { |
| 140 | LOG.warn("Unable to locate any plugins of the type: " + type.getName()); |
| 141 | return null; |
| 142 | } |
| 143 | |
| 144 | ArrayList<T> plugins = new ArrayList<T>(); |
| 145 | while(it.hasNext()) { |
| 146 | plugins.add(it.next()); |
| 147 | } |
| 148 | if (plugins.size() > 0) { |
| 149 | return plugins; |
| 150 | } |
| 151 | |
| 152 | LOG.warn("Unable to locate plugins for type: " + type.getName()); |
| 153 | return null; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Attempts to load the given jar into the class path |