I have a java project with this pom.xml in IntelliJ that uses Collections
<?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>test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.collections/google-collections -->
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
</dependencies>
</project>
I have run this from the command line:
mvn clean install -U
but even this I got this compilation error:
Cannot resolve symbol ImmutableMap
View -> Tool Windows -> Maven projects
You can click on the left most button to reimport all maven projects.
Then run mvn clean install.
Open your project as a Maven Project
If you don't find the maven toolbar, your project has to be open as a maven project in IntelliJ.
In your maven project panel try :
Reimport all Maven projects
Generate Source and Update Folders for all projects
You should perform a mvn clean install before
Related
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
I am learning Spring in maven environment. I am using netbeans.
pom.xml
<dependencies>
<?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.davidsalter.cookbook</groupId>
<artifactId>springMavenTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
</dependencies>
</project>
And spring.context-4.3.4.RELEASE.jar appears under Dependencies. Under Java Dependencies i only have JDK1.8.
When i have to configure my beans in a java class using #Configuration and #Bean annotations i can't import org.springframework.
It seems that you just create a maven project in NetBeans. The maven dependencies you declared in pom.xml will be downloaded and listed in the Dependencies folder.
Right click on Dependencies folder and click on Download Declared Dependencies to reload the dependency. If still failed, you may need to check your maven proxy in setting.xml.
Update you project.
By doing Alt + F5 and then select your project then click Ok
Else right click on your project -> Maven -> Update Project.
Make sure you are connected to the internet to download all these spring dependencies.
I had the same problems. I added the following to the pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
It seems to work ....
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/201/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.recommender</groupId>
<artifactId>RecomenderApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>RecomenderApp</name>
<url>http://maven.apache.org</url>
<properties>
<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>
</dependencies>
</project>
Eclipse shows an error in "jar". I tried installing groovy m2 eclipse, but that too failed. I tried looking at familiar posts but couldn't find a solution. Please help
Once you added the dependency you need to update the project. This can be done by right clicking on the project name > maven > update project. This will refresh your project and the erross should go away. I had the same issue and was able to fix this way.
There are many related questions to this but I am getting confused with the answers from them and decided to ask this myself. I have a Java program and want to use it in another one. How can I add the first one as a dependency in the POM.xml file of the second program? The IDE I am using is IntelliJ version 13.
If the first java program was built with maven (it has pom.xml with groupId:artifactId:version), you can add it as a dependency into your new project:
<dependency>
<groupId>old-program-group-id</groupId>
<artifactId>old-program-artifact-id</artifactId>
<version>version-you-want-to-re-use</version>
</dependency>
If no - it would be very complicated way (in size of an article)...
Suppose this is pom.xml of project A
<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.a</groupId>
<artifactId>a</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>a</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
After you compile project A through mvn install command, you can add project A into project B by using <dependency> of project A
suppose this is pom.xml of project B
<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.maventest</groupId>
<artifactId>mytest2</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>b</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.a</groupId>
<artifactId>a</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
See more information : How do I add a project as a dependency of another project?
The easiest way to make one a dependency of the other would be to put them together under a parent POM. Building multi-module Maven project is easy. This will get your started. Once you have created the parent pom and referenced it in the two modules, just use a standard maven <dependency/> tag in the one needing the dependency and create a new Intellij project that imports from the parent POM.xml file.
Follow this steps
Create jar file (java archive) with your project.
Execute
mvn install:install-file -Dfile=c:\your file.jar -DgroupId=your.id
-DartifactId=your name a -Dversion=1.0 -Dpackaging=jar
to include at your local repository
Add dependency to pom.xml
<dependency>
<groupId>your.id</groupId>
<artifactId>your name</artifactId>
<version>1.0</version>
I've 1 project with one subproject in my teamcity server. The subproject has the pom.xml file that references parent project.
This is the pom.xml of the project:
<?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>it.company.project</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>MyProject</name>
<url>http://maven.apache.org</url>
<properties>
<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>
</dependencies>
<modules>
<module>Foo</module>
</modules>
</project>
This is the pom.xml of the subproject:
<?xml version="1.0"?>
<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>
<parent>
<groupId>it.company.project</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>Foo</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>subproject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
</build>
</project>
When I run the maven build from my IDE (IntelliJ IDEA) on my subproject, all works fine. Also when I run maven build on the parent project all works fine.
When I run build agent (configured to run pom.xml) from TeamCity server on my subproject it doesn't work, and I've the following errors:
[Step 1/1] Error reading Maven project: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact it.company.project:MyProject:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 5, column 13
.
[14:08:12][Step 1/1] TeamCity is unable to read Maven project. Some features may be unavailable
When I run build agent (configured to run pom.xml) from TeamCity server on my parent project it doesn't work, and I've the following errors:
An error occurred during collecting Maven project information: File not found in any VCS root: subproject/pom.xml.
My subproject build configurations:
What's wrong?
Thanks