jdecomp
jdecomp copied to clipboard
Error opening .class in Windows, no 'file' command (workaround)
You can install & configure this module on Windows, but opening Java .class files will raise a runtime error about missing program 'file'
. This occurs because find
is Mac/Linux specific & doesn't exist on Windows, but the jdecomp--jar-p implementation assumes it's an inbuilt program.
This is the current jdecomp--jar-p source:
(defun jdecomp--jar-p (file)
"Return t if FILE is a JAR."
(ignore-errors
(let ((type-output (with-output-to-string
(process-file "file" nil standard-output nil
"-bL" "--mime-type"
(expand-file-name file)))))
(member (string-trim type-output) jdecomp--jar-mime-types))))
On Emacs 24+, we can override this implementation with a simple file-exists-p
on Windows. This is the configuration from my user.el:
(jdecomp-mode 1)
(customize-set-variable 'jdecomp-decompiler-type 'cfr)
(customize-set-variable 'jdecomp-decompiler-paths
'((cfr . "~/Downloads/cfr-0.152.jar")))
(advice-add 'jdecomp--jar-p :override
(lambda (file) (file-exists-p file)))
Then jdecomp
works automatically as expected when opening .class files.
(Appreciate the library -- saved me from installing Eclipse 🙂)
EDIT: The above code snippet only works if you manually EVAL it after init. It'll then work as long as your Emacs stays launched. It's probably possible to fix this by including the advice-add in a post-init hook, but I haven't done this yet.