Uploaded image for project: 'FtpServer'
  1. FtpServer
  2. FTPSERVER-514

please add a few configuration files to support GraalVM native images

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Trivial
    • Resolution: Unresolved
    • 1.2.0
    • None
    • Server
    • None
    • any os, with graalvm. Im using Graalvm for Java 17

    Description

      Hi - i love your project and use it a lot. Thank you.

      I wanted to make it work with GraalVM's `native-image` compiler mechanism.

      Here's some quick background on GraalVM native images. If you're interested, great, please read on. If not, please feel free to skip to the end of the ticket

       GraalVM is an OpenJDK replacement with an optional, extra component called the `native-image` compiler. This compiler takes Java applications (`.class` files, `.jar`s, etc.) and turns them into very quick, operating-system and architecture-specific binaries that take vanishingly small amounts of memory. 

      In order to do this trick, it analyses all the code used in your main application and looks at all the types that your application uses, and then looks at all the types your code uses and all the types that it uses, etc. 

      It does this all at compile time. It keeps those types - from the JRE and from your classpath - and throws away everything else. This is problematic, however, because it forecloses on the dynamic behavior of the JVM. Things like reflection, JNI, serialization, reflection, JDK proxies, loading resources from the classpath, etc., all beak. Unless that is, you furnish some `.json` files at compile time that tell it about these dynamic things. Then, they work.

      Ideally, each library that an application uses would furnish its own configuration files. These are trivial files that live in each `.jar`s `META-INF/native-image` directory.

       

      SO: please add these configuration files to your project. They allowed me to get a moderately sophisticated implementation of the Apache Mina FTP Server working. [See this example ](https://github.com/joshlong/spring-integration-aot-smoke-tests/blob/f63ba03bf70132bf9e4adb5b7ae31005d191647d/ftp-root/ftp-server/src/main/java/aot/ftpserver/FtpServerApplication.java) (you don't need that except as background for some of the things I attempt. You can build a native image by installing GraalVM and then running `mvn -Pnative -DskipTests clean package` in that project)

       

      1: `src/main/resources/META-INF/native-image/reflect-config.json` 

      ```

      [

      { "name": "org.apache.mina.transport.socket.nio.NioProcessor", "queryAllPublicConstructors": true, "allPublicConstructors": true, "queryAllDeclaredConstructors": true, "allPublicClasses": true, "queryAllDeclaredMethods": true, "allPublicMethods": true, "allPublicFields": true, "allDeclaredMethods": true, "allDeclaredFields": true, "queryAllPublicMethods": true, "allDeclaredConstructors": true, "allDeclaredClasses": true }

      ]

      ```

       

      2: `src/main/resources/META-INF/native-image/resource-config.json`

       

      ```

      {
      "resources": {
      "includes": [

      { "pattern": "\\Qorg\/apache\/ftpserver\/message\/FtpStatus.properties\\E" }

      ,

      { "pattern": "\\Qorg\/apache\/ftpserver\/message\/FtpStatus_en.properties\\E" }

      ,

      { "pattern": "\\Qorg\/apache\/ftpserver\/message\/FtpStatus_zh-tw.properties\\E" }

      ]
      }
      }

      ```

       

      You can see how I did it in that Apache 2 licensed code I linked you to. 

       

      Thank you for your consideration.

       

       

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            joshlong Josh Long
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: