Eugen Labun created MNG-7578:
--------------------------------

             Summary: Building Linux image on Windows impossible (patch incuded)
                 Key: MNG-7578
                 URL: https://issues.apache.org/jira/browse/MNG-7578
             Project: Maven
          Issue Type: Bug
          Components: Core, Toolchains
    Affects Versions: 3.8.6
            Reporter: Eugen Labun


If you try to find `javac` in a Linux JDK using `Toolchain.findTool()` method, 
it will fail when the build is running on Windows, since the implementation 
[JavaToolchainImpl#findTool()|https://github.com/apache/maven/blob/maven-3.8.6/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainImpl.java#L74-L86]
 appends ".exe" to the toolName (causing `javac.exe` not found):
{code:java}
    private static File findTool( String toolName, File installFolder )
    {
        File bin = new File( installFolder, "bin" ); //NOI18N
        if ( bin.exists() )
        {
            File tool = new File( bin, toolName + ( Os.isFamily( "windows" ) ? 
".exe" : "" ) ); // NOI18N
            if ( tool.exists() )
            {
                return tool;
            }
        }
        return null;
   }
{code}

The current  workaround is to manually add a fake `javac.exe` file to the JDK 
`bin` directory [tool chain issue (building linux image on windows 
machine)|https://github.com/moditect/moditect/issues/107].

The `findTool` method could yet easily be changed to search for exact 
`toolName` as requested, with a fallback to `toolName.exe` for backward 
compatibility:

{code:java}
    private static File findTool( String toolName, File installFolder )
    {
        File bin = new File( installFolder, "bin" );
        if ( bin.exists() )
        {
            File tool = new File( bin, toolName );
            if ( tool.exists() )
            {
                return tool;
            }
            File toolExe = new File( bin, toolName + ".exe" );
            if ( toolExe.exists() )
            {
                return toolExe;
            }
        }
        return null;
   }
{code}





--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to