Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a non-jar file to the Java class path

Tags:

java

classpath

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:

set CLASSPATH=%CLASSPATH%;%CD%\sample.txt java -classpath %CD%\sample.txt

In my application, I've tried the following:

  1. getClass().getResource("sample.txt")
  2. getClass().getResource("/sample.txt")
  3. getClass().getResource("classpath:sample.txt")

None of the above work. Any help would be appreciated.

like image 980
Ignatius Avatar asked Jul 20 '11 15:07

Ignatius


2 Answers

You must pack you txt file inside jar or place it in directory included in classpath.

like image 136
Alex Gitelman Avatar answered Oct 23 '22 16:10

Alex Gitelman


You should add to your classpath the directory containing the file, and not the file itself:

set CLASSPATH=%CLASSPATH%;%CD%
like image 41
Eli Acherkan Avatar answered Oct 23 '22 16:10

Eli Acherkan