PDA

View Full Version : Problems running jdk-1.7


incripshin
07-29-2008, 05:43 AM
I just installed jdk-1.7, but it doesn't quite work. I have /usr/local/jdk-1.7.0/bin in my PATH. When I run java or javac, I get this:

$ javac
Error: could not find libjava.so
Error: Could not find Java SE Runtime Environment.

If I give the full path to the binary, it runs fine. libjava.so is located in /usr/local/jdk-1.7.0/jre/lib/i386/libjava.so. I tried adding it to the arguments sent to ldconfig, but all that happens is this:

$ sudo ldconfig /usr/X11R6/lib /usr/local/lib /usr/local/jdk-1.7.0/jre/lib/i386
$ ldconfig -r | grep jdk
search directories: /usr/lib:/usr/X11R6/lib:/usr/local/lib:/usr/local/jdk-1.7.0/jre/lib/i386

Anybody have better luck than me?

incripshin
07-29-2008, 05:45 AM
Also I'm running -current, and I really wish I gave this thread a better title. ... TITLE FIXED!

ocicat
07-29-2008, 07:45 AM
If I give the full path to the binary, it runs fine.
I don't run 1.7, but creating symlinks in 1.6 has worked for me:
# ln -sf /usr/local/jdk-1.6.0/bin/java /usr/local/bin/java
# ln -sf /usr/local/jdk-1.6.0/bin/javac /usr/local/bin/javac

incripshin
07-29-2008, 08:35 AM
I don't run 1.7, but creating symlinks in 1.6 has worked for me:
# ln -sf /usr/local/jdk-1.6.0/bin/java /usr/local/bin/java
# ln -sf /usr/local/jdk-1.6.0/bin/javac /usr/local/bin/javac


No dice. 1.5 and 1.6 behave nicely: when I have it in my PATH, it works fine. Also, this works regardless of PATH:

$ cd /usr/local/jdk-1.7.0/bin
$ ./java
[reams of output]
$ cd .. ; bin/java
[same]
$ cd .. ; jdk-1.7.0/bin/java
[same]

So, it seems like Java is finding the libraries by using getcwd() and argv[0]. This is clearly a horrible idea since it makes working with PATH impossible. I don't know how java 1.5 and 1.6 found the libraries, but it was definitely a different method.

The only solution besides changing the source code is messing with the linker. Currently, ldconfig does not see any of the libraries in /usr/local/jdk-1.7.0/jre/lib/i386 and I can't figure out why.

I also tried setting JAVA_HOME and JDK_HOME to /usr/local/jdk-1.7.0.

ocicat
07-29-2008, 11:03 AM
I don't know how java 1.5 and 1.6 found the libraries, but it was definitely a different method.
My suggestion would be to contact the port maintainer & ask him. The appropriate email address can be found by issuing the following command:

cd /usr/ports ; make search key=jdk

Once you have resolution, it would be great if you would report here what was both the issue & solution.

incripshin
08-01-2008, 02:41 AM
So it was an issue with dladdr(), bug compatible with Solaris by the looks of it. Changing one line of the source code fixes it. The maintainer probably won't commit the change because of a ports soft-lock for 4.4, so in the meantime, you can either apply it yourself or make some shell scripts to do the work for you:

--- patch-jdk_src_solaris_bin_java_md_c.old 2008-07-31 20:34:09.000000000 -0500
+++ patch-jdk_src_solaris_bin_java_md_c 2008-07-31 20:34:19.000000000 -0500
@@ -41,15 +41,6 @@
/*
* On linux, if a binary is running as sgid or suid, glibc sets
* LD_LIBRARY_PATH to the empty string for security purposes. (In
-@@ -841,7 +851,7 @@ static const char*
- SetExecname(char **argv)
- {
- char* exec_path = NULL;
--#if defined(__solaris__)
-+#if defined(__solaris__) || defined(_ALLBSD_SOURCE)
- {
- Dl_info dlinfo;
- int (*fptr)();
@@ -1209,6 +1219,20 @@ UnsetEnv(char *name)
return(borrowed_unsetenv(name));
}

Alternative scripts to make at /usr/local/bin/java, /usr/local/bin/javac, etc. (notice the backticks):
#!/bin/sh
exec /usr/local/jdk-1.7.0/bin/`basename $0` "$@"

ocicat
08-01-2008, 04:57 AM
So it was an issue with dladdr(), bug compatible with Solaris by the looks of it. Changing one line of the source code fixes it. The maintainer probably won't commit the change because of a ports soft-lock for 4.4, so in the meantime, you can either apply it yourself or make some shell scripts to do the work for you:
Thanks for sharing what you found out!

incripshin
08-02-2008, 12:16 AM
The change will make it in despite the lock, so it appears we will all get a working JDK/JRE in the next OpenBSD release without having to accept Sun's license agreements and spend half a day compiling.

schrodinger
08-09-2008, 05:14 PM
just installed 4.3 onto my new laptop and i was about to start the ports build of devel/jdk/1.6 do I have to patch with the diff posted above??

ocicat
08-09-2008, 05:45 PM
...do I have to patch with the diff posted above??
No, the above discussion is specific to the JDK 1.7 port only for current users who are not running what is presntly in the -current ports tree. I built -current as of yesterday & can say firsthand that the above fix was been checked in for JDK 1.7.

schrodinger
08-10-2008, 06:54 PM
woops, you're right this was 1.7 specific. thanks for the reply though.