0

I have the following pom.xml :

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>xml-parsing</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>xml-parsing</name>
  <!-- FIXME change it to the project's website -->
  <url>https://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.xerces</groupId>
      <artifactId>org.apache.xerces</artifactId>
      <version>2.12.2</version>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

For some reason, maven is unable to find the Xerces dependency. Running the install method inside Lifecycle and the command mvn clean install shows the following error:

Failed to execute goal on project xml-parsing: Could not resolve dependencies for project org.example:xml-parsing:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.apache.xerces:org.apache.xerces:jar:2.12.2, org.apache.xerces:xml-apis:jar:2.11.0-20110622: Could not find artifact org.apache.xerces:org.apache.xerces:jar:2.12.2 in central (https://repo.maven.apache.org/maven2)  

Not sure why this could be the case, probably I am missing something in the pom.xml

Things I tried:
I added another dependency of the groupId org.apache.xerces -> unresolved
Then I added apache-commons dependency and this got resolved.
Not sure what could be the reason for this.

pensee
  • 375
  • 1
  • 10
  • try https://stackoverflow.com/questions/50946420/could-not-transfer-artifact-https-repo-maven-apache-org-maven2-received-fat – Saurabh Jhunjhunwala Aug 18 '23 at 12:03
  • Does this answer your question? [Dealing with "Xerces hell" in Java/Maven?](https://stackoverflow.com/questions/11677572/dealing-with-xerces-hell-in-java-maven) – k314159 Aug 18 '23 at 12:21
  • @Michael It's not wrong, it does exist here: https://mvnrepository.com/artifact/org.apache.xerces/org.apache.xerces/2.12.2 – pensee Aug 18 '23 at 13:17
  • @Michael Nice, I see that the Usage and Ranking is too low. – pensee Aug 18 '23 at 13:26
  • @Michael I wanted to use the apache xerces to pass a .rnc file and set a schema like: ` SAXParserFactory factory = SAXParserFactory.newInstance(); Schema schema = factory.setSchema();` Could you guide how should I construct the Schema here – pensee Aug 18 '23 at 13:31
  • 1
    @Michael you can post your answer. I will mark it as a solution – pensee Aug 18 '23 at 13:40
  • @pensee I haven't used Xerces in a long time, so I can't help with that one. I've found ChatGPT quite good for those kind of questions personally. – Michael Aug 18 '23 at 13:49

2 Answers2

1

Your group ID and artifact ID seem wrong.

There is a version of Xerces hosted under those IDs, but it's within an obscure repository called "Clazzes" which only hosts a single version of it: 2.12.2. This a strong clue that this isn't the source of truth, along with the fact that the number of usages is very low.

You could rely on that, but it would require adding a <repository> definition to Maven, and there's no guarantee that future version of Xerces will be uploaded there.

The "real" Xerces should use these coordinates, which I found just by searching for "Xerces" on mvnrepository.com

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version><!-- change me, e.g. to 2.12.2--></version>
</dependency>
Michael
  • 41,989
  • 11
  • 82
  • 128
0

The reason that does not work is, that the Artifacts are simply not in the default repository. If you follow the link https://repo.maven.apache.org/maven2 and search for them you won't find them --> https://repo.maven.apache.org/maven2/org/apache/ You can always check Maven Repository Sites like https://mvnrepository.com/artifact/org.apache.xerces/org.apache.xerces to check for which version of an Artifact is available and where. For example your org.apache.xerces:org.apache.xerces:jar:2.12.2 is available only in the Clazzes repository: https://mvnrepository.com/artifact/org.apache.xerces/org.apache.xerces?repo=clazzes-maven

Apache-commons probably has the dependency bundled (you could check the maven Repository for that).

So if you don't want the apache-commons and just the xerces dependencies, then you have to add the repository in the pom file --> https://maven.apache.org/guides/mini/guide-multiple-repositories.html

UPDATE: This is what it could look like in the pom file at the end:

<repositories>
    <repository>
      <!-- For Xerces stuff -->
      <id>clazzes</id>
      <name>Clazzes Repository</name>
      <url>https://maven.clazzes.org/</url>
    </repository>
  </repositories>
Ismael
  • 11
  • 2
  • I am not sure what id and URL to add in repository tag – pensee Aug 18 '23 at 13:16
  • @pensee FYI, though not what you want to do in this case, if you click on the repository on that website, it will list the URL (https://mvnrepository.com/repos/clazzes-maven) -> `https://maven.clazzes.org/`. Repo ID in Maven is mostly arbitrary, so in this case "clazzes" would do. – Michael Aug 18 '23 at 13:30