pacio14
pacio14

Reputation: 351

Compare files .class Beyond Compare 4

I'm using Beyond Compare 4 (4.1.9) in order to compare war files.

I need to compare the files .class that I find in the several packages.

  1. How I can compare them using this product (Beyond Compare 4)?
  2. Otherwise there is another product which can compare war file and compile the .class files?

Upvotes: 6

Views: 35098

Answers (6)

sNash
sNash

Reputation: 963

I managed to make this work about 90% in macOS Beyond Compare v4.4.7. Thanks to @Codizon for great guidance.

  1. Install jd-cli(https://github.com/intoolswetrust/jd-cli) : this is a maven project. mvn install will generate jd-cli.jar
  2. Run Beyond Compare then select File Formats... in the context menu
  3. Click + to create a new file format for .class extension
  4. Put value of Mask *.class in General tab
  5. Go to Conversion tab, select External program
  6. Enter Loading like this : {java path} -jar {jd-cli.jar path} %s -g ERROR > %t

e.g. my actual command was like this.

/opt/homebrew/Cellar/openjdk/20.0.1/libexec/openjdk.jdk/Contents/Home/bin/java -jar /Users/myMac/Documents/source_codes/jd-cli-jd-cli-1.2.1/jd-cli/target/jd-cli.jar %s -oc -g ERROR > %t

The only thing bothers me is that it changes package value by putting absolute path prior to it's original value which results the whole class files marked as different in Folder Compare view.

Upvotes: 0

Ashad Ahmad
Ashad Ahmad

Reputation: 29

The link to more formats is old in the above answer. Here use this one.

https://www.scootersoftware.com/kb/moreformats

  1. Download Java Class to Source file format from https://www.scootersoftware.com/kb/moreformats

  2. In Beyond Compare, pick Tools | Import Settings.

  3. Fill in the downloaded filename, and click Next and proceed to finish.

Upvotes: 0

Codizon
Codizon

Reputation: 447

Option : javap -l -p -c -constants %s > %t 2>&1 : doesn't work for me on beyondCompare4 4.3.7 (latest version to this date), and if used directly through cmd, gives a .class output but the formatting is bad and it is not really interpretable for the java reader I am.

Option to download the format through http://www.scootersoftware.com/download.php?zz=kb_moreformatsv4 : doesn't work for me neither. This library is based http://varaneckas.com/jad which is quite old.

The option I recommend and that worked is : Download https://github.com/kwart/jd-cli (project based from the famous "Java Decompiler" or "jd-gui" as we know it). Once it is installed, do the following in BeyondCompare4 : Go in format, create a new format, use external program, and use the following : C:\Users%USERNAME%\jd-cli-1.2.0-dist\jd-cli.bat %s > %t 2>&1

Hope this will help some.

Upvotes: 3

Ray
Ray

Reputation: 1334

I recently came across the need to compare class files in Beyond Compare 4 and so I found that adding an external program and using javap -l -p -c -constants %s > %t 2>&1 was enough for me. Just make sure a reasonably recent javap is one the PATH that understands any of the class file formats you'd want to compare. No extra software required and is cross platform compatible.

Upvotes: 0

ChandraBhan Singh
ChandraBhan Singh

Reputation: 2971

  1. Download Java Class to Source file format from http://www.scootersoftware.com/download.php?zz=kb_moreformatsv4

  2. In Beyond Compare, pick Tools | Import Settings.

  3. Fill in the downloaded filename, and click Next and proceed to finish.

Upvotes: 4

Chris Kennedy
Chris Kennedy

Reputation: 2899

Double clicking on a war file in Beyond Compare's folder compare will expand it as a folder because war files are essentially zip files.

To decompile Java class files to source code in Beyond Compare, install the Java Class to Source file format. With the file format installed, when you double click on a .class file inside a .war archive, it will display the decompiled source code in Beyond Compare's Text Compare.

Download page for file formats: http://www.scootersoftware.com/download.php?zz=kb_moreformatsv4

Note the Java class to source file format is only available for Windows, it isn't available for the Linux or Mac versions of Beyond Compare.

Upvotes: 12

Related Questions