You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ构建的JAR包无法包含InvalidArgumentException问题求助

Troubleshooting InvalidArgumentException Issues in Your IntelliJ-Built JAR

Hey Aaron, let's break down why you might be hitting issues with InvalidArgumentException even though your JAR builds and runs otherwise. Here are common culprits and actionable steps to debug:

  • Modular Project Configuration Gaps
    If your project uses Java modules (has a module-info.java), double-check that your module properly accesses the java.base module (where InvalidArgumentException resides). While java.base is implicitly required for most projects, misconfigurations like restricted exports or accidental module restrictions could cause runtime access issues.

  • Incomplete Artefact Packaging
    Head back to your Artefact Structure settings in IntelliJ. Verify that the class file containing the code that throws InvalidArgumentException is actually included in the JAR output. You can manually unzip your built JAR and check if the corresponding .class file exists in the correct directory structure. If it's missing, adjust your artefact to include the relevant module or source set.

  • JDK Version Mismatch Between Build and Runtime
    Even though InvalidArgumentException has existed since JDK 1.5, a mismatch between the JDK you used to build the JAR and the one you're using to run it could cause unexpected behavior—especially if you're using modular features. Run java -version to confirm the runtime JDK, and compare it to the Project SDK set in IntelliJ's Project Structure.

  • Subtle Code Logic Issues
    Sometimes the problem isn't with the exception itself, but how it's being thrown or handled. For example:

    // Check if the value triggering the exception has unexpected edge cases
    if (input < 0) {
        throw new IllegalArgumentException("Input cannot be negative: " + input);
    }
    

    Verify if the value you're passing when throwing the exception is causing unintended side effects, or if the exception is being swallowed incorrectly elsewhere in your code.

  • IntelliJ Cache Corruption
    IDE caches can sometimes lead to mismatched builds. Try these steps to rule that out:

    1. Go to File > Invalidate Caches... and select "Invalidate and Restart"
    2. Rebuild your entire project with Build > Rebuild Project
    3. Delete and re-create your artefact in File > Project Structure > Artefacts before rebuilding the JAR

To narrow this down further, it would help to share:

  • The full stack trace of the exception you're seeing (this will pinpoint exactly where and why it's failing)
  • The code snippet where you're throwing InvalidArgumentException
  • If it's a modular project, the content of your module-info.java
  • The exact command you're using to run the JAR

内容的提问来源于stack exchange,提问作者LordoftheVoid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:19:01