Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

Updating a .jar file

I have a Java .jar file (Saxon-HE-9.8.0-7.jar). I want to modify this .jar file.

My first attempt was to add a new class to it. All seemed to go well, until I tested it, and the calling program insisted it could not find the new class.

This was my new class:

package net.sf.saxon;

public class TransformerFactoryImpl2 extends TransformerFactoryImpl
{
	public TransformerFactoryImpl2()
	{
	    this.setAttribute("http://saxon.sf.net/feature/ignoreSAXSourceParser", true);
	}
}

Open in new window


I compiled it at a Windows Command Line using javac.exe

 java.exe -cp Saxon-HE-9.8.0-7.jar TransformerFactoryImpl2.java

Open in new window


This created file TransformerFactoryImpl2.class

Then I added this new class to the .jar file:

jar uf Saxon-HE-9.8.0-7.jar TransformerFactoryImpl2.class

Open in new window


Did I miss a step? Is there a manifest somewhere I need to add this new class to?


Since this approach did not work, my next idea was to modify the original class. I disassembled the original class, modified it, recompiled it using the same technique as above, then updated the jar file using the same technique as above. I then unzipped the resulting jar file, and found I had two copies of file TransformerFactoryImpl.class in two different places: the original class where it belonged in the net\sf\saxon directory, and my new class in the top level directory.


What step am I missing?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deleyd

ASKER

That worked great!

I have only one problem, which is now:

"java.lang.SecurityException: class "net.sf.saxon.TransformerFactoryImpl2"'s signer information does not match signer information of other classes in the  same package."

So looks like modifying Saxon-HE-9.8.0-7.jar itself isn't going to be viable.

I'll start another question asking for creative solutions around this.

Thank you!
:)