2013-03-21 2 views
-1

경로를 호출하는 XML이 있으며 위치는 하드 코딩되어 있습니다.xml의 .properties에서 경로를 호출합니다.

누구든지 .properties를 사용하여 경로에 넣은 다음 거기에서 전화하는 방법을 알고 있습니까? 보안상의 이유로이 작업을 수행하십시오.

<file:inbound-endpoint path="C: ../> 

가이 속성 파일에서로드 할 수 있습니다 다음과 같이 튜토리얼 http://www.mulesoft.org/documentation/display/current/Basic+Studio+Tutorial

인바운드의 경로에 따라

편집

라고?

Properties prop = new Properties(); 
    prop.load(new FileInputStream("C:\\prop.properties")); 
    String path = prop.getProperty("pathname"); 

하지만 당신은 propertie 파일로 하드 코드 경로가 :

+0

더 명확 할 수 있습니까? – abhinav

+0

피스는 샘플 코드를 추가하므로 사용자가 의미하는 바를 더 잘 이해할 수 있습니다. – MemLeak

답변

0

강령 된 .java 것은 그냥 통과 할 수 주요 방법에 대한 arg 로의 경로 :

public static void main(String Args[]){ 
    try { 
     if(Args != null){ 
      if(Args[1] != null){//Load XML or prop File     try{ 
        properties.load(new FileInputStream(Args[1])); 
       }catch(Exception e){ 
        throw new Exception("Error loading PropertieFile: "+Args[1] + " :"+e.getMessage()); 
       } 
      }else{ 
       throw new Exception("No File Found!"); 
      } 
0
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> 
<properties> 
    <comment>Application Configuration</comment> 
    <entry key="data.folder">D:\App\Data</entry> 
    <entry key="jdbc.url">jdbc:mysql://localhost/mydb</entry> 
</properties> 

LoadXmlProperties propertie 파일을로드 할 수

import java.io.FileInputStream; 
import java.util.Properties; 

public class LoadXmlProperties { 
    public static void main(String[] args) { 
     LoadXmlProperties lxp = new LoadXmlProperties(); 
     try { 
      Properties properties = lxp.readProperties(); 
      /* 
      * Display all properties information 
      */ 
      properties.list(System.out); 

      /* 
      * Read the value of data.folder and jdbc.url configuration 
      */ 
      String dataFolder = properties.getProperty("data.folder"); 
      System.out.println("dataFolder = " + dataFolder); 
      String jdbcUrl = properties.getProperty("jdbc.url"); 
      System.out.println("jdbcUrl = " + jdbcUrl); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public Properties readProperties() throws Exception { 
     Properties properties = new Properties(); 
     FileInputStream fis = new FileInputStream("configuration.xml"); 
     properties.loadFromXML(fis); 

     return properties; 
    } 
}