storm topology all in one spring文件合并
程序员文章站
2022-05-22 09:44:45
...
storm生成topology all in one的jar包时,如果是spring环境,就会出现问题,各种资源文件无法找到,写了个工具方法,合并并生成这些资源文件:
public class MergeMetaInf { public static void main(String[] args) throws IOException, URISyntaxException { File metaInfDir = new File("src/main/resources"); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); for (String name : new String[] {"META-INF/spring.factories", "META-INF/spring.handlers", "META-INF/spring.schemas", "META-INF/spring.tooling"}) { File file = new File(metaInfDir, name); if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); try (OutputStream out = new FileOutputStream(file)) { for (Enumeration<URL> iter = classLoader.getResources(name); iter.hasMoreElements();) { URL url = iter.nextElement(); if (!url.getProtocol().equals("file")) { UtilIO.write(url.openStream(), out); out.write('\n'); } } } } } }