2015-01-20 2 views
0

스프링 도구 모음 내에서 실행 가능한 jar를 처음으로 만들려고합니다. 나는 내보내기 기능을 사용하여 jar 파일을 생성하지만 실행하면, 다음과 같은 오류 얻을 : 나는 몇 가지 제안 된 솔루션을 여기에 소스 폴더에, 심지어 내가 그 짓을하더라도 파일을 배치 참조 발견스프링 도구 모음 실행 가능한 jar 오류 생성 구성 파일 찾기

java.io.FileNotFoundException: config.properties (The system cannot find 
the file specified) 

을 , 여전히 파일을 볼 수 없습니다. 심지어 여러 위치에 놓기를 원하기도했습니다. 여기

enter image description here

나는 파일을 읽을 수있는 클래스를 호출 오전 :

public static void main(String[] args) { 
    // TODO Auto-generated method stub 
     System.out.println("GETTING CONFIG PROPERTIES FILE..."); 
     configuration.readConfig(); 

.... 
public static void readConfig() { 

    Properties fileProp = new Properties(); 
    try { 

     //OutputStream output = null; 
     URL url1 = configuration.class. 
       getClassLoader().getResource("config.properties"); 
     File f = new File(url1.getFile()); 
     FileReader rd = new FileReader(f.getPath()); 

     //InputStream infile = new FileInputStream("config.properties"); 
     fileProp.load(rd); 

편집 :

슬래시를 삽입하여 파일 이름 경로에 변화를 제작하지만 그렇지 않은 것 같다 파일을 찾을 수 있습니다 :

LOADING CONFIG PROPERTIES FILE... 
Exception in thread "main" java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.eclipse.jdt.internal.jarinjarloader. 
    JarRsrcLoader.main(JarRsrcLoader.java:58) 
    Caused by: java.lang.NullPointerException 
    at com.ccccc.hbasededuper. 
    configuration.readConfig(configuration.java:48) 
    at com.ccccc.hbasededuper.HBaseMain.main(HBaseMain.java:144) 
    ... 5 more 

그 줄의 코드 이런 경우가 발생합니다 :

 URL url1 = configuration.class.getClassLoader(). 
     getResource("/config.properties"); 

     System.out.println("LOADING CONFIG PROPERTIES FILE..."); 

     File f = new File(url1.getFile()); 
     FileReader rd = new FileReader(f.getPath()); 

오류는 url1.getFile로 발생합니다.

edit2 :

실례; 문제는 제가 속성 파일을 읽는 방식이었습니다.

fileprop.load(ClassLoader.getSystemResourceAsStream("config.properties")) 

답변

1

내가 원하는 사람이 SRC/메인/자원의 하나라고 확신하고, '/'

configuration.class.getClassLoader().getResources("/config.properties") 

주를 통해 참조 할 수 있습니다. 다음

+0

감사를 만든 것입니다. 문제는 디버깅이 "/"없이 작동하지만 항아리 생성을 위해 삽입하면 문제가 발생했습니다. 지금 처리 할 다른 오류가 있습니다. 당신의 도움을 주셔서 감사합니다. – vbNewbie

+0

그것을 돌렸다, 그것은 여전히 ​​파일을 읽지 않고 있었지만 당신의 제안은 그것을 디버깅하는데 도움이되었다. – vbNewbie

0

의 차이와 SRC에서 설정 파일을 유지/주/자원

fileProp.load(configuration.class. 
     getClassLoader().getResourceAsStream("config.properties"));