Skip to content

Commit

Permalink
add debug info for java libpath
Browse files Browse the repository at this point in the history
  • Loading branch information
vintagewang committed Aug 18, 2012
1 parent 6710cee commit b6105a1
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,10 @@ pip-log.txt

# Mac crap
.DS_Store

# cpp
*.o

# java
*.class
*.jar
2 changes: 1 addition & 1 deletion bin/jwrapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<jvmtype>server</jvmtype>

<mainclass>com.github.vintage.wang.jwrapper.sample.NiceServer</mainclass>
<mainclass>com.github.vintage.wang.jwrapper.sample.HelloWorld</mainclass>

<properties>
<java.ext.dirs>${cpd}/../lib</java.ext.dirs>
Expand Down
Binary file modified project/icon1.ico
Binary file not shown.
1 change: 1 addition & 0 deletions samples/Hello/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mvn clean install
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
package com.github.vintage.wang.jwrapper.sample;

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

public class HelloWorld {
public static void printAll() {
Map m = System.getenv();
for (Iterator it = m.keySet().iterator(); it.hasNext();) {
String key = (String) it.next();
String value = (String) m.get(key);
System.out.println(key + ":" + value);
}
System.out.println("--------------------------------------");
Properties p = System.getProperties();

for (Iterator it = p.keySet().iterator(); it.hasNext();) {
String key = (String) it.next();
String value = (String) p.get(key);
System.out.println(key + ":" + value);
}
}

public static void main(String[] args) {
int i = 0;
for (String arg : args) {
System.out.println("arg[" + i++ + "] = " + arg);
}
printAll();
System.out.println(System.getenv("LD_LIBRARY_PATH"));
System.out.println("Hello World!");
System.exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public NiceServer() {

@Override
public void run() {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 50; i++) {
System.out.println(i + " Hello world");
try {
Thread.sleep(1000);
Expand All @@ -26,7 +26,7 @@ public void run() {

@Override
public void run() {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 50; i++) {
System.out.println(i + " Nice world");
try {
Thread.sleep(1000);
Expand All @@ -45,6 +45,12 @@ public void start() {
}

public static void main(String[] args) {
System.getProperties().list(System.out);
System.out.println("-------------------------------------");
System.out.println("maxMemory " + Runtime.getRuntime().maxMemory()/1024/1024);
System.out.println("freeMemory " + Runtime.getRuntime().freeMemory()/1024/1024);
System.out.println("totalMemory " + Runtime.getRuntime().totalMemory()/1024/1024);
System.out.println("-------------------------------------");
System.out.println("NiceServer begin...");
NiceServer niceServer = new NiceServer();
niceServer.start();
Expand Down
23 changes: 15 additions & 8 deletions src/JWUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,19 @@ namespace JWUtil

std::string getCurrentExeFileDir()
{
std::string result = getCurrentExeFilePath();
std::string::size_type pos = result.find_last_of(FILE_SEPARATOR);
if(pos != std::string::npos) {
return result.substr(0, pos);
}

return result;
return getDirName(getCurrentExeFilePath().c_str());
}

void setEnv(const char* name, const char* value)
{
assert(NULL != name);
assert(NULL != value);

#ifdef WIN32
std::string envFull = name;
envFull += "=";
envFull += value;

#ifdef WIN32
_putenv(envFull.c_str());
#else
setenv(name, value, 1);
Expand Down Expand Up @@ -148,4 +143,16 @@ namespace JWUtil

return (envLibPath != NULL) ? envLibPath : "";
}

std::string getDirName(const char* path)
{
assert(NULL != path);
std::string result = path;
std::string::size_type pos = result.find_last_of(FILE_SEPARATOR);
if(pos != std::string::npos) {
return result.substr(0, pos);
}

return result;
}
}
6 changes: 6 additions & 0 deletions src/JWUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ namespace JWUtil
void addLibPath(const char* path);

std::string getLibPath();

/**
* 获取DIRNAME
* path 包含文件名的全路径
*/
std::string getDirName(const char* path);
};

#endif // end of _JW_JWUTIL_H__
18 changes: 16 additions & 2 deletions src/JavaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ bool JavaConfig::load()
JWUtil::addLibPath(JWUtil::getCurrentExeFileDir().c_str());
JWUtil::addLibPath((this->javaHome + "/jre/bin").c_str());



return true;
}

Expand Down Expand Up @@ -231,57 +229,68 @@ std::string JavaConfig::getJVMDllPath()
#if defined(ARCH64)
result += this->javaHome;
result += "/jre/lib/amd64/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#else
result += this->javaHome;
result += "/jre/lib/i386/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#endif
#elif defined(SOLARIS_X86)
#if defined(ARCH64)
result += this->javaHome;
result += "/jre/lib/sparcv9/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#else
result += this->javaHome;
result += "/jre/lib/sparc/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#endif
#elif defined(HPUX)
#if defined(ARCH64)
result += this->javaHome;
result += "/jre/lib/IA64W/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#else
result += this->javaHome;
result += "/jre/lib/IA64N/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#endif
#elif defined(LINUX)
#if defined(ARCH64)
result += this->javaHome;
result += "/jre/lib/amd64/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#else
result += this->javaHome;
result += "/jre/lib/i386/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.so";
#endif
#elif defined(AIX)
result += this->javaHome;
result += "/jre/bin/classic/";
JWUtil::addLibPath(result.c_str());
result += this->jvmType;
result += "/libjvm.a";
#endif

JWUtil::addLibPath(JWUtil::getDirName(result.c_str()).c_str());

return result;
}

Expand Down Expand Up @@ -363,3 +372,8 @@ void JavaConfig::buildNewOptionTable(OptionTable& table)

table["-Djava.class.path"] = javaClassPath;
}

bool JavaConfig::isDebug()
{
return this->debug;
}
2 changes: 2 additions & 0 deletions src/JavaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class JavaConfig

bool load();

bool isDebug();

void printAll();

void printLog(const char* fmt, ...);
Expand Down
3 changes: 3 additions & 0 deletions src/JavaLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#include "JavaLauncher.h"
#include "JavaConfig.h"
#include "JWUtil.h"
#include "DLL.h"

#define NULL_CHECK0(e) if ((e) == 0) return 0
Expand Down Expand Up @@ -42,6 +43,8 @@ int JavaLauncher::launchJavaApp(int argc, char** argv)
// 1, 获取JVM动态库全路径
std::string jvmPath = JavaConfig::getInstance()->getJVMDllPath();

JavaConfig::getInstance()->printLog("LIBPATH = [%s]", JWUtil::getLibPath().c_str());

// 2, 定义DLL对象,并加载JVM动态库
DLL jvmDll(jvmPath.c_str());

Expand Down

0 comments on commit b6105a1

Please sign in to comment.