6

Im running a score and scoreservices class in eclipse dynamic project i created a webservice and ran it but it gives me errors saying The package javax.xml.namespace is accessible from more than one module: <unnamed>, java.xml. Dont know what to do with this output

score class

package startAgain;

import javax.xml.bind.annotation.*;
@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
public class Score {
public int wins, losses, ties;
}   

ScoreServies class

package startAgain;

import javax.ejb.*;
import javax.jws.*;
@Stateless
@WebService
public class ScoreService {
private static Score score = new Score();
public Score updateScore (int wins, int losses, int ties) {
    score.wins = wins;
    score.losses = losses;
    score.ties = ties;
    return score;
}
@WebMethod(operationName="resetScore")
public void reset() {
score.wins = score.losses = score.ties = 0;
}
        public Score getScore() { return score; }
        public int increaseWins() { return score.wins++; }
        public int increaseTies() { return ++score.ties; }
        public int increaseLosses() { return ++score.losses; }
        public int getWins() { return score.wins; }
        public int getTies() { return score.ties; }
        public int getLosses() { return score.losses; }

}

Any help on this on clearing this package javax.xml.namespace error Thanks

howlger
  • 31,050
  • 11
  • 59
  • 99
dave
  • 103
  • 1
  • 1
  • 8
  • If your project has a module-info.java file that you did not intentionally create, delete it. – nitind May 02 '20 at 02:01
  • 1
    The system library contains the module `java.xml` with the package `javax.xml.namespace`, but the package `javax.xml.namespace` is also somewhere contained on the classpath (``): in a dependency on the classpath or in your code not having a `module-info.java`. This is not allowed in Java 9 and higher. – howlger May 02 '20 at 08:36
  • @nitind there is no mudule-info.java file created – dave May 02 '20 at 09:49
  • @howlger where would i add module-info.java then to work around this issue – dave May 02 '20 at 09:50
  • 1
    @dave There is no workaround for this. Use Java 8, get rid of the dependency (or the package in your code) or exclude the `java.xml` system module (but I guess, both are need). In most cases the solution is to update the dependencies (assuming the package `javax.xml.namespace` is not used in your code). – howlger May 02 '20 at 13:05
  • @dave Did you get a solution or workaround for this? – Ayush Kumar Aug 11 '21 at 12:44
  • It sounds like what has been described here: https://stackoverflow.com/a/53824670/1016514 – Hans Dec 13 '21 at 09:46

1 Answers1

1

I faced the same issue with Eclipse few days ago.

So I tried to find the library that proposed the same package (javax.xml.namespace) already available in the javax.xml Java built-in module, provoking package duplication.

In my case it was a library under the name stax-api. I just removed it from the build, like this:

dependencies {
...
  configurations {
       compile.exclude group: 'stax', module: 'stax-api'
  }
...
}
Hans
  • 2,419
  • 2
  • 30
  • 37
BryZe NtZa
  • 31
  • 1
  • 4