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.
Related
This question already has answers here:
How do I tell Maven to use the latest version of a dependency?
(12 answers)
Closed 7 months ago.
Im using java and maven and I want to always get the last version of selenium-java. Is there any way to do that?
If I use this dependency I have a warning message
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
In general you don't want to do that. If there is a breaking change or a bug in the new version you'll be stuck determining where the issue is.
Maven has two ways to address this. The first is:
mvn versions:display-dependency-updates
this will display the libraries you are currently using and if there is a new version of them. For example, in an older project that I haven't touched in a while I get things like:
[INFO] The following dependencies in Dependencies have newer versions:
[INFO] com.fasterxml.jackson.core:jackson-databind ......... 2.9.10 -> 2.13.3
[INFO] com.google.code.gson:gson ............................. 2.8.6 -> 2.9.0
[INFO] com.jayway.jsonpath:json-path ......................... 2.5.0 -> 2.7.0
[INFO] commons-io:commons-io ................................ 2.8.0 -> 2.11.0
This is showing me where I need to take a look at updating. Nothing is automatically updated - this is a report that you need to generate by hand.
The second way may be closer to what you want. Maven can take a range of versions that you are willing to use. As a very general statement most libraries remain compatible if you don't jump outside of at least the major version. That isn't always true but you can decide that for your self. In your case you could change your dependency to:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>[4.3,5.0)</version>
</dependency>
This tells Maven to use at least version 4.3.0 but not version 5.0 and above. If 4.3.1 comes out it will automatically use this. It will not though use anything 5.0 and above.
If you really think you need to keep upgrading forever, you'd change this to:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>[4.3,)</version>
</dependency>
which just says version 4.3.0 and above. If a version 5.0 comes out it will use this. There is zero guarantee that version 5.0 is compatible - maven will blindly start using it.
Plugin Metaversion Resolution
Incase you are using Maven 2.x, it can pick the latest version available where the latest version could either be a release or a snapshot. Internally, Maven 2.x used the special version markers RELEASE and LATEST to support automatic plugin version resolution.
As an example:
Using RELEASE:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>RELEASE</version>
</dependency>
Using LATEST:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
However, Maven 3.x no longer supports usage of these metaversions in the POM. As a result, users will need to replace occurrences of these metaversions with a concrete version.
References
You can find a couple of relevant detailed discussion in:
How to automatically update selenium version in POM?
I'm currently working on a dbunit extension library. Thus this library depends on dbunit.
I extracted the version as a maven property.
<properties>
<dbunit.version>2.4.8</dbunit.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>${dbunit.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
This allows me to run the maven build with another dbunit version
mvn test -Ddbunit.version=2.7.3
But it also change the dbunit version that the compiler uses. Thus I test source code compatibility to another dbunit version.
The question I want to answer with my maven build is:
Does my library work normal, as specified by the tests, if I use the library that was build against dbunit 2.4.8 with dbunit 2.7.3 at runtime?
I would like to introduce version ranges so that clients of the library can choose which version they want to use, but to do that I want to test which versions work.
The maven-surefire-plugin allows me to add additional classpath entries. But only if I know the path of a lib. I would like to use the GAV (group artifact version) format.
How can I solve this? Do you know another plugin that can handle such cases.
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?
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.
I'm trying to use RichFaces in my learning JSF application. I have set up Maven using
https://repository.jboss.org/nexus/content/groups/public-jboss/
I have included the dependencies
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-api</artifactId>
<version>4.0.0.Final</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-api</artifactId>
<version>4.0.0.Final</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
This has fetched guava-r08.jar.
When I try to run the project in Tomcat7 I see a lot of class load exceptions - failing to load classes that I can see exist within guava-r08.jar along with sac-1.3 and cssparser-0.9.5.
If I try to use the source instead - taking source from guava-r09 - Eclipse tells me that it cannot find classes such as javax.annotation.Nullable. Problem is neither can I!
Where can I find these classes, or am I taking the wrong approach from the start?
Thanks
Richard
Maven configuration for RichFaces dependencies
Tomcat fails to load these classes, because RichFaces' dependency on Guava has a runtime scope. Contrary to the compile scope, these dependencies are not added to the classpath when compiling. You must include them yourself.
To achieve this, you should include richfaces-bom in the dependency management section of your POM, as explained in this JBoss wiki article. This will include Guava and all other required dependencies RichFaces might need.
This is the "Bill of Materials" (BOM) pattern. The JBoss wiki explains this pattern far better than I would, and links to other articles on the subject.
javax.annotation.Nullable warnings in the Guava source
These occur because Guava uses JSR 305 annotations. It is not required to depend on the JSR 305 jar when using Guava, because annotations do not require to be present on the classpath once compiled. Of course, if you want to use #Nullable and other such annotations in your code (you definitely should), you'll need to add a dependency on the JSR 305 jar.
I have started from scratch using instructions at jboss.org
I installed Maven 3.0.3
I copied the supplied settings.xml to my .m2 directory and added the JBOSS section from 1
I used the command line to create the project:
mvn archetype:generate -DarchetypeGroupId=org.richfaces.archetypes \
-DarchetypeArtifactId=richfaces-archetype-simpleapp \
-DarchetypeVersion=4.0.0-SNAPSHOT \
-DgroupId=uk.m0rjc \
-DartifactId=jsfplay
I then built the project. I had to remove the previously downloaded guava jars from my m2 repository because they were corrupt - perhaps my initial problem.
mvn clean package
I copied the WAR file it produced to Tomcat and navigated to the sample page at localhost:8080/jsfplay-1.0-SNAPSHOT/
I had some issues making the project work in Eclipse. These may be due to my setup from previous experiments.
I used the "Import -> Maven -> Existing Maven Project" to import it
I had to switch the project to JDK 1.6 and 1.6 compatibility mode.
I was unable to use the JavaServer Faces facet. This does not seem to matter.
I had to set my Server Profile to use the right JDK
I had to map *.xhtml to the Faces Servlet in web.xml. It may have been corrupted when I pressed a wrong button to accept a JSF addin.
Then it worked!!
Now to try porting my existing code to the new project.