IntelliJ not recognizing/forgetting to use xml context files

已回答

I have an old Eclipse project. We use developer profiles to store our own context files and configurations. I have my profile folder marked as resources. In my profile, I have another folder containing 2 xml files necessary for running part of the application. Fairly frequently, IntelliJ stops recognizing the files, though I made no changes to the files or their location. The app will start up, but when I navigate to the area of the app requiring the files, I get an error. The only thing that works is deleting them and re-adding them and refreshing the project, and eventually it picks them up. Sometimes it takes 10+ attempts at deleting/re-adding for them to get used. Reindexing doesn't work. Invalidating caches doesn't work. Running Ant compilation/clean tasks doesn't work. This is incredibly frustrating and I'm wasting a lot of time trying to just get the project to run normally. 

0

Please go through below checklist and see if it could help.

• Mark resources correctly:

In Project Structure → Modules → Sources, ensure your profile folder is under the module’s content root and marked as Resources. No parent/child should be Excluded.
    
• Ensure XMLs are copied:

Settings → Compiler → Resource patterns should include `*.xml`. Then do Build → Rebuild Project.
    
• Classpath check:

Your Run Configuration → Use classpath of module must point to the module that contains your profile resources.
    
• File flags:

Right-click each XML → File Properties → make sure Exclude from compilation is off.
    
• No overlapping content roots:

Remove duplicate or overlapping module roots (common after Eclipse import).
    
• If Spring XMLs:

Add a Spring facet and register those XMLs under it.

0

Bond Han Hi. Thank you so much for your reply. I confirmed the resources and root are marked correctly and the classpath points to my profile. I have used the Spring facet before, but I wasn't at the moment, so I added those. I also made sure xml was marked for use by the compiler. Unfortunately, none of those things worked. 

0

Erin Have you checked from run configuraiton side also?

  1. Open Run/Debug Configurations.
  2. Check:
    • Use classpath of module → should be the module where your profile resources live.
    • No custom “Override classpath” or custom working directory that would bypass the normal output.
0

Bond Han Hello again. I am deploying the web app using Tomcat 9.0.100. Under the run configuration, I don't see any settings regarding classpath. Can you point me in the right direction?

0

If you’re deploying via a Tomcat run configuration, the classpath is controlled by the artifact, not by the run configuration itself. 

Check if the XML files are actually packaged 

  • Go to Build → Build Artifacts… and build the artifact your Tomcat config uses (e.g., xxx:war exploded). 
  • Open the artifact output and verify the two XML files appear under WEB-INF/classes/. 

Confirm the correct module is included in the artifact 

  • Open File → Project Structure → Artifacts. 
  • Select the artifact and make sure the module containing your profile resources is included as Module Output / Module Resources. 
  • Add it if missing.
0

请先登录再写评论。