How can I check the version number of Log4j in a .jar file?

Viewed 17317

I have a .jar project which may be using Log4j. How can I check the version number of that Log4j?

It's an executable JAR file. I don't have the source code and can't decompile it.

6 Answers

Decompress the JAR file and look for the manifest file (META-INF\MANIFEST.MF)

unzip -p file.jar META-INF/MANIFEST.MF

There are two ways to do this

Way 1:

jar -tfv my.jar | grep -i log4

  23590 Tue Aug 10 10:51:24 IST 2021 log4j-slf4j-impl-2.13.3.jar
  32722 Tue Aug 10 10:51:24 IST 2021 log4j-web-2.13.3.jar
1714164 Tue Aug 10 10:51:24 IST 2021 log4j-core-2.13.3.jar
  23702 Tue Aug 10 10:51:24 IST 2021 log4j-over-slf4j-1.7.30.jar
 292301 Tue Aug 10 10:51:24 IST 2021 log4j-api-2.13.3.jar
  11259 Tue Aug 10 10:50:10 IST 2021 log4j2.xml

Way 2:

unzip -l my.jar | grep -i log4

    23590  08-10-2021 10:51   log4j-slf4j-impl-2.13.3.jar
    32722  08-10-2021 10:51   log4j-web-2.13.3.jar
  1714164  08-10-2021 10:51   log4j-core-2.13.3.jar
    23702  08-10-2021 10:51   log4j-over-slf4j-1.7.30.jar
   292301  08-10-2021 10:51   log4j-api-2.13.3.jar
    11259  08-10-2021 10:50   log4j2.xml
org.apache.log4j.Layout.class.getPackage().getImplementationVersion()

If you have sudo shell access to the server or host, you can get quick and dirty answers with this or something like it:

sudo find / -name "*log4j*" -print -exec unzip -p {} META-INF/MANIFEST.MF \;

As mentioned in other answers this won't work for all JAR files, but it seemed to for me.

Decompress the JAR file of your application and check version in the pom.xml/property file present in directory "META-INF\maven\org.apache.logging.log4j\log4j-core"

If you are on Linux, this can help. It looks for Log4j JAR files, extracts the manifest files of them and prints the Implementation-Version: line which will show you the version of Log4j.

locs=( $(sudo find / -name 'log4j*'|grep jar) )
fcount=${#locs[@]}

echo "Found $fcount jar files"
echo " "

for (( j=0; j<${fcount}; j++ ));
do
   unzip ${locs[$j]} META-INF/MANIFEST.MF
   mv META-INF/MANIFEST.MF META-INF/MANIFEST$j.MF
done

echo " "
for (( j=0; j<${fcount}; j++ ));
do
    echo ${locs[$j]}
    tail -2 META-INF/MANIFEST$j.MF
done
Related