Closed sds83uk closed 2 years ago
Have you tried
mvn package -Pnative
? ie: on the root directory, use maven to build the package, and pass the -Pnative, to also build the native package. You may need to setup some environment variables (GRAALVM_HOME)
If you can build JAR using maven, use mvn package -Pnative
.
If you just downloaded JAR, and want to build native image using it:
native-image --static -jar log4j2-scanner-2.6.1-package.jar log4j2-scan-2.6.1 -H:-CheckToolchain -H:ReflectionConfigurationFiles=reflection-config.json
Thank you both!
After some experimentation, since Pull Request 172 I have found that I can just:
mvn package -Pnative
Prerequisites for Using Native Image on Windows Lastly, on Windows, the native-image builder will only work when it is executed from the x64 Native Tools Command Prompt. Source: https://www.graalvm.org/reference-manual/native-image/
Whilst the above is now my preferred option, I found that I could also use native-image ... -H:ReflectionConfigurationFiles=reflection-config.json
to build the Windows executable against:
-package.jar
) created with VS Code and the Maven "package" optionOne thing that initially tripped me up was that when I tried run the command mvn package -Pnative
in the VS Code terminal, I encountered this error (again):
Error: Default native-compiler executable 'cl.exe' not found via environment variable PATH
Unless anyone has any counter advice, I found this the first time I had problems with native-image
:
"Once you've installed Visual Studio, all of your build commands should be run through the Native Tools Command Prompt. If you keep the default Start Menu shortcuts while installing Visual Studio, this will be accessible at: Start -> Visual Studio 2019 -> Tools -> x64 Native Tools Command Prompt Source: https://stackoverflow.com/questions/64197329/cl-exe-missing-when-building-native-app-using-graalvm
@sds83uk Your logs will be helpful to many people trying to build own image. :D
I should probably start this query with a disclaimer...
I am not a Java developer but was asked if I could build the scanner, from source, into a Windows executable. It is a bit long-winded (and all new to me) but the short version is that I have found a way to install+configure the necessary components (initially in a Windows Sandbox) to allow me to "package" using VSCode+Maven and create the "native-image" as described here:
https://github.com/logpresso/CVE-2021-44228-Scanner/wiki/FAQ
I recognise that a lot of fantastic work has been going on by all contributors and my old method is no longer working for two reasons:
1. Removal of scanner.json
native-image -jar .\cve-2021-44228-scanner-2.6.1\target\log4j2-scanner-2.6.1.jar log4j2-scan-2.6.1 -H:-CheckToolchain -H:ReflectionConfigurationFiles=.\cve-2021-44228-scanner-2.6.1\scanner.json
2. Dependency (org.apache.commons.compress)
native-image -jar .\cve-2021-44228-scanner-2.6.1\target\log4j2-scanner-2.6.1.jar
Having seen most of the commits to improve the build process (now including some of the native-image options previously required) I found an additional "-package.jar" file is created that can be built with a simplified command:
native-image -jar .\cve-2021-44228-scanner-2.6.1\target\log4j2-scanner-2.6.1-package.jar
Are you able to advise whether it is appropriate to create the native image from the
-package.jar
file in this way? I also accept that with my limited knowledge I may be missing a simple trick that will do this all for me; or, that it may be beyond the scope of a simple FAQ.Thank you again.