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.
Related
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?
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>
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
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.
It's very strange. I am moving a dynamic web project from Java 8 to Java 10.
The last thing I cannot get the dependency resolved is the javax.xml.namespace.QName class.
You can see in the attached screen shot, the QName class exist in JRE System Library, but the IDE keep complaining that QName cannot be resolved to a type.
There probably is a duplicate dependency pulled in from some other dependency.
In eclipse do
"Navivate -> Open Type..."
Type in "java.xml.namespace".
If there are other results than from your (Open-)JDK, these need to be removed in the following steps. In my case it was xml-apis
Open your pom.xml in eclipse, and visit the "Dependency Hierarchy" tab to check which dependency was pulling in xml-apis
Type "xml-apis" in the Filter. In my case the top level dependency that was pulling xml-apis was "esapi"
exclude xml-apis from the esapi dependency:
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.2.0.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
Right click your Project and choose "Maven -> Update Project...". Check your project and click OK.
That's it
I had the same error moving from Java 8 to Java 11,
and I included an explicit dependency on the library stax-api 1.0-2:
<dependency>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>1.0-2</version>
</dependency>
and excluded any transitional dependency on the library stax-api 1.0.1:
...
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
...
After this, my IDE found the lost import javax.xml.namespace.QName correctly.
I hope this helps.
Try to change the order of elements on your classpath. The JRE must be before the Maven Dependencies. That fixes the issue.
My guess is that the Java 10 compiler notices that you're trying to replace internal classes (java.xml.namespace) with code from JARs and it doesn't like that.
Resolved it by removing jsr173_api.jar from the project classpath (project -> properties -> java build path -> libraries -> classpath). It appears again when eclipse project rebuilt.
This worked! Checking for multipletypes Ctrl+Shift+T, removing unwanted ones.
I have had the same experience with the JRE 11, and Gradle 7.5. If it helps anyone, you can exclude xml-apis as such:
configurations {
all {
exclude group: 'xml-apis', module: 'xml-apis'
}
}