How to use regular expression in java manifest classpath?

[亡魂溺海] 提交于 2019-11-28 07:39:33

问题


I need to make use of additional jars during the execution of the program. I manually add the jars to the relative ./lib folder and then execute the program. How should I define the classpath in the manifest file?


回答1:


You can't use regular expressions or other wildcards in the Class-Path attribute of your manifest.

There is only one supported wildcard in Java, and that only works on if specified on the commandline on a "manual" java invocation (i.e. not using -jar): using directoryname/*.




回答2:


I'm not all too sure about what you want exactly, but you can add jars during runtime:

  • list (jar) files using File.list() on the directory containing the jars
  • do a regex on the filenames you retrieve
  • use an URLClassLoader to load the jar

I don't know exactly how to register (if necessary) the URLClassLoaders to the main classloader. But that's the way I think I would go.



来源:https://stackoverflow.com/questions/4756736/how-to-use-regular-expression-in-java-manifest-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!