JSR 181: error in pom.xml - java

I got a strange error in my pom.xml. Maven (I'm using Maven 2) is signaling Missing artifact javax.jws:jsr181:jar:1.0, even if I get the corresponding dependency in my pom.xml:
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181</artifactId>
<version>1.0</version>
</dependency>
What could possibly be the cause of this error?

Ok, I found the solution to the problem. I think the way to find it could be interesting, too.
When I look on mvnrepository.com, the pom file on the repository pointed on an URL on bea.com, which is not available anymore. So I had to change to the maintenance release, like Brian Agnew suggested. And of course, update some other dependencies in my pom.xml, which needed the obsolete version in their own dependencies. Maven comes with a cost...
<!-- https://mvnrepository.com/artifact/javax.jws/jsr181-api -->
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0-MR1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.1-1</version>
<exclusions>
<exclusion>
<groupId>javax.jws</groupId>
<artifactId>jsr181</artifactId>
</exclusion>
</exclusions>
</dependency>

Looking at my repository, I think you want:
<dependency>
<groupId>sun-jaxws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0</version>
</dependency>

Related

Maven build failed due to JDT dependencies - No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0)

Today when I tried to install my maven project, I get an error due JDT dependencies and here is the report information:
Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.
[ERROR] Failed to execute goal on project redundantcheck:
Could not resolve dependencies for project edu.fudan.selab:redundantcheck:jar:1.0-SNAPSHOT:
Failed to collect dependencies at org.eclipse.jdt:org.eclipse.jdt.core:jar:3.20.0 ->
org.eclipse.platform:org.eclipse.core.resources:jar:3.12.0 ->
org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 ->
org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 ->
org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 ->
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]
I tried to add 1.1.0 org.osgi.service:org.osgi.service.prefs to the project, but still can't solve this problem. To avoid dependency update, I specied almost every version of the dependencies, but still encounter this error today. Here is my pom.xml:
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.20.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.commands</artifactId>
<version>3.9.800</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.contenttype -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.contenttype</artifactId>
<version>3.7.900</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.filesystem -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.filesystem</artifactId>
<version>1.7.700</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.jobs -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.jobs</artifactId>
<version>3.10.1100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.resources</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.runtime -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
<version>3.20.100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.equinox.common -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.14.100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.osgi -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.16.200</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.text -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.text</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.expressions</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.app</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.registry</artifactId>
<version>3.11.0</version>
</dependency>
</dependencies>
Is there anyway to solve this problem?
EDIT: The issue is known by the project team and tracked as eclipse-equinox/equinox.bundles#54 on GitHub.
The dependency:
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.0</version>
Which is one of your transitive dependency, references this dependency in its dependencies list:
<dependency>
<groupId>org.osgi.service</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
<version>[1.1.0,1.2.0)</version>
</dependency>
Source: org.eclipse.equinox.preferences-3.10.0.pom on maven central.
It is a mistake. As Maven tells you, this does not exist:
Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.
It should have been:
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
<version>[1.1.0,1.2.0)</version>
</dependency>
Which exists (note the different groupId).
Because you are not fixing the dependencies you are consuming in your project, and because the dependencies are using version ranges, suddenly you got a new version.
By the way as beingnurd has noted, there is now the newer version 3.10.1 of org.eclipse.equinox.preferences where this wrong dependency is fixed (see org.eclipse.equinox.preferences-3.10.1.pom).
If you continue to use always the newest dependency of the compatible range, the problem will be solved for you.
Now if we take a step back:
You are trying to use following JDT version:
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.20.0</version>
</dependency>
This corresponds to the Eclipse Version 2019-12 (also called 4.14 internally).
Your problem is that the eclipse projects (org.eclipse.jdt.core and all the dependencies) are using version ranges.
If you look at the org.eclipse.jdt.core dependencies declarations:
org.eclipse.platform:org.eclipse.core.resources:[3.12.0,4.0.0)
org.eclipse.platform:org.eclipse.core.runtime:[3.13.0,4.0.0)
org.eclipse.platform:org.eclipse.core.filesystem:[1.7.0,2.0.0)
org.eclipse.platform:org.eclipse.text:[3.6.0,4.0.0)
If you don't do anything, Maven always takes the latest:
Today (June 2022) this would be:
org.eclipse.core.resources: 3.16.100
org.eclipse.core.runtime: 3.24.100
org.eclipse.core.filesystem: 1.9.300
org.eclipse.text: 3.12.0
When the library was published (December 2019) this was:
org.eclipse.core.resources: 3.13.600
org.eclipse.core.runtime: 3.17.0
org.eclipse.core.filesystem: 1.7.600
org.eclipse.text: 3.10.0
And of course this is recursive, you need to do this for all the dependencies.
Letting Maven choose always the latest is problematic:
It prevents you creating reproducible build, because the dependencies picked by maven depends from what is available on maven central on that day.
You need to solve conflicts.
You are potentially the first trying out a combination.
This is why I always use a set of projects that were released together. By the way this is also how the Eclipse project itself is doing it (by using P2 update sites and target platform).
I am publishing Maven BOM files to fix the versions: ECentral project
This is how you can do it:
<repositories>
<repository>
<id>ecentral</id>
<url>https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>fr.jmini.ecentral</groupId>
<artifactId>eclipse-platform-dependencies</artifactId>
<version>4.14</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<!-- no version needed here, because it is defined in the BOM -->
</dependency>
</dependencies>
Because I ran into this problem today too, but via plugin sub-dependency, my temporary solution is to download the regular org.osgi:org.osgi.service.prefs:jar:1.1.2 and install it in the local repository as org.osgi.service:org.osgi.service.prefs:jar:1.1.2.
You can exclude the dependency like this :
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.24.0</version>
<exclusions>
<exclusion>
<groupId>org.osgi.service</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
</exclusion>
</exclusions>
so the reason for this failure is dependency
<groupId>org.osgi.service</groupId> <artifactId>org.osgi.service.prefs</artifactId>
but the group org.osgi.service doesn't exists, instead it is only org.osgi
so dependency should look
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
I have got the same problem today in our SpringBoot project 1.5.25 with org.hibernate:hibernate-tools:jar:5.0.6.Final
The error message as follow:
# Failed to collect dependencies at org.hibernate:hibernate-tools:jar:5.0.6.Final ->
# org.eclipse.jdt:org.eclipse.jdt.core:jar:3.12.2 ->
# org.eclipse.platform:org.eclipse.core.resources:jar:3.11.1 ->
# org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 ->
# org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 ->
# org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 ->
# org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]
I use the private nexus, to resolve this problem, i added a proxy maven2 (maven-ecentral) repo pointed to https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo , thanks #Jmini
then added the follow lignes in the pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>fr.jmini.ecentral</groupId>
<artifactId>eclipse-platform-dependencies</artifactId>
<version>4.14</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>ecentral</id>
<url>https://nexus.xxxx.xxx/repository/maven-ecentral/</url>
</repository>
</repositories>
Reload your project with IDEA, it should work.
Another solution is using exclusions
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>${hibernate-tools.version}</version>
<!-- exclure the old org.eclipse.platform -->
<exclusions>
<exclusion>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- the 3.10.1 org.eclipse.platform fixed the pb -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.1</version>
</dependency>
Even I have been facing this problem since today, it was working fine till yesterday.
Finally what I found was that pom of org.eclipse.equinox.preferences:3.10.0 group id mentioned as org.osgi.service, but the artifact is located in repo1.maven.org at org/osgi, there is no service folder in it.
I changed dependency group id to org.osgi in the pom of org.eclipse.equinox.preferences and then it worked.
--EDIT--
I can see a new version of 3.10.1 added in repo which has the group id corrected to org.osgi instead of org.osgi.service
I ran into this problem with a maven plugin (net.revelc.code.formatter). We use it from another maven plugin that generates code. Since it is just a formatter for generated code, my solution was to drop the usage of the formatter plugin. Obviously I couldn't use the above solutions, because I don't want to fork the formatter code.

Couldn't understand managed version under Maven dependency hierarchy

In my pom.xml, I have a SikuliX Jar which has a transitive dependency on jna-platform.
As seen in below image, version 4.5.2 has overrided version 5.4.0.
But i dont understand, how this version is overrided as i have not specified any dependency for jna-platform. I had also verified that no any there dependency is fetching this jar.
Please help me understand why this is happening. Any detailed document is well appreciated.
Related dependencies:-
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>2.0.4</version>
<exclusions>
<exclusion>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
</exclusion>
</exclusions>
</dependency>
Thanks
Since you were using spring boot, as suggested here (there's also the reason of this behaviour):
java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/SspiUtil$ManagedSecBufferDesc #882
you can change your order of dependencies, or specify the exact version, like this:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.4.0</version>
</dependency>
or add this property:
<jna.version>5.4.0</jna.version>

Maven commons-configuration2

I am using Apache commons-configuration2 in one of my projects. Recently, I decided to let Maven manage my projects. Which works fine, except for commons-configuration2; I am not able to find that dependency on the Maven repo. Even when looking just for commons-configuration, not commons-configuration2, none of the results I am getting are org.apache.commons.
What am I doing wrong?
That's because, version 1.x of the artifact commons-configuration was really under the commons-configuration group. You can find the latest release version, 1.10, of that artifact in the repo.
It was only after it became commons-configuration2 (technically an entirely different Maven artifact of the same project), it was grouped under org.apache.commons. You don't see them in the maven repo (the RELEASE repo that is) probably because it's still a SNAPSHOT. You can still find the artifact in the SNAPSHOT repo.
See the project summary and release history for more information.
Current workaround solution:
Download Apache Commons Configuration 2.0 and got the commons-configuration2-2.0-beta2.jar
Add the commons-configuration2-2.0-beta2.jar to external library
Add the needed dependency in maven.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>xml-resolver</groupId>
<artifactId>xml-resolver</artifactId>
<version>1.2</version>
</dependency>
commons-configuration2 now available on Maven Central: http://mvnrepository.com/artifact/org.apache.commons/commons-configuration2
A bug has been filed against the documentation (or against the repo, depending on your view). Apparently, commons-configuration2 will not be pushed to Maven central until final release, but the documentation on their website is automatically generated and points you to a non-existent repository. This will be fixed when a final release is done.
commons-configuration2-2.1 is now available in the Maven repository.

maven: how to disable certain dependencies?

Well, I'm not talking about the well-known commons-logging problem, I know I can disable it by setting the 99.0-does-not-exist version.
My problems is, some packages are contained in different dependencies, say, aspectjlib is contained both in org.aspectj:aspectjlib and aspectj:aspectjlib. In some cases, transitive dependencies may introduce the two jars at the same time, while of different versions, e.g., org.aspectj:aspectjlib:1.7.3, aspectj:aspectjlib:1.6.1. And mis-loading aspectj:aspectjlib:1.6.1 accidentally is not my intention. So is there a way like commons-logging that I can disable aspectj:aspectjlib completely?
I tried the same trick using 99.0-does-not-exist, only to find an error from maven:
[ERROR] Failed to execute goal on project XXX: Could not resolve
dependencies for project XXX:jar:1.0.0-SNAPSHOT: The following
artifacts could not be resolved:
aspectj:aspectjlib:jar:99.0-does-not-exist,
aspectj:aspectjrt:jar:99.0-does-not-exist,
aspectj:aspectjweaver:jar:99.0-does-not-exist: Could not find artifact
aspectj:aspectjlib:jar:99.0-does-not-exist in tbmirror
(http://mvnrepo.taobao.ali.com/mvn/repository) -> [Help 1]
Well, although some repositories do provide 99.0-does-not-exist for logging system dependencies like log4j, slf4j-log4j, commons-logging, etc., this is not a universal solution.
I find a solution to do this: use 'provided' scope.
To clarify, in my example above, I have two conflicting dependencies: org.aspectj:aspectjlib:1.7.3, aspectj:aspectjlib:1.6.1, I want to disable aspectj:aspectjlib:1.6.1, I only need to put this in top-level pom:
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjlib</artifactId>
<version>1.6.1</version>
<scope>provided</scope>
</dependency>
in this way, aspectj:aspectjlib:1.6.1 will never appear in the final built lib.
You can use Maven's dependency exclusions to eliminate the version you don't want. Using your example:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>includes-new-aspectj</groupId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>includes-old-aspectj</groupId>
<exclusions>
<exclusion>
<groupId>org.aspectj<groupId>
<artifactId>aspectjlib</artifactId>
<exclusion>
</exclusions>
</dependency>
</dependencies>
Alternatively, you can simply pin the version you desire using dependency management:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjlib</artifactId>
<version>1.7.3</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>includes-new-aspectj</groupId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>includes-old-aspectj</groupId>
</dependency>
</dependencies>
If you are not sure which dependencies include which versions, you can use this to discover that info:
mvn dependency:tree -Dincludes='org.aspectj:aspectjlib'
There is no 99.0 version for aspectj:aspectjlib, your project is configured to use wrong version, check for 99.0 in your pom.xml

Writing Maven Dependency for javax.persistence

Can someone help me write the dependency for javax.persistence. I have googled it but nothing worked.
I bumped into this page that gives some details on how to write the dependency, but yet i am unable to write it. Can someone help me out?
This is the one for javax.persistence:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
and this is for the whole Java EE 6 stack:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
Edit
Note that I specified a provided scope here, which means that your dependency is available at compile- and test-time, but will not be packaged into your artifacts. This is usually needed if you want to deploy your artifacts in an application server, since they provide their own implementation of the api.
And add this dependency in your pom.xml:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
That "Coping with Sun JARs" page might be a little outdated, this JAR is available in the Maven Central Repository
Updated link:
https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api/2.2 is here.
and the maven dependency is as below:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
For the latest versions javax.persistance is not working instead of that we can use jakarta.persistence to create an entity or resolve the error Cannot resolve symbol 'Entity'. For that need to add the dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.6.Final</version>
<type>pom</type>
</dependency>

Categories

Resources