IntelliJ can't find Maven dependencies at runtime - java

I'm not getting any red lines, but IntelliJ can't find my Maven dependencies when I run the (Play) app. Tried invalidate cache/restart. Tried running mvn clean install.
compiler error message
(compile:compileIncremental) Compilation failed
[info] Compiling 8 Scala sources and 5 Java sources to /Users/****/IdeaProjects/GeoMood/target/scala-2.11/classes...
[error] /Users/****/IdeaProjects/GeoMood/app/views/show_tweets.scala.html:1: not found: value twitter4j
[error] #import twitter4j.Status
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>geomood</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.8.0</version>
<classifier>models</classifier>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
</dependency>
</dependencies>
</project>
Does anyone have any ideas why IntelliJ isn't picking this up? The maven build runs fine, and the dependencies are listed under external libraries.

I usually have to do the following to make IntelliJ aware of changes to my dependencies in the pom.xml:
Right click the root folder of the project in IntelliJ's project view
Go the the Maven menu item, and open the Maven submenu
Click Reimport

It sounds like you've hit bug IDEA-148573:
when a Maven dependency uses a classifier, IDEA ignores the classifier when building its classpath and tries to use the non-classified artifact for that dependency

Related

Why doesn't maven see a specific version of the dependency?

I have a separate project, which I assemble into a jar file, and connect as an external dependency to my main project.
External project pom.xml
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.2</version>
<name></name>
<packaging>jar</packaging>
The command to place the jar file in a local repository.
mvn deploy:deploy-file -DgroupId=my.group -DartifactId=artif-idbla -Dversion=0.9.2 -Durl=file:C:/Development/local-maven-repo -DrepositoryId=local-maven-repo -DupdateReleaseInfo=true -Dfile=C:/path/my.jar
Then I connect it to the main project.
Main project pom.xml
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file://C:/Development/local-maven-repo</url>
</repository>
</repositories>
<dependency>
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.2</version>
</dependency>
It works!
Next, I make changes to my dependency, and I want to generate a new version of the project.I am changing the version from 0.92 to 0.9.21
External project pom.xml
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.21</version>
<name></name>
<packaging>jar</packaging>
I reassemble the jar file and put it in the local repository.
-Dversion=0.9.21
Changing the main project pom.xml.
<dependency>
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.21</version>
</dependency>
And I get an error.
Unresolved dependency: 'my.group:artif-idbla:jar:0.9.21'
This is what the local repository looks like.
Here is the structure maven-metadata.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<versioning>
<release>0.9.21</release>
<versions>
<version>0.9.2</version>
<version>0.9.21</version>
</versions>
<lastUpdated>20220707041151</lastUpdated>
</versioning>
</metadata>
For what reason does Maven not see version 0.9.21 but sees 0.9.2 ?
UPD 1.
I use Intellij Idea.
When updating pom.xml the main project, I'm trying to update maven.
If version 0.9.2 is specified, everything works if 0.9.21 is not updated.
The only output I see in the console.
Unresolved dependency: 'my.group:artif-idbla:jar:0.9.21'

dependencies from pom.xml not being resolved

I'm trying to create a maven project in intellij, to create a parser in antlr. Here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mua</groupId>
<artifactId>json-parser-java-antlr</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Json parser Java ANTLR</name>
<packaging>jar</packaging>
<description>Trying to create a parser using ANTLR in Java, as facing problems with LLVM</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
</dependency>
</dependencies>
</project>
When I click on import changes, it loads for just 1-2 seconds then done. But if I try to import MapUtils from org.apache.commons.collections4.MapUtils it says it can't resolve common, although I added in <groupId>org.apache.commons</groupId> dependency.
I'm new in maven project creation and management.
So, what is the problem here and how can I resolve this problem ?
I studied some pom.xml and found a parent attribute. No idea how to configure that.
My Eclipse editor shows:
Project build error: 'dependencies.dependency.version' for org.antlr:antlr4-runtime:jar is missing.
Project build error: 'dependencies.dependency.version' for org.apache.commons:commons-collections4:jar is missing.
Project build error: 'dependencies.dependency.version' for org.apache.directory.studio:org.apache.commons.io:jar is missing.
None of the dependencies work, because it doesn't know which version of them you want.
Specifying dependencies without a version is something you do when you have a parent pom. You don't, so versions are mandatory.
You could try adding a specific version of antlr to your pom.xml. And if you are using the antlr plugin as well, make sure the version of antlr run-time you are using is the same as the built-in version of the plugin.

Missing Maven Dependency and can not import class

I have created a new maven project by choosing org.apache.maven.archtypes maven.archtype.webapp.
I perform the below commands:
right click pom > maven clean
right click pom > maven install.
check maven user setting file
right click on project > maven update.
but maven dependency library is not added into libraries folder although a build success message has been output.
[INFO] Scanning for projects...
<p>
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO] BUILD SUCCESS
[INFO] Total time: 2.248 s
[INFO] Finished at: 2018-06-07T09:40:57+03:00
[INFO] Final Memory: 8M/20M
Here's my pom file, e.g dependency mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache. rg/xsd/maven-4.0.0.xsd">
<groupId>test</groupId>
<artifactId>maven.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>maven.test Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Here's my library screenshot without maven dependency
As Amer mentioned , do a maven update for your project, if it doest work the try with different network(either use mobile phone network or home network) to update project then do a eclipse clean(not maven clean) for that project then do a maven install. sometimes network block the jar file to download
right click on the project -> maven -> update project
I saw screen shot you attached but there is not any folder called "Maven Dependencies". So please try one option it may solve your problem...right click on project -> configure -> convert to maven.
go to the source folder of the project using cmd and
run maven command:
mvn clean install (this command won't work unless you specified path to maven/bin folder in path of system variables)
be sure you're not beyond the proxy, if you are, then you should configure maven to work with it. Link to how to configure a proxy in maven

How are third party tools such as this accessed within Java?

https://github.com/bvanalderweireldt/concurrent-unique-queue
I have tried to set up a Maven dependency within IntelliJ, but I am not sure how the contents of this repository should be built and imported into a Java project. Could someone with more experience please advise on how this is done?
Kind regards,
L
If you want to use this project in another project, you will create a dependency to this using the dependency entry mentioned on the github readme:
<dependency>
<groupId>com.hybhub</groupId>
<artifactId>concurrent-util</artifactId>
<version>0.1</version>
</dependency>
For this, you need the artifact in your local maven repository*. For this, you need to build this project or use a reference from Maven Central (Thanks #Mark Rotteveel )
Clone the project locally, you need to build it in one of the following ways
Build it from the command line: Navigate to the project's location in your shell (bash or cmd) and run mvn install
This will build the project and add the artifact (jar) to the local .m2 repository.
Import to Intellij Idea (File -> New -> From Existing Sources). Once imported, build this project from the "Maven Projects" view.
Once you have done this, you can use this in other projects using the <dependency> entries
*For production ready apps, you may want to have a common maven repository for team your like Nexus or Artifactory and use that to maintain artifacts. You would also have a build system like Jenkins.
In the link you gave it had the dependency Maven entry for that library.
<dependency>
<groupId>com.hybhub</groupId>
<artifactId>concurrent-util</artifactId>
<version>0.1</version>
</dependency>
That entry would need to be nested into you <dependencies> tag. Like the example below.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.hybhub</groupId>
<artifactId>concurrent-util</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

How to get all of required Apache POI library using Maven?

I have installed maven and I created a project using this command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
The result is there are 2 folder and 1 file created in my-app folder: src, target, and pom.xml.
Then I modify the pom.xml in order to get the all of required apache POI jars.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.my-app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- This is what I added -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
</dependencies>
</project>
Then I run:
mvn package
but no jars downloaded into the project folder although I got message "BUILD SUCCESS".
What you've done is correct. However, the poi jars won't download to your project folder but to your local Maven repository. This is exactly what Maven is supposed to do so that you don't have to manage many libraries/jars yourself and get all in a mess. If you do a search of your local Maven repository, you should find it there.
I also suggest you read up on how Maven uses external dependencies, this is all explained here:
http://maven.apache.org/guides/getting-started/index.html#How_do_I_use_external_dependencies
If you want to package up all of your dependent jars in to one big jar look here:
How can I create an executable JAR with dependencies using Maven?
Your project has a jar packaging type. Java not support nested jar and then maven package doesn't put any jar in your project . To do this you have to use Maven Assembly Plugin or use Spring-boot to make your uber jar

Categories

Resources