Using Maven Dependency in RCP app and getting ClassNotFoundException from included dependency - java

I want to include XStream in my RCP project and used a Maven Dependency to add it to my target definition.
<location includeDependencyDepth="infinite" includeDependencyScopes="compile,provided,runtime,test,system,import" includeSource="true" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.20</version>
<type>jar</type>
</dependency>
</dependencies>
</location>
From this diagram, it seems like xmlpull is present but XStream throws ClassNotFoundException in the constructor.
java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException cannot be found by xstream_1.4.20
Looking more closely, I see that there are a number of new plugins named wrapped.bundlename. I then reconfigured the Maven Dependency to produce a feature and added the feature to my core feature.
The run configuration picked up the new feature but xmlpull was still not found at runtime. In desperation, I added all plugins (xmlpull included) to the run configuration but there was no improvement.
Is this the right approach for creating plugins from maven dependencies?

Related

Why am I not able to import a class into java file in Eclipse Maven Project?

I need to use AuthenticationRequest in my Maven Java Project. I did a search on the internet and found AuthenticationRequest on this page (OpenID Connect authentication), indicating this library contains AuthenticationRequest. I follow the links on that website to this page (com.nimbusds:oauth2-oidc-sdk-6.13 API Doc) and find a list of packages. I found this library at Maven Repository.
I added the information in my pom.xml in my Maven Project in Eclipse. Updated Project. Yet I am not able to import any packages starting with "com.nimbusds.oauth2".
Here is the dependency info for that library that I put in my pom.xml file:
<!-- https://mvnrepository.com/artifact/com.nimbusds/oauth2-oidc-sdk -->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>6.13</version>
<scope>runtime</scope>
</dependency>
I am following an example code that uses the AuthenticationRequest class. I am having trouble finding the Maven info to put in my pom.xml file that allows me to use that class in my project. How do I find the right info for it?
Since you are developing a class that depends on that AuthenticationRequest class to compile, your maven goal is going to be before runtime. Maven scope of runtime is not appropriate.
You need to modify your pom.xml to specify compile scope:
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>6.13</version>
<scope>compile</scope>
</dependency>
Since Maven's default scope is compile, you could also just omit the scope tag.
Maven will import dependencies from the Maven Central repository by default. If Maven Central doesn't contain your dependency (I haven't checked) you must specify a repository that does contain it with something of this form in your pom.xml (note the repo is just an example - substitute a real one that contains your dependency)
<repositories>
<repository>
<id>some-example-repo</id>
<url>http://some.example.repo/some_example_path/</url>
</repository>
</repositories>

How to solve dependency problem in maven because of using different versions of same project

I have 4 modules in my project.
Module1 (i.e. com.assign.print:printlog.value:3.0.0-SNAPSHOT) has one class i.e. Foo.java, inside this class, on more class is there which is using com.print.assess: mns.pro:2.0
Module2 , Module2 and Module4 are using com.print.assess: mns.pro:6.2.
In my project main pom.xml, the dependency is added as :
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
<version>6.2</version>
</dependency>
In Foo.java, I have one class as DataVal.java which is using older version.
If I don't add
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
<version>2.0</version>
</dependency>
to Module1 pom.xml, Redline error is coming for DataVal.java saying "cannot resolve the symbol". So when I added the dependency with version 2.0, the error was resolved but while installing project:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for com.print.assess:mns.pro:6.2 paths to
dependency are:
+-com.assign.print:printlog.value:3.0.0-SNAPSHOT
+-com.app.print:print.sal:1.1.3
+-com.print.assess:mns.pro:6.2
and
+-com.assign.print:printlog.value:3.0.0-SNAPSHOT
+-com.print.assess:mns.pro:2.0
and
+-com.assign.print:printlog.value:3.0.0-SNAPSHOT
+-com.print.assess.over:multi-task.rev:3.1
+-com.print.assess:mns.pro:6.2
How to resolve this issue?
Thanks in advance
If you have the dependencyConvergence enforcer rule active (which you obviously have), you need to determine your versions in the <dependencyManagement> (which is different from the standard <dependencies>).
Then you can declare the dependencies without version in <dependencies>. dependencyManagement entries can be in the main pom and in modules as well. #Bahmut gave you the link to understand dependencyManagement.
You may want to move your 6.2 dependency in your main pom to <dependencyManagement> so it does not get imported by default. Then you can simply import the 6.2 version in your module poms like this:
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
</dependency>
and in the module where you need version 2, you can import it like this:
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
<version>2.0</version>
</dependency>
More information about dependency management can be found here:
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

Maven dependency weird bug

I have 4 projects in my eclipse workspace. They are all 4 maven projects. The names are API, Games, Faction, Board.
API is used in all the other maven projects (Games, Faction, Board) and itself depends of a jar into my PC and also HikariCP.
I declare this dependencies in my API pom.xml
<dependency>
<groupId>org.github.paperspigot</groupId>
<artifactId>paperspigot-api</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}\lib\paperspigot-1.7.10-R0.1-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.8</version>
<scope>compile</scope>
</dependency>
Then I declare on my 3 other projects that they depend of API
<dependency>
<groupId>net.onima</groupId>
<artifactId>onimaapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
But I have a big warning on the API and the error log says this:
I don't understand why is there this error as I can code with the API in my classes. Can someone explain me? Thanks
EDIT: As requested the text of the screenshot:
Description Resource Path Location Type
Project 'OnimaAPI' is missing required Java project: 'paperspigot' OnimaAPI Build path Build Path Problem
Description Resource Path Location Type
Project 'OnimaGames' is missing required Java project: 'onimaapi' OnimaGames Build path Build Path Problem
I don't know why I can't set the pom.xml here so here's a link: https://ghostbin.com/paste/r4u62
You're declaring paperspigot with system scope.
<dependency>
<groupId>org.github.paperspigot</groupId>
<artifactId>paperspigot-api</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}\lib\paperspigot-1.7.10-R0.1-SNAPSHOT.jar</systemPath>
</dependency>
Dependencies with the scope system are always available and are not looked up in repository. They are usually used to tell Maven about dependencies which are provided by the JDK or the VM.
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
You should declare it with compile scope:
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

customized job in maven

I generated jars from Talend,and I suppose to use them in a maven project.After some research I know that I have to install this jars in the local maven repository using:
mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1 -Dpackaging=jar
and then add a dependency:
<dependency>
<groupId>....</groupId>
<artifactId>...</artifactId>
<version>...</version>
</dependency>
But I don't know what to put exactly in the groupId,artifactId and version tag. Help plz
Go to the maven repository https://mvnrepository.com and search for your dependency. Click on the version number and it will show you the complete dependency tag for your talend. e.g
<!-- https://mvnrepository.com/artifact/org.talend.esb.job/org.talend.esb.job.api -->
<dependency>
<groupId>org.talend.esb.job</groupId>
<artifactId>org.talend.esb.job.api</artifactId>
<version>6.3.1</version>
You should specify what is this "Talend"?
Here is simple introduction to maven pom structure:maven pom doc
groupId: This is generally unique amongst an organization or a project.
artifactId: The artifactId is generally the name that the project is known by.
version: is last piece of specification which package to use.
You can find specification to mvn dependencies on maven repository page. Here is an example for Talend ESB jar (newest version):
<!-- https://mvnrepository.com/artifact/org.talend.esb.job/org.talend.esb.job.api -->
<dependency>
<groupId>org.talend.esb.job</groupId>
<artifactId>org.talend.esb.job.api</artifactId>
<version>6.3.1</version>
</dependency>
BTW if you are just using it locally , then you can install jar with any group Id,artifact Id and version you feel like. Just make sure you use the same in your dependencies in project POM.
However this is not the recommended approach, but if you are not sure about the maven coordinates( group Id, artifact Id and version) you can use above given hack.

Not able to use #Inject in eclipse 4

I am trying to use dependency injection in my eclipse project. I included maven dependency for org.eclipse.e4.core.di in my dependency management pom.
<dependency>
<groupId>org.eclipse.e4</groupId>
<artifactId>org.eclipse.e4.core.di</artifactId>
<version>1.5.0-SDK-4.5.0</version>
</dependency>
And also, in the plugin where I am using dependency injection with compile scope.
<dependency>
<groupId>org.eclipse.e4</groupId>
<artifactId>org.eclipse.e4.core.di</artifactId>
<version>compile</version>
</dependency>
After this, when I try to use the annotation #Inject, I am seeing error and I am not able to see any import suggestion also.
I have tried including the following in the pom also
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
What is causing this problem? I am using Java 8.
To use #Inject you must include javax.inject in the Require-Bundle or Import-Package entries in the MANIFEST.MF of your plug-in.
To do this in the MANIFEST.MF editor go to the Dependencies tab and add javax.inject to the Required Plug-ins or Imported Packages section.
When you have done this you should be able to use
import javax.inject.Inject;
in your code.
Note: Only classes created from entries in the e4 Application.e4xmi are injected unless you use ContextInjectionFactory to create the class.

Categories

Resources