2012-12-17 4 views
1

일부 봄 콩을 포함하는 hadoop 작업이 있습니다. 또한 스프링 컨텍스트 파일에는 app.properties라는 PropertyPlaceholderConfigurer가 있습니다.Hadoop에서 외부 속성 파일을로드하는 방법

이 app.properties는 jar 파일 내에 있습니다. 다시 컴파일하지 않고 일부 속성을 변경하려면 jar 파일에서 제거하십시오.

-file 옵션을 시도했지만 -jarlibs 옵션을 시도했지만 어느 것도 작동하지 않았습니다.

아이디어가 있으십니까? 다음과 같이

답변

2

했다 :

  • 서브 클래스 PropertyPlaceholderConfigurer와
  • 무시 loadProperties 방법
  • 사용자 지정은 System.getProperty ("hdfs_path")

    try { 
         Path pt = new Path(hdfsLocationPath); 
         FileSystem fs = FileSystem.get(new Configuration()); 
         BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt))); 
         props.load(br); 
        } catch (Exception e) { 
         LOG.error(e); 
        } 
    
가있는 경우

은 매력처럼 작동합니다 ...

1

당신은이 속성이 분산 캐시에 파일을 추가 할 수 있습니다

... 
Path s3PropertiesFilePath; 
Properties prop = new Properties(); 
@Override 
public void configure(JobConf job) { 
    s3PropertiesFilePath = DistributedCache.getLocalCacheFiles(job)[0]; 
    //load the properties file 
    prop.load(new FileInputStream(s3PropertiesFilePath.toString())); 
... 
} 

:

... 
String s3PropertiesFilePath = args[0]; 
DistributedCache.addCacheFile(new URI(s3PropertiesFilePath), conf); 
... 

나중에 구성에서() 당신의 매퍼/감속기, 당신은 다음과 같은 작업을 수행 할 수 PS : Amazon EMR에서 실행하지 않는 경우 hdfs에서이 등록 정보 파일을 유지하고 대신 해당 경로를 제공 할 수 있습니다. 내가 무슨 짓을

+0

좋습니다.하지만 app.properties 원본을 대체해야했습니다. 이 방법을 사용하면 app.properties (external | internal)와 app.properties (external | internal) 사이를 전환 할 수있는 사용자 정의 PropertyPlaceHolder를 만들어야합니다. 어쨌든 고마워요. – psabbate

관련 문제