IntelliJ项目导入Eclipse后部署Weblogic报ServletConfig类找不到
ClassNotFoundException: ServletConfig When Deploying Eclipse Project to WebLogic 12.1.2 Hey, let's work through this error together—this is a super common issue when moving projects between IDEs and deploying to WebLogic, so we can narrow it down step by step. The ServletConfig class is part of the standard Servlet API, which WebLogic already includes out of the box, so the problem almost always boils down to conflicting dependencies or misconfigured project settings.
Step 1: Check for Conflicting Servlet API Dependencies
WebLogic ships with its own copy of the Servlet API (located in WL_HOME/server/lib/servlet-api.jar), so your project should not include this jar in its deployed artifacts—doing so causes a classloader conflict where WebLogic tries to load the wrong version of ServletConfig.
For non-Maven projects in Eclipse:
- Right-click your project → Properties → Java Build Path → Libraries.
- Look for any
servlet-api.jarorjavax.servlet-api.jarentries. If you see one:- Go to Deployment Assembly (also in Project Properties) and remove the corresponding entry so it doesn't get packaged into your WAR/EAR.
- Alternatively, replace it with Eclipse's built-in "Server Runtime" library:
- Click Add Library → Server Runtime → Select your WebLogic 12.1.2 server → Finish. This ensures you use the exact Servlet API version WebLogic provides, and it won't be deployed with your app.
For Maven projects:
- Open your
pom.xmland make sure the Servlet API dependency has<scope>provided</scope>:<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <!-- Match WebLogic 12.1.2's Servlet version (3.0) --> <scope>provided</scope> </dependency>
The
providedscope tells Maven the jar is supplied by the server, so it won't be included in the final build.- Open your
Step 2: Verify Eclipse Dynamic Web Project Configuration
Eclipse's project facets need to align with WebLogic's supported specs:
- Right-click your project → Properties → Project Facets.
- Ensure:
- Dynamic Web Module is set to 3.0 (WebLogic 12.1.2 supports Servlet 3.0; higher versions like 3.1 won't work).
- If you're using Struts, make sure any related facets (like Struts 2) are enabled and using a version compatible with Servlet 3.0 (Struts 2.3+ works well).
- Check your
web.xmlto confirm it's using the correct Servlet 3.0 schema:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <!-- Your web app config here --> </web-app>
Step 3: Adjust WebLogic Classloader Settings
If dependencies are still conflicting, tweak WebLogic's classloader behavior to prioritize its own libraries:
- Create or edit
WEB-INF/weblogic.xmlin your project (this file controls WebLogic-specific settings):<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd"> <container-descriptor> <!-- Tell WebLogic to load its own libraries first, avoiding conflicts --> <prefer-web-inf-classes>false</prefer-web-inf-classes> </container-descriptor> </weblogic-web-app> - Also, check your WebLogic domain's
libdirectory (DOMAIN_HOME/lib)—if there's a strayservlet-api.jarhere, delete it. This directory's jars are loaded globally and can cause conflicts.
Step 4: Struts-Specific Checks
Since you mentioned using Struts, make sure it's configured correctly:
- Use a Struts version compatible with Servlet 3.0 (Struts 2.3.x or later is recommended). Older versions like Struts 2.2 might have issues with Servlet 3.0 annotations or classloading.
- Verify your
struts.xmldoesn't have any custom interceptors or actions that incorrectly referenceServletConfig—Struts typically handles Servlet API interactions via its own context, so manual references might be a red flag.
Step 5: Clean and Redeploy
Old cached files can cause weird issues, so do a full clean:
- In Eclipse: Go to Project → Clean..., select your project, and click OK to wipe compiled classes.
- On WebLogic:
- Stop the server.
- Delete the
tmpandcachedirectories underDOMAIN_HOME/servers/[your-server-name]/. - Start the server back up.
- Re-deploy your project from Eclipse to WebLogic.
Most of the time, fixing the Servlet API dependency scope (marking it as provided or using the server runtime library) resolves this error. If you're still stuck, check the full WebLogic logs for more details—sometimes there are hidden dependency conflicts that the truncated stacktrace doesn't show.
内容的提问来源于stack exchange,提问作者noobie

