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

如何在WildFly 9中通过Java访问未解压WAR内的JSON资源文件

Troubleshooting Accessing JSON Resources in Unexploded WAR on WildFly 9

Hey there, let's work through this issue together—unexploded WARs can sometimes throw curveballs with resource access, but we've got several actionable fixes to try:

1. Verify JSON File Placement & Accessibility Rules

  • First, double-check where your JSON file lives in the WAR:
    • If it's inside WEB-INF/ or WEB-INF/classes/, you can't access it directly via a browser URL—WildFly blocks direct external access to the WEB-INF directory for security reasons. Move it to the WAR root (or a subdirectory outside WEB-INF) if you need to hit it directly.
    • If it's in the WAR root or a public subdir, make sure the path matches what you're using in your URL.

2. Confirm Your Access URL is Correct

Let's say your WAR's context root is myapp, and your JSON file is at myapp/data/config.json in the WAR structure. Your full access URL should look like:
http://your-server:8080/myapp/data/config.json

  • If you didn't set a custom context root, WildFly uses the WAR filename by default (e.g., myapp.war becomes /myapp).

3. Check WildFly Deployment Configuration

Ensure WildFly is properly set up to handle zipped WARs:

  • Open your standalone.xml (or domain.xml for domain mode) and locate the <deployment-scanner> section. Verify these settings:
    <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" 
                         scan-interval="5000" auto-deploy-zipped="true"/>
    
    The auto-deploy-zipped="true" flag is critical here—it tells WildFly to deploy zipped WARs without unpacking them.

4. Fix Programmatic Resource Access (If Using Java Code)

If you're trying to read the JSON file from your application code, never use absolute file paths—they won't work with unexploded WARs. Instead, use the class loader:

// For a file in WEB-INF/classes/config.json
InputStream jsonStream = getClass().getResourceAsStream("/config.json");

// For a file in WEB-INF/classes/data/config.json
InputStream jsonStream = getClass().getResourceAsStream("/data/config.json");

This method works regardless of whether the WAR is exploded or not.

5. Clean WildFly Cache & Redeploy

Cached deployment data can sometimes cause access issues:

  1. Stop WildFly completely.
  2. Delete the contents of standalone/tmp and standalone/data/content (these directories hold temporary deployment files).
  3. Restart WildFly and redeploy your WAR.

6. Check File Permissions

Make sure the user running WildFly has read permissions on your zipped WAR file. If the server can't read the WAR, it won't be able to access any resources inside it.

Give these steps a try—one of them should get your JSON resources accessible again!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:08:39