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

求助:Gradle构建中使用axis2-java2wsdl-maven-plugin生成WSDL

Hey there! Let's work through how to generate WSDL from your Java classes in a Gradle war project. You mentioned trying the axis2-java2wsdl-maven-plugin but needing clear usage examples—here are a couple of solid approaches, including direct tooling and plugin integration:

Approach 1: Directly Use Axis2's Java2WSDL Tool with Gradle JavaExec

This is the most straightforward method, as it bypasses Maven plugin adaptation and calls Axis2's core WSDL generation tool directly via a Gradle JavaExec task.

  1. First, add the Axis2 Java2WSDL dependency to your buildscript (since this is a build-time tool):
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.apache.axis2:axis2-java2wsdl:1.6.2'
    }
}
  1. Define a Gradle task to generate WSDL:
task generateWSDL(type: JavaExec) {
    // Point to Axis2's Java2WSDL main class
    main = 'org.apache.axis2.wsdl.Java2WSDL'
    
    // Include buildscript dependencies + your compiled project classes
    classpath = buildscript.configurations.classpath + files(sourceSets.main.output.classesDirs)

    // Configure generation parameters (adjust these to match your project)
    args = [
        '-cn', 'com.yourcompany.yourproject.YourWebServiceClass', // Full class name of your service
        '-o', "${buildDir}/generated/wsdl", // Output directory for WSDL
        '-tn', 'http://yourcompany.com/webservices', // Target namespace for the WSDL
        '-sn', 'YourServiceName', // Name of the service in the WSDL
        '-pn', 'YourServicePort' // Name of the service port
    ]

    // Ensure output directory exists before running
    doFirst {
        file("${buildDir}/generated/wsdl").mkdirs()
    }
}

// Make the war build depend on WSDL generation (so WSDL is created before packaging)
war.dependsOn generateWSDL
  1. To see all available parameters for Java2WSDL, run this command in your terminal:
java -cp path/to/axis2-java2wsdl-1.6.2.jar org.apache.axis2.wsdl.Java2WSDL -help

Approach 2: Integrate the axis2-java2wsdl-maven Plugin in Gradle

If you specifically want to use the Maven plugin, you can configure Gradle to invoke it using the Maven plugin bridge:

  1. Add the Maven plugin and dependencies to your build.gradle:
plugins {
    id 'war'
    id 'maven'
}

repositories {
    mavenCentral()
}

dependencies {
    // Your project's runtime dependencies (adjust as needed)
    implementation 'org.apache.axis2:axis2-adb:1.6.2'
    // Build-time dependency for the Maven plugin
    build 'org.apache.axis2:axis2-java2wsdl-maven-plugin:1.6.2'
}
  1. Define a task to trigger the Maven plugin's java2wsdl goal:
task generateWSDL(type: org.gradle.api.tasks.Maven) {
    dependsOn classes // Ensure your Java classes are compiled first
    goals = ['org.apache.axis2:axis2-java2wsdl-maven-plugin:1.6.2:java2wsdl']
    
    // Pass configuration parameters as system properties
    systemProperties = [
        'axis2.java2wsdl.className': 'com.yourcompany.yourproject.YourWebServiceClass',
        'axis2.java2wsdl.outputDirectory': "${buildDir}/generated/wsdl",
        'axis2.java2wsdl.targetNamespace': 'http://yourcompany.com/webservices',
        'axis2.java2wsdl.serviceName': 'YourServiceName'
    ]
}

war.dependsOn generateWSDL

Alternative: Use JAX-WS wsgen (If Your Project Uses JAX-WS)

If your web service uses standard JAX-WS annotations (like @WebService), you can use JAX-WS's built-in wsgen tool instead:

task generateWSDL(type: JavaExec) {
    main = 'com.sun.tools.ws.WsGen'
    classpath = sourceSets.main.runtimeClasspath // Includes your classes + JAX-WS dependencies

    args = [
        '-cp', sourceSets.main.output.classesDirs.asPath,
        '-wsdl', // Generate WSDL
        '-d', "${buildDir}/generated/wsdl",
        'com.yourcompany.yourproject.YourWebServiceClass'
    ]
}

war.dependsOn generateWSDL

Add this dependency if you don't already have JAX-WS in your project:

implementation 'com.sun.xml.ws:jaxws-rt:2.3.5'

Key Notes

  • Always ensure your service classes are compiled before generating WSDL (hence the dependsOn classes in tasks).
  • If your service uses custom annotations or complex types, double-check that the classpath includes all necessary dependencies (like JAX-WS or Axis2 libraries).
  • You can customize the output directory and WSDL parameters to match your project's requirements.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:40:09