We try to locate runtime.zip in runtime/ directory relative
to the path of current executable.
This patch also sets the value of 'java.home' to the
directory containing current executable.
Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
Makefile | 2 +
vm/jato.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
index 07182ce..993725e 100644
--- a/Makefile
+++ b/Makefile
@@ -343,7 +343,9 @@ INSTALL_PREFIX ?= $(HOME)
install: $(PROGRAM)
$(E) " INSTALL "Â $(PROGRAM)
$(Q) $(INSTALL) -d -m 755 $(INSTALL_PREFIX)/bin
+ $(Q) $(INSTALL) -d -m 755 $(INSTALL_PREFIX)/bin/runtime
$(Q) $(INSTALL) $(PROGRAM) $(INSTALL_PREFIX)/bin
+ $(Q) $(INSTALL) runtime/runtime.zip $(INSTALL_PREFIX)/bin/runtime/
.PHONY: install
PHONY += FORCE
diff --git a/vm/jato.c b/vm/jato.c
index f6744d7..4792039 100644
--- a/vm/jato.c
+++ b/vm/jato.c
@@ -248,6 +248,46 @@ static void init_system_properties(void)
add_system_property_const("os.version", info.release);
}
+/**
+ * Returns path to directory containing jato executable
+ */
+static char *get_exe_dir(void)
+{
+ char *path;
+ int path_size;
+ int err;
+
+ path_size = 64;
+ path = malloc(path_size);
+ if (!path)
+ error("out of memory");
+
+ do {
+ err = readlink("/proc/self/exe", path, path_size - 1);
+ if (err == -ENAMETOOLONG) {
+ char *new_path;
+
+ path_size = path_size * 2;
+ new_path = realloc(path, path_size);
+
+ if (!new_path)
+ error("out of memory");
+
+ path = new_path;
+ }
+ } while (err == -ENAMETOOLONG);
+
+ if (err < 0)
+ error("failed to locate self executable");
+
+ path[err] = 0;
+
+ char *slash = rindex(path, '/');
+ if (slash)
+ *slash = 0;
+
+ return path;
+}
/**
* This should be called after parsing of call arguments.
@@ -256,6 +296,28 @@ static void init_configurable_system_properties(void)
{
/* XXX: currently user defined -Djava.class.path=value is overriden. */
add_system_property_const("java.class.path", get_classpath());
+
+ /* Set 'java.home' to the directory containing jato binary */
+ char *path = get_exe_dir();
+ add_system_property_const("java.home", path);
+
+ /*
+ * Try to automatically locate runtime.zip containing VM
+ * specific classes and add it to class path.
+ */
+
+ char *runtime_path;
+
+ if (asprintf(&runtime_path, "%s/runtime/runtime.zip", path) < 0)
+ error("asprintf failed");
+
+ struct stat s;
+ if (stat(runtime_path, &s))
+ error("file not found: %s", runtime_path);
+
+ classloader_add_to_classpath(runtime_path);
+ free(runtime_path);
+ free(path);
}
static void native_vmsystemproperties_preinit(struct vm_object *p)
--
1.6.0.6
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel