Skip to content

Commit

Permalink
java config item complete
Browse files Browse the repository at this point in the history
  • Loading branch information
vintagewang committed Jun 9, 2012
1 parent c3fc38d commit c549c55
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 20 deletions.
29 changes: 26 additions & 3 deletions bin/jwrapper.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
<java>
<debug>true</debug>

<javahome>C:\dummy_java_home</javahome>

<jvmtype>hotspot</jvmtype>

<mainclass>Hello</mainclass>

<properties>
<java.ext.dirs>${cpd}/../lib</java.ext.dirs>
<com.sun.management.jmxremote></com.sun.management.jmxremote>
<com.sun.management.jmxremote.port>9999</com.sun.management.jmxremote.port>
<com.sun.management.jmxremote.authenticate>false</com.sun.management.jmxremote.authenticate>
<com.sun.management.jmxremote.ssl>false</com.sun.management.jmxremote.ssl>
<log4j.configuration>${cpd}/log4j.properties</log4j.configuration>
</properties>

<classpaths>
<cp>cp1</cp>
<cp>cp2</cp>
<cp>cp3</cp>
<path>cp1</path>
<path>cp2</path>
<jars>cp3</jars>
</classpaths>

<options>
<-Xms512m></-Xms512m>
<-Xmx512m></-Xmx512m>
<-XX:NewSize>256M</-XX:NewSize>
<-XX:MaxNewSize>256M</-XX:MaxNewSize>
<-XX:PermSize>128M</-XX:PermSize>
<-XX:MaxPermSize>128M</-XX:MaxPermSize>
</options>
</java>
69 changes: 52 additions & 17 deletions src/JavaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
using namespace boost::property_tree;
using std::string;

JavaConfig::JavaConfig()
#include <iostream>
using std::cout;
using std::endl;

JavaConfig::JavaConfig() : debug(false)
{
}

Expand All @@ -28,29 +32,59 @@ bool JavaConfig::load()
ptree pt;
read_xml(getConfigFile().c_str(), pt);
try {
// java home
// Debug ?
this->debug = pt.get<string>("java.debug") == "true";

// Java Home
const char* jh = getenv("JAVA_HOME");
if(!jh) jh = "";
this->javaHome = pt.get("java.javahome", jh);
if(this->javaHome.empty()) {
fprintf(stderr, "You must set JAVA_HOME environment variable or set it in config file.\n");
return false;
}

// JVM Type
this->jvmType = pt.get<string>("java.jvmtype");

// Main class
// Main Class
this->mainClass = pt.get<string>("java.mainclass");

// Class path
BOOST_AUTO(child, pt.get_child("java.classpaths"));
for(BOOST_AUTO(pos, child.begin());
pos != child.end();
++pos) {
this->classPathList.push_back(pos->second.data());
// Java System Property
{
BOOST_AUTO(child, pt.get_child("java.properties"));
for(BOOST_AUTO(pos, child.begin());
pos != child.end();
++pos) {
this->propertyTable[pos->first.data()] = pos->second.data();
}
}

// Class Path
{
BOOST_AUTO(child, pt.get_child("java.classpaths"));
for(BOOST_AUTO(pos, child.begin());
pos != child.end();
++pos) {
this->classPathList.push_back(pos->second.data());
}
}

// Java Options
{
BOOST_AUTO(child, pt.get_child("java.options"));
for(BOOST_AUTO(pos, child.begin());
pos != child.end();
++pos) {
this->optionTable[pos->first.data()] = pos->second.data();
}
}

} catch(const std::exception& e) {
fprintf(stderr, "%s\n", e.what());
return false;
} catch(...) {
fprintf(stderr, "Unexpected exception.%s\n");
fprintf(stderr, "Unexpected exception.\n");
return false;
}

Expand All @@ -59,15 +93,16 @@ bool JavaConfig::load()

void JavaConfig::printAll()
{
printf("javaHome = [%s]\n", this->javaHome.c_str());
printf("jvmType = [%s]\n", this->jvmType.c_str());
printf("mainClass = [%s]\n", this->mainClass.c_str());

for(size_t i = 0; i < this->classPathList.size(); i++) {
printf("classPathList %2d = [%s]\n", i, this->classPathList[i].c_str());
if(this->debug) {
printf("javaHome = [%s]\n", this->javaHome.c_str());
printf("jvmType = [%s]\n", this->jvmType.c_str());
printf("mainClass = [%s]\n", this->mainClass.c_str());

for(size_t i = 0; i < this->classPathList.size(); i++) {
printf("classPathList %2d = [%s]\n", i, this->classPathList[i].c_str());
}
}

printf("EXE = [%s]\n", this->getConfigFile().c_str());
}

std::string JavaConfig::getConfigFile()
Expand Down
9 changes: 9 additions & 0 deletions src/JavaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
#include <vector>

typedef std::vector<std::string> ClassPathList;
typedef std::vector<std::string> OptionList;
typedef std::map<std::string, std::string> PropertyTable;
typedef std::map<std::string, std::string> OptionTable;

class JavaConfig
{
// Debug ?
bool debug;
// Java Home Dir
std::string javaHome;
// JVM Type
Expand All @@ -16,6 +21,10 @@ class JavaConfig
std::string mainClass;
// Class Path List
ClassPathList classPathList;
// Java System Property
PropertyTable propertyTable;
// Java Options -X
OptionTable optionTable;

public:
JavaConfig();
Expand Down

0 comments on commit c549c55

Please sign in to comment.