创建问题只是为了存储我的问题解决方案并使每个人都可以使用。 没有答案的最接近问题是apache cxf wsdl2java Failed to generate types->Access is denied
我尝试了此处提到的其他变通方法(总是= fork,在Windows中禁用磁盘缓存,关闭其他程序等),但没有任何帮助。因此,我花了很多时间尝试了解问题所在以及为什么cxf-codegen-plugin产生AccessDeniedException,例如:
[WARNING] Exception in thread "main" org.apache.cxf.tools.common.ToolException: Failed to generate types.
[WARNING] at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.generate(JAXBDataBinding.java:849)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.generateTypes(WSDLToJavaContainer.java:727)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:267)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:164)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:412)
[WARNING] at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
[WARNING] at org.apache.cxf.maven_plugin.wsdl2java.ForkOnceWSDL2Java.main(ForkOnceWSDL2Java.java:51)
[WARNING] Caused by: java.nio.file.AccessDeniedException: E:\Projects\example-project\example-module\target\generated-sources\cxf\com\package\SomeClass.java
[WARNING] at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
[WARNING] at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
[WARNING] at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
[WARNING] at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
[WARNING] at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
[WARNING] at java.nio.file.Files.newOutputStream(Files.java:216)
[WARNING] at org.apache.cxf.tools.util.OutputStreamCreator.createOutputStream(OutputStreamCreator.java:33)
[WARNING] at org.apache.cxf.tools.wsdlto.databinding.jaxb.TypesCodeWriter.openBinary(TypesCodeWriter.java:72)
[WARNING] at com.sun.codemodel.CodeWriter.openSource(CodeWriter.java:100)
[WARNING] at com.sun.codemodel.JPackage.createJavaSourceFileWriter(JPackage.java:490)
[WARNING] at com.sun.codemodel.JPackage.build(JPackage.java:441)
[WARNING] at com.sun.codemodel.JCodeModel.build(JCodeModel.java:311)
[WARNING] at com.sun.codemodel.JCodeModel.build(JCodeModel.java:301)
[WARNING] at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.generate(JAXBDataBinding.java:837)
[WARNING] ... 8 more
最后自己找到了解决方案。张贴在这里给大家。在我的情况下,从多个WSDL文件生成了多个端点,它们使用了XSD文件的共享集,即,使用的通用类以及在每个WSDL中生成的内容。因此,我将所有此类生成都提取到单独的步骤中-在端点生成之前生成它们。现在它们是由jaxb2-maven-plugin从这些XSD生成的,并且端点像以前一样通过cxf-codegen-plugin生成,但是为了避免生成这些类,将其排除在外,例如:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-common-jaxb-classes</id>
<phase>generate-sources</phase>
<configuration>
<arguments>
<argument>-Xnamespace-prefix</argument>
<argument>-XtoString</argument>
<argument>-Xequals</argument>
<argument>-XhashCode</argument>
<argument>-Xinheritance</argument>
<argument>-Xvalue-constructor</argument>
</arguments>
<sources>
<source>xsd/BaseTypes.xsd</source>
<source>xsd/EntityDocument.xsd</source>
<source>xsd/ScheduleDocument.xsd</source>
</sources>
<xjbSources>
<xjbSource>bindings/bindingsCommon.xjb</xjbSource>
</xjbSources>
<outputDirectory>${project.basedir}/target/generated-sources/jaxb/common</outputDirectory>
</configuration>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
<execution>
<id>generate-endpoints</id>
<phase>generate-sources</phase>
<configuration>
<fork>once</fork>
<encoding>UTF-8</encoding>
<defaultOptions>
<bindingFiles>
<bindingFile>bindings/bindingsCommon.xjb</bindingFile>
</bindingFiles>
<extraargs>
<extraarg>
-xjc-target,2.0,-Xnamespace-prefix,-XtoString,-Xequals,-XhashCode,-Xinheritance,-Xvalue-constructor
</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-nexclude</extraarg>
<extraarg>http://entsoe.etse.com/internal/type</extraarg>
<extraarg>-nexclude</extraarg>
<extraarg>http://some.site.com/internal/type/schedule</extraarg>
<extraarg>-nexclude</extraarg>
<extraarg>http://some.site.com/internal/type/entity</extraarg>
</extraargs>
</defaultOptions>
<wsdlRoot>wsdl</wsdlRoot>
<includes>
<include>*.wsdl</include>
</includes>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
希望这可以帮助某人节省时间自己寻找解决方案...