Community
Participate
Working Groups
Build Identifier: 20100917-0705 Exception thrown while running the following program in Eclipse using JVM 1.6.0 (MacOS default). The same program works fine in command line. It also works if the eclipse project JRE is set to Standard VM. /* * MacTest.java */ import javax.crypto.Mac; public class MacTest { public static void main(String[] args) throws Exception { Mac mac = Mac.getInstance("HmacSHA1"); } } Exception in thread "main" java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available at javax.crypto.Mac.getInstance(DashoA13*..) at MacTest.main(MacTest.java:6) Reproducible: Always Steps to Reproduce: 1. type the above program 2. in Run configuration->JRE, set jre to alternative -> JVM 1.6.0 (Mac OS default) 3. Run
It looks like you are missing some libraries on the classpath.
Thank you for your reply. I run the program again with -verbose:class option on to see which classes are loaded. It turned out that in Eclipse, the jar files loaded are exactly the same and even more, but it still fails. (On my machine, /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/ is a symbolic link to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/) Could it be the permission thing? Does Eclipse change the default configuration of the sandbox or something? Please help me find out the reason. Thanks. ==================================== The following is from the output. COMMAND LINE: [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar] ... [Opened /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar] ECLIPSE: [Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar] ... [Opened /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar] [Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/ui.jar] [Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jsse.jar] [Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jce.jar] [Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/charsets.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar] [Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar]
If you try this code using an Oracle JRE does it work as expected? It could be that the Apple provided 1.6 JRE does not support that algorithm. According to the Oracle docs it does support HmacSHA1: http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html#SunJCEProvider
Closing as NOT_ECLIPSE, since it appears to be a configuration issue