package org.b3log.latke;
public class testEVN {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Latkes.initRuntimeEnv();
System.out.println(Latkes.getRuntimeEnv());
}
}
输出:
七月 15, 2013 7:55:52 上午 org.b3log.latke.Latkes initRuntimeEnv
INFO: Latke is running on [LOCAL] with mode [DEVELOPMENT]
七月 15, 2013 7:55:53 上午 org.b3log.latke.Latkes initRuntimeEnv
INFO: Runtime database is [MYSQL]
LOCAL
latke.properties:
# Configures the followings before deploy
serverScheme=http
serverHost=localhost
serverPort=8080
staticServerScheme=http
staticServerHost=localhost
staticServerPort=8080
# Note: The context path and static path should be "" if deploy app on ROOT. For other cases, starts with '/'
# and not ends with '/', for example, /blog
contextPath=
staticPath=
#### Runtime Environment ####
runtimeEnv=LOCAL
#### Runtime Mode ####
runtimeMode=DEVELOPMENT
#runtimeMode=PRODUCTION
#### Cache Implementation ####
# Note: If the runtime environment is LOCAL, the cache will be 'LOCAL' always
cache=LOCAL
#### User Service Implementation ####
userService=LOCAL
#### Cache ####
cache.maxPageCnt=128
cache.maxDataCnt=128
#### Static resource version ####
staticResourceVersion=201211021410
public final class Latkes {
/**
* Latke configurations (latke.properties).
*/
private static final Properties LATKE_PROPS = new Properties();
try {
final InputStream resourceAsStream = Latkes.class.getResourceAsStream("/local.properties");
public static void initRuntimeEnv() {
LOGGER.log(Level.FINEST, "Initializes runtime environment from configuration file");
final String runtimeEnvValue = LATKE_PROPS.getProperty("runtimeEnv");
if (null != runtimeEnvValue) {
runtimeEnv = RuntimeEnv.valueOf(runtimeEnvValue);
}
if (null == runtimeEnv) {
LOGGER.log(Level.FINEST, "Initializes runtime environment by class loading");
try {
runtimeEnv = RuntimeEnv.GAE;
Class.forName("org.b3log.latke.repository.gae.GAERepository");
} catch (final ClassNotFoundException e) {
runtimeEnv = RuntimeEnv.LOCAL;
}
}
final String runtimeModeValue = LATKE_PROPS.getProperty("runtimeMode");
if (null != runtimeModeValue) {
runtimeMode = RuntimeMode.valueOf(runtimeModeValue);
} else {
LOGGER.log(Level.FINEST, "Can't parse runtime mode in latke.properties, default to [DEVELOPMENT]");
runtimeMode = RuntimeMode.DEVELOPMENT;
}
LOGGER.log(Level.INFO, "Latke is running on [{0}] with mode [{1}]", new Object[] {Latkes.getRuntimeEnv(), Latkes.getRuntimeMode()});
if (RuntimeEnv.LOCAL == runtimeEnv) {
// Read local database configurations
final RuntimeDatabase runtimeDatabase = getRuntimeDatabase();
LOGGER.log(Level.INFO, "Runtime database is [{0}]", runtimeDatabase);
if (RuntimeDatabase.H2 == runtimeDatabase) {
final String newTCPServer = Latkes.getLocalProperty("newTCPServer");
if ("true".equals(newTCPServer)) {
LOGGER.log(Level.INFO, "Starting H2 TCP server");
final String jdbcURL = Latkes.getLocalProperty("jdbc.URL");
if (Strings.isEmptyOrNull(jdbcURL)) {
throw new IllegalStateException("The jdbc.URL in local.properties is required");
}
final String[] parts = jdbcURL.split(":");
if (parts.length != Integer.valueOf("5")/* CheckStyle.... */) {
throw new IllegalStateException("jdbc.URL should like [jdbc:h2:tcp://localhost:8250/~/] (the port part is required)");
}
String port = parts[parts.length - 1];
port = StringUtils.substringBefore(port, "/");
LOGGER.log(Level.FINEST, "H2 TCP port [{0}]", port);
try {
h2 = Server.createTcpServer(new String[] {"-tcpPort", port, "-tcpAllowOthers"}).start();
} catch (final SQLException e) {
final String msg = "H2 TCP server create failed";
LOGGER.log(Level.SEVERE, msg, e);
throw new IllegalStateException(msg);
}
LOGGER.info("Started H2 TCP server");
}
}
}
locale = new Locale("en_US");
}
源代码:http://pan.baidu.com/share/link?shareid=1644033861&uk=3878681452