簡體   English   中英

Java二進制文件未從指定的類路徑中獲取資源

[英]Java binary not picking up resources from the specified class path

我正在嘗試將文本文件作為InputStream加載,但是txt文件從未被拾取,並且輸入流的值始終為null 我不知道為什么會這樣,我想尋求幫助。

nohup java  -jar crawler-jar-2014.11.0-SNAPSHOT.jar -classpath /home/nbsxlwa/crawler/resources/common-conf:/home/nbsxlwa/crawler/resources/dotcom-conf:./plugins/*:./lib/* & 

txt文件位於/home/nbsxlwa/crawler/resources/dotcom-conf目錄中。 我可以確認該文件確實存在,所以我不知道為什么未提取該文件。 設置如下:

  1. `System.getEnvironment( “java.class.path”)

    返回以下值crawler-jar-2014.11.0-SNAPSHOT.jar

  2. 代碼塊正在嘗試創建文本輸入流。

  String fileRules = conf.get(URLFILTER_REGEX_FILE); System.out.println("file rules = " + fileRules); // Pass the file as a resource in classpath. // return conf.getConfResourceAsReader(fileRules); // Pass the file as a resource in classpath. InputStream is = RegexURLFilter.class.getResourceAsStream("/" + fileRules); System.out.println("Inputstream is = " + is); System.out.println(ClassLoader.getSystemResourceAsStream(fileRules)); 

以上代碼段的輸出是

file rules = regex-urlfilter.txt
Inputstream is = null
null
  1. 我嘗試將類路徑文件夾添加到類路徑MANIFEST.MF文件中。 MANIFEST.MF包含以下條目,但輸出仍返回null

類路徑:資源/ common-conf資源/ dotcom-conf資源/ olb-conf lib / gora-cassandra-0.3.jar **其他JARS **

注意-jarjava手冊頁條目

使用此選項時,JAR文件是所有用戶類的源,而其他用戶類路徑設置將被忽略。

因此,其他類路徑條目將被忽略。 您將必須使用普通的舊java命令,使用main方法指定一個類,並將.jar包含在類路徑中。

您在清單中指定的相對路徑是相對於JAR本身還是完整的URL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM