简体   繁体   English

从JVM外部访问捆绑的Java文件

[英]Access bundled Java file from outside the JVM

Is it possible to access a bundled Java file from outside the JVM? 是否可以从JVM外部访问捆绑的Java文件? My particular issue is that I have Ruby scripts bundled with my application that I need to execute from the command line. 我的特殊问题是我的应用程序捆绑了Ruby脚本,需要从命令行执行。

The Ruby scripts are located at src/main/resources, and to execute them I am using a third party exe in Windows where the final command looks something like: custom_ruby.exe -script PATH_TO_SCRIPT Ruby脚本位于src / main / resources,要执行它们,我在Windows中使用第三方exe,其最终命令类似于:custom_ruby.exe -script PATH_TO_SCRIPT

So, I need to get a file system path to a bundled Java resource. 因此,我需要获取绑定的Java资源的文件系统路径。 Is this even possible? 这有可能吗? If not I am planning to read the Ruby Script in Java, and simply write it to a temp directory. 如果不是,我打算阅读Java中的Ruby脚本,然后将其写入临时目录。 If there is a more elegant solution I'd like to know. 如果有更优雅的解决方案,我想知道。

Thanks. 谢谢。

You are looking for Class.getResource() and Class.getResourceAsStream() . 您正在寻找Class.getResource()Class.getResourceAsStream() Checkout an example here . 在此处签出示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM