javagitmavengithubmainclass

Java: "Couldn't find the target main class to run after checking the Java version" when running a popular .jar file to clean Git repository (BFG)


BFG REPO CLEANER

I am attempting to clean up a Git repository (remove passwords) using BFG repo cleaner:

This is a popular project recommended even officially by GitHub as per:

INTENDED USAGE

The intended operation as I understand it is:

  1. Ensure current Java is installed (Java 8)
  2. Download current BFG .jar file (all versions here, now 1.14.0), and put in .git folder for project you want to affect.
  3. Create passwords.txt file in same directory with each password you want replaced on a different line.
  4. Ensure the most current commit has the sensitive data (passwords) removed manually.
  5. Run java -jar bfg.jar --replace-text passwords.txt and it will clean the older commits.

ERROR

However, this is returning the following error, both from Administrator cmd and from Ubuntu on Windows:

Couldn't find the target main class to run after checking the Java version.

The attribute should be in the Jar manifest and called Main-Class-After-UseNewerJava-Check

MAIN CLASS

The mainClass is defined here it appears in the code, although I don't know Java or how Java projects work (I code C++ and C#):

https://github.com/rtyley/bfg-repo-cleaner/blob/master/bfg/build.sbt

mainClass := Some("use.newer.java.Version8")
packageOptions in (Compile, packageBin) +=
  Package.ManifestAttributes( "Main-Class-After-UseNewerJava-Check" -> "com.madgag.git.bfg.cli.Main" )

JAVA VERSIONS

I uninstalled and reinstalled Java 8 in Windows and get from cmd java -version:

java version "1.8.0_401"
Java(TM) SE Runtime Environment (build 1.8.0_401-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.401-b10, mixed mode)

From Ubuntu on Windows I get:

openjdk version "11.0.21" 2023-10-17
OpenJDK Runtime Environment (build 11.0.21+9-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.21+9-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

Both of these give the same error, even just from java -jar bfg.jar with no other commands.

COMPUTER SPECIFIC ISSUE

I tested on another Windows system, and this does not provide the same error from java -jar bfg.jar (it provides the help information).

So this is clearly a single computer system related issue, although I am not sure what.

Is there any probably reason one Windows computer would provide the error above and another would run it smoothly?

Thanks for any ideas.


Solution

  • It appears to run further than that on my machine (MacBook, OpenJDK 18)

    ravn@freewifi /tmp % java -version
    openjdk version "18.0.2.1" 2022-08-18
    OpenJDK Runtime Environment Zulu18.32+13-CA (build 18.0.2.1+1)
    OpenJDK 64-Bit Server VM Zulu18.32+13-CA (build 18.0.2.1+1, mixed mode, sharing)
    ravn@freewifi /tmp % curl -O https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 13.8M  100 13.8M    0     0  8101k      0  0:00:01  0:00:01 --:--:-- 8100k
    ravn@freewifi /tmp % echo muh > pass
    ravn@freewifi /tmp % git init
    Initialized empty Git repository in /private/tmp/.git/
    ravn@freewifi /tmp % java -jar bfg-1.14.0.jar --replace-text pass
    
    Using repo : /private/tmp/.git
    
    java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at use.newer.java.Util.invokeMainMethod(Util.java:89)
        at use.newer.java.Util.executeMainProgram(Util.java:28)
        at use.newer.java.Util.checkJavaVersionAndExecuteMainProgram(Util.java:18)
        at use.newer.java.Version8.main(Version8.java:5)
    Caused by: java.lang.IllegalArgumentException: Couldn't find 'HEAD' in /private/tmp - are you sure that exists?
    
    
    

    Note, the error message you see may have been triggered later than this . You should be able to replicate this on your system.