-1

I imported a gradle project on my eclipse. (I am using Java 11.) I had codes which uses jakarta.xml libraries.

import jakarta.xml.soap.*;

For it to function, I added Maven dependencies for jaxws-rt:

<dependencies>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-ri</artifactId>
        <version>3.0.0-M3</version>
        <type>pom</type>
    </dependency>
    <dependency>
  <groupId>jakarta.xml.ws</groupId>
  <artifactId>jakarta.xml.ws-api</artifactId>
  <version>2.3.3</version>
</dependency>
  </dependencies>

But when I try to generate the build, it shows following error:

error: package jakarta.xml.soap does not exist
import jakarta.xml.soap.*;

If I refresh the project as a Maven project the gradle feature gets disabled. If I run it as a gradle project, the maven dependencies get disabled. Can you please suggest how to run the build?

Matrix
  • 23
  • 7
  • I see nothing related to Gradle here. You are simply using Maven and you are looking for way to add a dependency which contains jakarta.xml.soap. Are you sure jakarta.xml.ws-api contains package jakarta.xml.soap? – Adrian Shum Aug 24 '20 at 02:53
  • Yes. Because the code works when Maven dependencies are set as above. But I need to integrate that piece of code with a gradle based project. – Matrix Aug 24 '20 at 02:57
  • What do you mean exactly by "integrate ... with a gradle based project"? Your project is defined as Gradle project or Maven? You just need to add the dependency to your project using the corresponding syntax, that's all. I guess what you need is to go thru basics of Gradle (or/and Maven) and have some basic understanding on how dependency management works – Adrian Shum Aug 24 '20 at 03:07
  • My project is defined as a Gradle project. I created a java class which needs to import jakarta.xml.soap library. To make this run I need to add Maven dependency in the gradle. But it is not working. Can you please suggest me an alternative? Someone suggested me to not add maven dependency; rather add following dependency in gradle: ``` compile group: 'com.sun.xml.ws', name: 'jaxws-ri', version: '3.0.0-M3', ext: 'pom' compile group: 'jakarta.xml.ws', name: 'jakarta.xml.ws-api', version: '2.3.3' ``` I tried it but it doesn't work. Can you please suggest any better alternative? – Matrix Aug 24 '20 at 03:16

1 Answers1

1

Do not manage separate dependencies on two different build platforms.

You will want to choose either Maven or Gradle. Having two build systems will cause unnecessary duplicate work and still requires continued maintenance. Going down this path will require you to manage two separate build files that are identical in nature. Every dependency in your gradle config will also need to be added to your maven config.

Instead of trying to create a pom.xml for the Maven build, you will want to determine the Gradle equivalent for the libraries you want to pull.

compile group: 'com.sun.xml.ws', name: 'jaxws-ri', version: '3.0.0-M3', ext: 'pom'
compile group: 'jakarta.xml.ws', name: 'jakarta.xml.ws-api', version: '2.3.3'
shinjw
  • 3,329
  • 3
  • 21
  • 42
  • Thanks. I refreshed the gradle project and added these dependencies in the build.gradle. But the code is still showing the same error error: package jakarta.xml.soap does not exist. Any suggestion? – Matrix Aug 24 '20 at 02:16
  • Which version of java are you running? – shinjw Aug 24 '20 at 02:21
  • I am using Java 11 – Matrix Aug 24 '20 at 02:23
  • `compile group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '2.3.3'` try this library. JAXB was removed from Java 11 which is what is causing that package does not exist error. – shinjw Aug 24 '20 at 02:24
  • Tried all three. Still not working. Not able to import the library. – Matrix Aug 24 '20 at 02:28
  • If I create a separate maven project then it works. But there is a third party requirement to use gradle. – Matrix Aug 24 '20 at 02:30
  • https://stackoverflow.com/questions/52502189/java-11-package-javax-xml-bind-does-not-exist Running your builds should still compile your application somewhat the same. There is likely some missing dependency. You can translate all of your dependencies in your POM into gradle dependencies. – shinjw Aug 24 '20 at 02:34