1

Basically I have a Jar file capable of parsing Java files and do some calculations based on the parsed values.

The problem is that the grammar in this Jar is old and only supports version 1.5 of Java. I looked around and found a grammar released by the same company that supports Java version 1.8, so I want to update the Jar file with the two updated files needed by the application.

Analysing the Jar file with JD-GUI, I can see that this is the location of the two files that I want to update:

JarDir/foo/bar/Java.g

JarDir/foo/bar/JavaTreeParser.g

First, I followed this suggestion and tried using 7-zip to edit both files. I basically opened the Jar file with 7-zip, found the files and edited their content. After trying the "updated" Jar, it seems to work just like before updating it. For example it still can't parse this ArrayList<String> s = new ArrayList<>(); since the diamond operator is a Java 7 addition.

Now I was thinking about using jar uf like this answer suggests, but I don't know how to specify the path of the that I want to insert in the Jar.

Can anyone give me a hand with this?

Duarte M.
  • 35
  • 1
  • 6

2 Answers2

1

The 7-zip solution should have worked. I've done this many times. Check your math...

You should be able to do a jar -tvf xxx.jar after editing with 7-zip to verify it was changed. Pay attention to the file sizes and dates to see you've actually changed what you want.

Using jar uf (or -uf) is fairly simple. If you want to update, for example, com.foo.bar.class, you need to create an empty directory structure with a com directory that contains a foo directory which contains bar.class. Then from the directory that contains the com directory run:

jar -uf yourJarFile.jar com

Again, check your work by doing a jar -tvf to see that the file was changed.

wdtj
  • 4,554
  • 3
  • 17
  • 20
  • Well, I did it again with 7-zip and it keeps not working. My first guess was that it has something to do with the application itself. Like it's logic may not handle 1.5 plus Java versions. But the error output is actually from ANTLR saying that `JavaTreeParser.g` mismatched a tree node, so I think that the problem is really in the grammar. My second thought is that the problem may be in the file attributes, or simething. In the 7-zip window, the parameters changed from this (https://image.ibb.co/igJ58U/1.png) to this (https://image.ibb.co/hwwNNp/2.png). Do you have any thoughts about this? – Duarte M. Aug 24 '18 at 20:14
  • Well, looking at 7-zip, it seems that the files are updated, but actually I think they're not. Using 7-zip, I deleted all of the content from `Java.g` and `JavaTreeParser.g` (then I checked both file sizes, and it was 0). Then, I tested my app using this "updated" Jar and it still can parse code, even though this two files are empty. Either there is another grammar being used that hidden somewhere (I seriously doubt that) or I am doing something wrong while updating the files. – Duarte M. Aug 24 '18 at 20:36
0

After some time analysing the Jar file, I realized that Java.g and JavaTreeParser.g aren't being used in the code. They were used to generate some Java files and some .token files. Those are the files being used by the application.

Duarte M.
  • 35
  • 1
  • 6