生成WAR包时遇com.sun.xml.internal.ws.developer包不存在错误求助
Hey there, let's work through this problem you're facing with the WSBindingProvider class and your WAR build. I've got a couple of solid solutions for you, both fixing the compile error upfront and modifying the code post-WAR if you need that.
com.sun.xml.internal.ws.developer.WSBindingProvider Compile Error First, let's address why this error pops up: the com.sun.xml.internal packages are internal JDK APIs, meaning they're not meant for public use—different JDK versions might hide or remove them entirely, which breaks your build. Here's how to fix it properly:
Option 1: Switch to the Public API (Recommended)
The public, supported version of this class lives in com.sun.xml.ws.developer.WSBindingProvider (note the missing internal). To use this:
- Update your import statement to remove
internal:import com.sun.xml.ws.developer.WSBindingProvider; - Add the official JAX-WS runtime dependency to your build file:
- For Maven, add this to your
pom.xml:<dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>2.3.3</version> <!-- Use the latest compatible version --> <scope>provided</scope> <!-- Mark as provided if your server already includes it --> </dependency> - For Gradle, add this to your
build.gradle:implementation 'com.sun.xml.ws:jaxws-rt:2.3.3'
- For Maven, add this to your
This ensures you're using a supported API that won't break across JDK versions.
Option 2: Force Access to Internal JDK APIs (Not Recommended)
If you absolutely need to keep using the internal package (I'd advise against this for long-term compatibility), you can tell your compiler to allow access to internal JDK classes:
- For Maven, update the
maven-compiler-pluginin yourpom.xml:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <compilerArgs> <arg>-XDignore.symbol.file</arg> </compilerArgs> </configuration> </plugin>
This skips the JDK's symbol file check, letting you compile against internal APIs. Just remember this could break if you upgrade your JDK later.
If you already have a WAR and need to comment out the WSBindingProvider code without rebuilding from source, here's how to do it:
Extract the WAR contents
Use a tool likeunzip(or any archive manager) to unpack the WAR into a directory:unzip your-project.war -d war-extractedLocate the compiled class file
Navigate towar-extracted/WEB-INF/classesand find the.classfile corresponding to your Java class (e.g.,com/example/MyService.classif your class iscom.example.MyService).Decompile the class to Java code
Use a decompiler tool like JD-GUI (local, offline tool is safest) to convert the.classfile back into readable Java code. Once decompiled, comment out the import statement and any code that usesWSBindingProvider.Recompile the modified Java file
Compile the updated.javafile, making sure to include all your project's dependencies (fromWEB-INF/lib):javac -cp "war-extracted/WEB-INF/lib/*:war-extracted/WEB-INF/classes" com/example/MyService.javaReplace the original class file
Copy the newly compiled.classfile back into thewar-extracted/WEB-INF/classesdirectory, overwriting the original.Recreate the WAR file
Navigate back to the extracted directory and re-zip everything into a new WAR:cd war-extracted zip -r ../your-modified-project.war .
A quick note: This is a temporary fix. Whenever possible, modify the source code and rebuild the WAR properly—it's easier to maintain and less error-prone.
内容的提问来源于stack exchange,提问作者Juan Teheran

