Intellij can not resolve class of external library - java

Need a help !
I'm trying to connect spring security library to my project using Maven.
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
Library org.springframework.security.core have been downloaded successfully.
But when i'm trying to extend my class(AuthorizedUser.class) from org.springframework.security.core.userdetails.User
Intellij says, that can not resolve it. But other classes and interfaces from: org.springframework.security.core.userdetails resolving well. See the link...
When i goes to external library tree and opened org.springframework.security.core.userdetails library i saw User.class like this See the link...
Please, if anyone knows something about this problem, I'll be very thankful for any information
Windows 7
Intellij IDEA version 2017.2.4 Ultimate
Java version 1.8.0_144
Maven version 3.5.0

Maybe, you just need to create a constructor matching with super class or first try to create a class property instead of extending it just for test. apidoc
if it does not help, probably it is not related to ide, it is possible maven could not resolve dependencies because of some misconfiguration.
You can try these:
1- check local maven repository and confirm right version of jar files are there.
c:\users{username}.m2\repository\org\springframework\security
2- try build from commandline with following command and confirm build finish succesfully
mvn clean install
3- Try reimport all maven project
4 - Also, confirm intellij use right maven version, repository and settings xml. You can write "maven settings" on search bar, ant it will lead you to maven settings page.
if you find any of them is not as expected, let me know so I will try to help.

Related

How to download files from Gitlab account using java

I am writing one utility job in java to download JSON files from particular URL of Gitlab account and further process them according to requirement. I tried to do same using java-gitlab-api dependency. However, even after including below maven dependency,
I get error as :
Missing artifact org.gitlab:java-gitlab-api:jar:1.1.8-
The import org.gitlab cannot be resolved.
Maven dependency I am using is :
<dependency>
<groupId>org.gitlab</groupId>
<artifactId>java-gitlab-api</artifactId>
<version>1.1.8-SNAPSHOT</version>
</dependency>
I tried to update, clean maven project but nothing worked. Anyone has an idea of how can I rectify issues and download files from gitlab account.
Use appropriate maven java-gitlab-api version(s). There is most recent version is available too.
https://mvnrepository.com/artifact/org.gitlab/java-gitlab-api/1.1.8
https://mvnrepository.com/artifact/org.gitlab/java-gitlab-api
<!-- https://mvnrepository.com/artifact/org.gitlab/java-gitlab-api -->
<dependency>
<groupId>org.gitlab</groupId>
<artifactId>java-gitlab-api</artifactId>
<version>1.1.8</version>
</dependency>

IntelliJ Idea not resolving Mockito and JUnit dependencies with Maven

I am using IntelliJ idea for writing simple unit test cases using JUnit and Mockito. I am using Maven for dependency management.
IntelliJ idea keeps complaining that following imports cannot be resolved:
import org.junit.Test; //Cannot resolve symbol 'Test'
import static org.mockito.Mockito.*; //Cannot resolve symbol 'mockito'
Following is the dependencies section of my project:
<dependencies>
<!-- Dependency for JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<!--<scope>test</scope>-->
</dependency>
<!-- Dependency for Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<!--<scope>test</scope>-->
</dependency>
</dependencies>
Following is my project structure:
Try View -> Tool Windows -> Maven projects, then click the blue icon in the top left of the tool window (Reimport all Maven projects). You should be able to find the dependencies in the project view, under external libraries.
If this does not work, there is probably something wrong with your maven config (pom.xml). Try mvn clean install from the command line see if it gives any errors.
My IDE was not resolving JUnit & Mockito dependencies. Tried reimport in IntelliJ and mvn clean install multiple times which didn't help. Reimport worked for me, but with the following steps.
Please be aware that you will lose any run configurations that you have created.
Close IntelliJ
Go to Project Folder and remove .idea folder (rm -rf ./idea)
Import Maven project again (You will need to add back any run configurations that were deleted)
I solved this problem by adding mockito to module I used. Just go to File -> Project structure and in Modules add mockito to your selected module - the one in which you use mockito (usually Test).
You can also use command
mvn -U idea:idea
This command forces a check for missing dependencies and helps in resolving them.
Restartig intellIJ fixed that for me
For me, I deleted org.mockito package from m2 repository and then did mvn clean install.
this reimport the package.
Try using lower versions of junit and mockito.
The latest versions weren't working in my project but it worked once I used lower versions.
Few other things you can do:
After adding the dependency just make sure to update the maven
project. (right-click on project folder -> Maven -> Reload project)
You can also try clicking on the tiny m symbol on the top right to
load maven changes or select maven button to get clean+install
options and click play button.

Maven dependency from local file - resolve any (*) symbol

I want to use missioncontrol module which is not published at maven repository and is installed with JDK. I could manually install it by mvn install like it's done in this script. But I'd prefer maven to resolve this dependency automatically.
The issue is I don't know exact version of module on each machine (assuming that JAVA_HOME is defined for every machine). And maven does not seem to automatically resolve the * placeholder:
<dependency>
<groupId>com.jrockit.mc</groupId>
<artifactId>com.jrockit.mc.common</artifactId>
<version>LATEST</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/missioncontrol/plugins/com.jrockit.mc.common_*.jar</systemPath>
</dependency>
Is there any proper way to do this? Or is it a bad practice for some reason? Thanks.
Does your jar file name changes with java version

Using elasticsearch in Java

I am trying to use the Java API of elasticsearch. I can find many examples on how to use different elasticsearch methods but I am still stuck on how to set up elasticsearch so it is available within Java. I tried following this guide:
http://www.ibm.com/developerworks/library/j-use-elasticsearch-java-apps/index.html
So I set up a maven project in Eclipse and edited the POM.xml to include
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.1.1</version>
</dependency>
In a main file I tried initializing a client using the TransportClient class. But it can't be resolved. It seems like my main doesn't know the elasticsearch types. What can I do about this?
If you edit your pom.xml you should rebuild your project. Maven will download the lib and normally you should than be able to use it.
Right click your maven project, go to Maven -> Update Project to update your maven. Then, your refresh your Project.
Another way to refresh your Maven Project is to run Maven clean install.
Run as -> Maven build
then fill clean install in the Goals edit box.

What is the best way of adding a jar file to a maven project if we could not find it the maven central repository?

I need to add the package "uk.ac.shef.wit.simmetrics.similaritymetrics"
to my maven project but I am not able to find any remote repository which contains it. I have to add it via dependency to the project, but not successful yet.
-I already added the jar file to the referenced library but in that wat I get the following error:
package uk.ac.shef.wit.simmetrics.similaritymetrics does not exist.
-Adding it through following dependency to the Pom.xml also does not help
<dependency>
<groupId>uk.ac.shef.wit</groupId>
<artifactId>simmetrics</artifactId>
version>1.6.2</version>
<scope>system</scope>
<systemPath>LocalPath\simmetrics-1.6.2.jar</systemPath>
</dependency>
Any help is appreciated!!
If this is a small project that you intend to only build locally or on a few machines then the simplest way is follow directions at the site below to add a 3rd party jar. Those instructions will help you install it in your local repository. You will need to do that for all machines that you intend to run the build on.
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
If you plan to run it on many machines then the best thing to do is to install the artifact to your own private repository. If that is the case then I suggest you create a project for it in version control. Then upload the file as part of that project.
I appear to be the current maintainer of Simmetrics. You can add this dependency to your pom file.
<dependency>
<groupId>com.github.mpkorstanje</groupId>
<artifactId>simmetrics-core</artifactId>
<version>4.0.1</version>
</dependency>
Simmetrics has been given a much needed serious overhaul since 1.6.2. You may have to adjust your code accordingly. For source code and documentation see https://github.com/Simmetrics/simmetrics

Categories