#XmlElement - OpenJDK using Maven - java

I recently am trying open JDK, for obvious reasons the SUN libraries are not included as part of the openJDK runtime.
I am wondering what I have to add to my POM file to use mavin to include the SUN libraries.
Currently in my environment I am using the following annotation.
package com.sun.xml.internal.txw2.annotation does not exist
#XmlElement

If this is javax.xml.bind.annotation.XmlElement then you need to add dependencies to either JAXB or java-ee API.
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
Or
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
Both should be available on Maven Central. Note that the API dependencies will let you compile your code, but if you have any unit tests that actually use JAXB you'll also need to declare dependencies on an actual JAXB implementation.

You can try downloading the JAR containing the required classes and importing external dependencies into your project, but it will explode if the project is embedded on a continuous integration server.

Related

javax.jnlp as maven dependency

Using JNLP (javax.jnlp) in one java project, I reaized that it is not part of the normal JDK.
As it is a Maven project I would like to add it as a dependency to my POM.
The one dependency I found working is:
<dependency>
<groupId>javax.jnlp</groupId>
<artifactId>jnlp-api</artifactId>
<version>8.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/javaws.jar</systemPath>
</dependency>
But depending on a system path looks bad to me - really bad.
system is marked as deprecated here: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Is there no other way?
Getting it from repositories as an reasonable up to date version (java 8)?
Or what would be the clean way?

maven dependency conflict only in eclipse

We have several applications as a number of modules; we've been using NetBeans. I am attempting to move the development to eclipse.
All projects are built with Maven. One of them uses dbunit, and also POI. When I try to compile it in eclipse, it gives me an error for a bad method signature. Neither NetBeans build with maven nor command-line build give me this error.
I discovered that the compiler was attempting to compile using a version of POI older than the one we use. The specific version of POI is designated in compile scope as a dependency for dbunit, according to dbunit's maven repository info. I don't understand why that would pull that version of POI into my compile, since I'm using dbunit, not compiling it.
Nor do I understand why it gets pulled in for eclipse and not for either of the other two compilation operations.
I have seen a number of comments on SO and on the eclipse bug report site about how eclipse uses one classpath only, and that it would be difficult to change and that there are no plans to change.
If that's true, how are other people dealing with this? I can't have the only project in the world (or even in my city) that uses libraries that have compile dependencies that conflict with the project compilation. Is there an m2e patch, or an eclipse workaround, hopefully something that does not involve modifying all 20 pom.xml files?
Compile dependencies are transitive. The Maven2Eclipse plugin uses only one dependency from the tree for a library (probably not the same as Maven does).
To be on the safe side, exclude POI when using dbunit:
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</exclusion>
</exclusions>
</dependency>
If you use a newer version of dbunit like 2.4.3, the dependency to POI is optional, meaning not transitive.

Jetty wants Jersey, but I'm not using it

Building a relatively simple jetty app, following the instructions here:
http://www.eclipse.org/jetty/documentation/9.4.x/maven-and-jetty.html
I'm not using Jersey, but mvn jetty:run complains about
Provider com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer not found
My pom.xml does not include any reference to Jersey. In fact, it is quite simple:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.0.1</version>
</dependency>
What is making jetty look for Jersey?
Search all of your dependencies for META-INF/services/javax.servlet.ServletContainerInitializer files.
The one that has the entry for com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer is the one causing you problems.
Look at your project dependencies (aka <project><dependencies>) and your project's configuration of jetty-maven-plugin to see if that <plugin> has any extra dependencies added to it (aka <plugin><dependencies>).
Well, after much machination, and gnashing of teeth, I think I stumbled about the answer. Whilst learning about maven, I was playing with shaded uber-jars. I had compiled one of the packages as an uper-jar, and installed it. When maven put it all together, it added a bit too much and broke my dependencies. Removing the shaded jar for local installation and just using it for distribution worked just fine.

SolrJ version mismatch while merging 2 projects

I have 2 java projects which developed using Solrj.
Project 1 -> using solrj 4.10.1
Project 2 -> using solrj 5.2.1
Now, I am trying to merge both the projects to single project.
I tried including both version of jars in maven, still same issue.
If I try including only major version, I'm getting some of the classes(4.10.1) are deprecated and some interfaces are unavailable in it.
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.10.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>5.2.1</version>
</dependency>
In simple:Few Packages of same project uses different jars.
example:
Package1/Module1 uses : Solrj Jar version 4.10.1
Package2 uses : Solrj Jar version 5.2.1
Is there any way to merge this projects in best way, without change old project ? I am totally stuck here.
If both projects are under the same Maven project (pom.xml), you need to update (or downgrade) one of the implementation. Both need to use the same SolrJ version. It shouldn't be too hard to update. You can find some details in Solr Wiki.

could not find class EqualsBuilder, but I've included commons-lang

I am trying to use EqualsBuilder in the apache commons library. So, I downloaded commons-lang3-3.1.jar from the apache site, and in Eclipse I configured my build path to add it to my set of libraries. I see it listed in my libraries, and if I hit cmd+shift+o it automatically adds this import:
import org.apache.commons.lang3.builder.EqualsBuilder;
However, when I run my application and try to use it, I get:
Could not find class 'org.apache.commons.lang3.builder.EqualsBuilder', referenced from method com.gnychis.awmon.DeviceAbstraction.Interface.equals
Is there something simple I'm missing, here?
Having in build path just satisfies compile time requirement
You need to add it to your project runtime also (If it is web-app, add it to lib folder)
In case you are using maven, add the following dependency to your pom.xml file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
Or if you ever need "lang" dependencies rather than "lang3", use this one instead:
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

Categories