📄 props.java
字号:
package com.wls8unleashed.jms;
import java.util.*;
import java.io.*;
import javax.naming.*;
/**
* Properties file helper. Helps read values from
* properties file easily.
*/
public class Props {
// The build.properties file name used with the examples.
private static String FILE_NAME = "build.properties";
private static Properties props = null;
/**
* Get an instance of the build.properties file.
*/
private static void getInstance(){
props = new Properties();
try{
props.load(new FileInputStream(FILE_NAME));
}
catch(IOException e){
System.out.println("PROBLEM FINDING FILE NAME "
+ FILE_NAME + " ... EXITING ...");
System.exit(1);
}
}
/**
* Return a property value given a name and create
* properties file handle if doesn't already exist.
*/
public static String get(String name){
if(props == null){
getInstance();
}
return (String) props.get(name);
}
/**
* Construct a JNDI initial context from the
* properties file info.
*/
public static Context getInitialContext(){
Context ctx = null;
// Get properties for naming service
String jndiFactory = Props.get("jndi.factory");
String providerURL = Props.get("jndi.provider.url");
// Create hashtable of JNDI properties
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, jndiFactory);
env.put(Context.PROVIDER_URL, providerURL);
// Return handle to JNDI context
try{
ctx = new InitialContext(env);
}
catch(Exception e){
System.out.println("PROBLEM CREATING JNDI CONTEXT...EXITING...");
System.exit(1);
}
return ctx;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -