如何解决“命令行太长”问题使用 GraalVM 和 Windows?

发布于 2025-01-11 02:26:44 字数 6289 浏览 0 评论 0原文

我正在尝试在 Windows 上使用 GraalVM 构建 JHipster 7 应用程序。我已经成功让它在 macOS 和 Linux 上运行。在 Windows 中,我收到有关命令行太长的错误。

[INFO] Executing: C:\Users\runneradmin\.graalvm\graalvm-ce-java17-22.0.0.2\bin\native-image.cmd -cp ...;D:\a\auth0-full-stack-java-example\auth0-full-stack-java-example\target\flickr-2-0.0.1-SNAPSHOT.jar --no-fallback --verbose -J-Xmx10g -H:Name=native-executable
The command line is too long.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

我复制并粘贴了 GitHub Actions 运行的命令,它的长度刚刚超过 12,000 个字符。根据此文档、Windows仅支持8191个字符。

我尝试使用 这个建议,但没有帮助。我什至尝试了 C:\r 而不是 C:\repo

Twitter 上的人们 建议使用 PowerShell 并将命令回显到文件中,然后运行该文件。但是,我还没有找到任何有关如何从 Maven 中提取 native-image.cmd 命令及其参数的示例。

您可以找到我用来配置的 GitHub 操作 此处。为了方便起见,我也将其粘贴在下面。

name: Publish

on:
  release:
    types: [published]

env:
  graalvm_version: '22.0.0.2'
  java_version: '17'
  branch: 'spring-native'

jobs:
  build:
    name: GraalVM - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
    - uses: actions/checkout@v2
      with:
        ref: '${{ env.branch }}'
    - name: Set up GraalVM (Java ${{ env.java_version }})
      uses: graalvm/setup-graalvm@v1
      with:
        version: '${{ env.graalvm_version }}'
        java-version: '${{ env.java_version }}'
        components: 'native-image'

    - name: Cache Maven dependencies
      uses: actions/cache@v2
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
        restore-keys: ${{ runner.os }}-maven

    - name: Cache npm dependencies
      uses: actions/cache@v2
      with:
        path: |
          ~/.npm
          ~/.cache/Cypress/
        key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

    - name: Set up swap space
      if: runner.os == 'Linux'
      uses: pierotofy/[email protected]
      with:
        swap-size-gb: 10

    - name: Build native images
      run: ./mvnw -B -ntp package -Pnative,prod -DskipTests

    - name: Archive binary
      uses: actions/upload-artifact@v2
      with:
        name: flickr2-${{ matrix.os }}-x86_64
        path: target/native-executable

    - name: Get release version
      run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
    - name: Rename binary
      run: mv target/native-executable target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64
    - name: Upload release
      uses: alexellis/[email protected]
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        asset_paths: '["target/flickr2-${{ runner.os }}*"]'

  build-windows:
    name: GraalVM - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest]
    steps:
      - uses: actions/checkout@v2
        with:
          ref: '${{ env.branch }}'
      - uses: ilammy/msvc-dev-cmd@v1
      - uses: microsoft/setup-msbuild@v1

      - name: Set up GraalVM (Java ${{ env.java_version }})
        uses: graalvm/setup-graalvm@v1
        with:
          version: '${{ env.graalvm_version }}'
          java-version: '${{ env.java_version }}'
          components: 'native-image'

      - name: Cache Maven dependencies
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-maven

      - name: Cache npm dependencies
        uses: actions/cache@v2
        with:
          path: |
            ~/.npm
            ~/.cache/Cypress/
          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

      - name: Configure pagefile
        uses: al-cheb/[email protected]

      - name: Set up pagefile
        run: |
          (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize
      - name: mvnw --version
        run: mvnw --version
        shell: cmd

      - name: Maven resolve
        run: mvnw -B -ntp dependency:resolve-plugins
        shell: cmd

      - name: Build native images
        run: |
          mklink /J C:\r C:\Users\runneradmin\.m2\repository
          mvnw -B -ntp package -Pnative,prod -DskipTests -Dmaven.repo.local=C:\r
        shell: cmd

      - name: Archive binary
        uses: actions/upload-artifact@v2
        with:
          name: flickr-${{ matrix.os }}-x86_64.exe
          path: target/native-executable.exe

      - name: Get release version
        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

      - name: Rename binary
        run: move target/native-executable.exe target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64.exe
      - name: Upload release
        uses: alexellis/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          asset_paths: '["target/flickr2-${{ runner.os }}*"]'

I'm trying to make a JHipster 7 app build with GraalVM on Windows. I've successfully got it to work with macOS and Linux. With Windows, I get an error about the command line being too long.

[INFO] Executing: C:\Users\runneradmin\.graalvm\graalvm-ce-java17-22.0.0.2\bin\native-image.cmd -cp ...;D:\a\auth0-full-stack-java-example\auth0-full-stack-java-example\target\flickr-2-0.0.1-SNAPSHOT.jar --no-fallback --verbose -J-Xmx10g -H:Name=native-executable
The command line is too long.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

I've copied and pasted the command that GitHub Actions runs and it's just over 12,000 characters long. According to this document, Windows only supports 8191 characters.

I tried shortening up the classpath using this suggestion, but it doesn't help. I even tried C:\r instead of C:\repo.

People on Twitter suggested using PowerShell and echoing the commands into a file, and then running that. However, I haven't been able to find any examples of how to extract the native-image.cmd command and its arguments from Maven.

You can find the GitHub action I'm using to configure things here. I've also pasted it below for convenience.

name: Publish

on:
  release:
    types: [published]

env:
  graalvm_version: '22.0.0.2'
  java_version: '17'
  branch: 'spring-native'

jobs:
  build:
    name: GraalVM - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
    - uses: actions/checkout@v2
      with:
        ref: '${{ env.branch }}'
    - name: Set up GraalVM (Java ${{ env.java_version }})
      uses: graalvm/setup-graalvm@v1
      with:
        version: '${{ env.graalvm_version }}'
        java-version: '${{ env.java_version }}'
        components: 'native-image'

    - name: Cache Maven dependencies
      uses: actions/cache@v2
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
        restore-keys: ${{ runner.os }}-maven

    - name: Cache npm dependencies
      uses: actions/cache@v2
      with:
        path: |
          ~/.npm
          ~/.cache/Cypress/
        key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

    - name: Set up swap space
      if: runner.os == 'Linux'
      uses: pierotofy/[email protected]
      with:
        swap-size-gb: 10

    - name: Build native images
      run: ./mvnw -B -ntp package -Pnative,prod -DskipTests

    - name: Archive binary
      uses: actions/upload-artifact@v2
      with:
        name: flickr2-${{ matrix.os }}-x86_64
        path: target/native-executable

    - name: Get release version
      run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
    - name: Rename binary
      run: mv target/native-executable target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64
    - name: Upload release
      uses: alexellis/[email protected]
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        asset_paths: '["target/flickr2-${{ runner.os }}*"]'

  build-windows:
    name: GraalVM - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest]
    steps:
      - uses: actions/checkout@v2
        with:
          ref: '${{ env.branch }}'
      - uses: ilammy/msvc-dev-cmd@v1
      - uses: microsoft/setup-msbuild@v1

      - name: Set up GraalVM (Java ${{ env.java_version }})
        uses: graalvm/setup-graalvm@v1
        with:
          version: '${{ env.graalvm_version }}'
          java-version: '${{ env.java_version }}'
          components: 'native-image'

      - name: Cache Maven dependencies
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-maven

      - name: Cache npm dependencies
        uses: actions/cache@v2
        with:
          path: |
            ~/.npm
            ~/.cache/Cypress/
          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

      - name: Configure pagefile
        uses: al-cheb/[email protected]

      - name: Set up pagefile
        run: |
          (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize
      - name: mvnw --version
        run: mvnw --version
        shell: cmd

      - name: Maven resolve
        run: mvnw -B -ntp dependency:resolve-plugins
        shell: cmd

      - name: Build native images
        run: |
          mklink /J C:\r C:\Users\runneradmin\.m2\repository
          mvnw -B -ntp package -Pnative,prod -DskipTests -Dmaven.repo.local=C:\r
        shell: cmd

      - name: Archive binary
        uses: actions/upload-artifact@v2
        with:
          name: flickr-${{ matrix.os }}-x86_64.exe
          path: target/native-executable.exe

      - name: Get release version
        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

      - name: Rename binary
        run: move target/native-executable.exe target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64.exe
      - name: Upload release
        uses: alexellis/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          asset_paths: '["target/flickr2-${{ runner.os }}*"]'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗫嚅 2025-01-18 02:26:44

升级到 native-build-tools v0.9.10 修复了 Windows 上的此问题。更多详细信息请访问 https://github.com/graalvm/native-build-tools /issues/214https://github.com/graalvm/setup-graalvm/issues/6#issuecomment-1054582083

Upgrading to native-build-tools v0.9.10 fixes this issue on Windows. More details at https://github.com/graalvm/native-build-tools/issues/214 and https://github.com/graalvm/setup-graalvm/issues/6#issuecomment-1054582083.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文