简体   繁体   中英

Sun Java not loading UnixPrincipal (Ubuntu 12)

Im getting this very odd error with sun java and ubuntu.

"java.lang.ClassNotFoundException: com.sun.security.auth.UnixPrincipal"

This class appears to be a sun specific class, and i have a fresh, working version of sun java 1.6 on ubuntu 12.04. I have confirmed that my version of java is the correct one which is being used to run by class, and in fact, that the other versions (like openjdk) are not interfering.

Here are my specs :

$ java -version java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)

$ lsb_release -a No LSB modules are available. Distributor ID:
Ubuntu Description: Ubuntu 12.04 LTS Release: 12.04 Codename:
precise

The error :

home/vagrant/Development/workspace/xxxxx/build.xml:222: java.lang.NoClassDefFoundError: com/sun/security/auth/UnixPrincipal at org.apache.hadoop.security.UserGroupInformation.(UserGroupInformation.java:246) at org.apache.hadoop.fs.FileSystem$Cache$Key.(FileSystem.java:1436) at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1337) at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:244) at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:122) ... Caused by: java.lang.ClassNotFoundException: com.sun.security.auth.UnixPrincipal at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1361) at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1311) at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1070) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 38 more

'First, I thought this just meant that the class wasnt in my sun installation'

But the following :

unzip -l /usr/lib/jvm/java-6-sun/jre/lib/rt.jar | grep UnixPrincipal

revealed :

1272 2012-05-09 10:19 com/sun/security/auth/UnixPrincipal.class

And, by checking System.getProperties(), I found :

java.ext.dirs=....usr/lib/jvm/java-6-sun-1.6.0.33/jre/lib/rt.jar.....

Thus indicating that this class is in a jar which is certainly in the Runtime version of my java !

Thus, somehow, the java runtime is not able to load this class. I wonder why ?

One minor note : Im running it via ant 1.8. However, I dont think this should effect anything, since the Ant classloader is, I believe, relatively stable.

You've probably solved this by now, but here's my recent tangle with the same problem:

Both Sun java and gcj installed. Running interactively gave me the Sun java and the UnixPrincipal class loads correctly. Running non-interactively ( service myservice start ) would not properly set JAVA_HOME and the system would use gcj instead and UnixPrincipal fails to load. Explicitly setting JAVA_HOME in my service script resolved the problem.

I encountered this problem trying to use ant to run Solr. While I had JAVA_HOME set up for Oracle JDK8, I believe that ant may have been finding the openjdk install on my Ubuntu 15.10 computer.

The solution to the problem was to include the fork="true" option in the <java> task:

<java fork="true" classname="com.mycompany.MyMainClassName">

By including the fork="true" option, it created a 2nd JVM using the java command which correctly found my Oracle JDK. If you do not include the fork="true" option, the user program is run inside the same JVM that ant is using (which may not be the JDK you intend).

For reference, the full error stacktrace was:

 [java] java.lang.NoClassDefFoundError: com/sun/security/auth/UnixPrincipal
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:195)
     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:772)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:222)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:136)
     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:109)
     [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java]     at java.lang.reflect.Method.invoke(Method.java:497)
     [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
     [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
     [java]     at org.apache.tools.ant.Target.execute(Target.java:435)
     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:456)
     [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
     [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:853)
     [java]     at org.apache.tools.ant.Main.startAnt(Main.java:235)
     [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
     [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
     [java] Caused by: java.lang.NoClassDefFoundError: com/sun/security/auth/UnixPrincipal
     [java]     at org.apache.hadoop.security.UserGroupInformation.<clinit>(UserGroupInformation.java:336)
     [java]     at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:1765)
     [java]     at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:1758)
     [java]     at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1626)
     [java]     at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:254)
     [java]     at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:123)
     [java]     at com.touchcommerce.engagementloader.EngagementLoader.getFileSystem(EngagementLoader.java:342)
     [java]     at com.touchcommerce.engagementloader.EngagementLoader.load(EngagementLoader.java:364)
     [java]     at com.touchcommerce.engagementloader.EngagementLoader.main(EngagementLoader.java:454)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java]     at java.lang.reflect.Method.invoke(Method.java:497)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:218)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:153)
     [java]     ... 21 more
     [java] Caused by: java.lang.ClassNotFoundException: com.sun.security.auth.UnixPrincipal
     [java]     at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1388)
     [java]     at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1337)
     [java]     at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1095)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
     [java]     ... 36 more
     [java] Java Result: -1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM