将非jar文件添加到Java类路径 [英] Adding a non-jar file to the Java class path
本文介绍了将非jar文件添加到Java类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过类路径为我的应用程序提供.txt文件。在我的启动脚本中 - 它与.txt文件位于同一文件夹中 - 我设置了以下内容:
I'm trying to make a .txt file available to my application via the class path. In my startup script--which is co-located in the same folder as the .txt file--I've set the following:
设置CLASSPATH =%CLASSPATH% ;%CD%\sample.txt
java -classpath%CD%\ _sample.txt
set CLASSPATH=%CLASSPATH%;%CD%\sample.txt java -classpath %CD%\sample.txt
在我的应用程序中,我尝试了以下方法:
In my application, I've tried the following:
- getClass()。getResource(sample.txt)
- getClass()。getResource (/sample.txt)
- getClass()。getResource(classpath:sample.txt)
以上工作均不适用。任何帮助将不胜感激。
None of the above work. Any help would be appreciated.
推荐答案
您必须在jar中包装txt文件或将其放在类路径中包含的目录中。
You must pack you txt file inside jar or place it in directory included in classpath.
这篇关于将非jar文件添加到Java类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文