JAR files ...

Hi,

I am trying to use a number of classes stored as a package within a .jar file by importing them at the start of some applet code (see below) ...

However when I put my applet in to its own .jar ( which also includes the jar described above and a DLL that is required ) the applet throws up an error. The error comes when I try to create a new object from the classes within the first jar file... Error shown below.

Exception in thread "AWT-EventQueue-1" java.lang.ExceptionInInitializerError

at regView.readKey(regView.java:75)

at regView.actionPerformed(regView.java:92)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19

95)

at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav

a:2318)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel

.java:387)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242

)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL

istener.java:236)

at java.awt.Component.processMouseEvent(Component.java:6038)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)

at java.awt.Component.processEvent(Component.java:5803)

at java.awt.Container.processEvent(Container.java:2058)

at java.awt.Component.dispatchEventImpl(Component.java:4410)

at java.awt.Container.dispatchEventImpl(Container.java:2116)

at java.awt.Component.dispatchEvent(Component.java:4240)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322

)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)

at java.awt.Container.dispatchEventImpl(Container.java:2102)

at java.awt.Component.dispatchEvent(Component.java:4240)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre

ad.java:273)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.

java:183)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

ad.java:173)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Caused by: java.security.AccessControlException: access denied (java.lang.Runtim

ePermission loadLibrary.jRegistryKey)

at java.security.AccessControlContext.checkPermission(AccessControlConte

xt.java:323)

at java.security.AccessController.checkPermission(AccessController.java:

546)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

at java.lang.SecurityManager.checkLink(SecurityManager.java:818)

at java.lang.Runtime.loadLibrary0(Runtime.java:817)

at java.lang.System.loadLibrary(System.java:1030)

at ca.beq.util.win32.registry.RegistryKey.<clinit>(RegistryKey.java:88)

... 26 more

My code is as follows

// TestApplet.java

import java.io.*;

import java.awt.event.*;

import java.applet.*;

import javax.swing.*;

import javax.swing.border.*;

import java.awt.*;

import ca.beq.util.win32.registry.*;// This is the jar file that is also included in the main jar

publicclass regViewextends JAppletimplements ActionListener

{

private JPanel pane =null;

private JScrollPane scrolling =null;

private JTextPane fileBox =null;

private JTextField keyname =null;

private JTextField valname =null;

private JButton butLoad =null;

privatefinal String LOAD ="load";

publicvoid init()

{

try

{

jbInit();

}

catch(Exception e)

{

e.printStackTrace();

}

}

privatevoid jbInit()throws Exception

{

pane =new JPanel();

pane.setBounds(new Rectangle(0, 0, 500, 325));

pane.setLayout(null);

pane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

pane.setBackground(new Color(0, 0, 0));

fileBox =new JTextPane();

fileBox.setText("");

fileBox.setEditable(false);

scrolling =new JScrollPane(fileBox);

scrolling.setBounds(new Rectangle(16, 110, 295, 200));

keyname =new JTextField();

keyname.setText("");

keyname.setBounds(new Rectangle(16, 23, 206, 29));

valname =new JTextField();

valname.setText("");

valname.setBounds(new Rectangle(16, 65, 206, 29));

butLoad =new JButton();

butLoad.setBounds(new Rectangle(231, 23, 80, 30));

butLoad.setText("Show");

butLoad.setActionCommand(LOAD);

butLoad.addActionListener(this);

pane.add(scrolling);

pane.add(keyname);

pane.add(valname);

pane.add(butLoad);

setContentPane(pane);

}

private String readKey(String key, String val)

{

System.out.println(key);

RegistryKey r =new RegistryKey(RootKey.HKEY_CURRENT_USER, key);

if(r.hasValue(val))

{

RegistryValue v = r.getValue(val);

return v.toString();

}

return"Key not found !";

}

publicvoid actionPerformed(ActionEvent e)

{

if (e.getActionCommand().equals(LOAD))

{

fileBox.setText(readKey(keyname.getText(), valname.getText()));

}

}

}

Any ideas why this might be ?

Any help is much appreciated.

Message was edited by:

chris_j_pook

[8213 byte] By [chris_j_pooka] at [2007-11-27 5:54:20]
# 1
> import ca.beq.util.win32.registry.*;// This is the jar file that is also included in the main jarDoes this imply that you included the jar file itself instead of its contents?
quittea at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 2
> // This is the jar file that is also included in the main jarJust because that jar is inside your main jar doesn't mean it's on your classpath. I'd put it alongside the main jar, and add it to the classpath when you invoke the program.
kevjavaa at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 3
> Just because that jar is inside your main jar doesn't mean it's on your classpath. Yes it does -- if the main JAR is in the classpath.> when you invoke the program.It's an applet.
quittea at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 4
> Caused by: java.security.AccessControlException: access denied (java.lang.Runtim> ePermission loadLibrary.jRegistryKey)Translation: Your applet is not allowed to load this library. Only signed applets are allowed to load native libaries. Is your applet signed?
jsalonena at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 5
> Yes it does -- if the main JAR is in the classpath.Ahh... good to know. > It's an applet.Indeed it is :). /rubs eyes, goes for coffee.
kevjavaa at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 6
No its not signed ... I'll try it as a signed applet and report back. Thanks for the help so far !
chris_j_pooka at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 7

OK i signed it.

The jar contains the following:

jRegistryKey.jar

jRegistryKey.dll

regView.class

My HTML is:

<html><body>

<applet code="regView.class" archive="regview.jar" width=325 height=325>

</applet>

</body></html>

I now get this error :(

Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: ca/beq/util/win32/registry/RegistryKey

at regView.readKey(regView.java:75)

at regView.actionPerformed(regView.java:92)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Its as if it cant find the classes in the jRegistryKey jar. I notice these are all part of a package 'ca.beq.util.win32.registry.RegistryKey' might this be the problem ?

Thanks again

chris_j_pooka at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 8

> > Yes it does -- if the main JAR is in the classpath.

>

> Ahh... good to know.

Don't get me wrong. If an unextracted JAR is put into another JAR, only the JAR file is in the classpath, not its contents ;) You could still access and extract it using a ClassLoader and JarInputStream, though ...

quittea at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 9
> The jar contains the following:> > jRegistryKey.jarI'm afraid I'm responsible for a little bit of confusion :/Extract this JAR and add its contents to your main JAR as you did before.
quittea at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 10

Ok I extracted the files from jRegistryKey and made a new .jar which now has:

regView.class

...

ca<-this is the top level of the subfolders with the classes in.

I still get this error though !

Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: ca/beq/util/win32/registry/RegistryKey

chris_j_pooka at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 11

> Don't get me wrong. If an unextracted JAR is put into

> another JAR, only the JAR file is in the classpath,

> not its contents ;) You could still access and

> extract it using a ClassLoader and JarInputStream,

> though ...

Oh, good... I thought I was sorely misunderstanding the JVM's classloader :). I was actually about to try that. Thanks for clearing that up, I'd have been pulling my hair out when I couldn't get it to work :).

kevjavaa at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 12

> regView.class

> ...

> ca<-this is the top level of the subfolders with the classes in.

Looks right.

> I still get this error though !

> Exception in thread "AWT-EventQueue-2"

> java.lang.NoClassDefFoundError:

> ca/beq/util/win32/registry/RegistryKey

Can you make sure the page has loaded the new JAR file?

quittea at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 13
Yes, its definately loading the new .Jar file and the RegistryKey class is definately there in the directory 'ca/beq/util/win32/registry/' within the .jar.This is really confusing me !
chris_j_pooka at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...
# 14
No worries, I've sorted it. I changed my imports at the top to link directly to each specific file within the subdirectory containing them. Seems to work now !Thanks for the help.
chris_j_pooka at 2007-7-12 15:48:45 > top of Java-index,Java Essentials,Java Programming...