I'm trying to get Apache Log4j 2.9.0 into my IntelliJ Maven project, but am getting nowhere. This is the first time I've tried to use Maven with IntelliJ; I've been able to use it successfully with Eclipse in the past. (I'm using Windows 10 if it makes a difference.)
What I've tried:
1) In pom.xml, Alt+Insert -> Dependency, search for an artifact with log4j. It will find log4j 1.x, but not log4j-api or log4j-core which are needed for 2.x.
2) Downloaded log4j 2.9.0 from Apache. Their web site didn't tell me what to do with the file; after unzipping the download, I copied the top-level folder to .m2\repository. Retried searching for log4j, but it still couldn't find log4j 2.x stuff; tried various things like "Reimport all Maven projects", the Update button on the Settings page for Maven, Invalidate all caches and restart.... nothing has worked.
Edit: When I typed the above, I was sure there was a pom.xml file in my download. But I just double-checked and there wasn't. So I don't know whether any of the downloads on the Apache web page will work for Maven.
3) On the Settings page for Maven Repositories, tried "Test" on all the "Artifactory or Nexus Service URLs". The Test seemed to work fine.
4) On the Maven Settings page, changed Maven Home Directory from Bundled (Maven 3) to something inside Program Files (x86)\Jet Brains, which showed up on the drop-down menu. Didn't help.
I'm using IntelliJ Community Edition 2016.1.1, build #IC-145.597, Maven 3.0.5.
I must be missing a setting, but I can't figure out what. The documentation at https://www.jetbrains.com/help/idea/maven.html isn't helpful for solving this.
Related
What I did:
I went to start.vaadin.com
I selected "Vaadin 20" and "Java 16"
I downloaded and extracted the project
When I open the project in IntelliJ IDEA, I get three errors in the pom.xml:
Line 19, definition of parent: Project 'org.springframework.boot:spring-boot-starter-parent:2.4.6' not found
Line 143, vaadin-maven-plugin for prepare-frontend build goal: Plugin 'com.vaadin:vaadin-maven-plugin:20.0.1' not found
Line 164, production profile with vaadin-maven-plugin: Plugin 'com.vaadin:vaadin-maven-plugin:20.0.1' not found
The Maven Central repository is configured in the pom.xml file as a repository and as a plugin repository. Using my browser I can find the vaadin-maven-plugin in version 20.0.1 in the repository: https://mvnrepository.com/artifact/com.vaadin/vaadin-maven-plugin/20.0.1
When I change the version of the vaadin-maven-plugin to 19.0.7 and the version of the spring-boot-starter-parent to 2.4.5, the errors disappear and the dependencies could be found.
I am not behind a proxy and I don't have a firewall running on my computer. I use Apache Maven 3.8.1 and AdoptOpenJDK 16.0.1.
Any ideas what I am missing?
If Maven has failed to load dependencies for whatever reason then you might need to run mvn -U for it to retry from the network instead of only the local cache
Sorry, the problem was related to IntelliJ IDEA. The fix was really easy:
Menu "File > Invalidate Caches", select "Clear file system cache and Local History" and "Clear downloaded shared indexes", click on "Invalidate and Restart".
Looks like some cache or index files of IntelliJ got corrupted. Opening the project after the restart took a little bit longer because IntelliJ needs to reindex everything, but the three errors in the pom.xml are gone.
Sorry, I totally forgot about the caching of IntelliJ…
I'm working in eclipse and I have a problem that I can't import my personal java libraries.
I created the libraries and 'installed' them into my local maven repo (using mvn install). This created a subdirectory related to the 'version' name that was in the POM file from when I ran the command. Which seemed fine.
So in this directory there where the usual jar files and other stuff.
When I released this file I manually changed the name of the version in the POM. going from 0.0.1-SNAPSHOT to 0.0.1-RELEASE
This seems to have worked as I would have expected.
However I can't seem to find import the new release jar.
Using the maven repositories browser in eclipse I can see that the new artifact is in the 'local' repository.
I try to add the dependency in the following methods:
Select the main project -> Maven -> add dependency.
This adds the dependency details into the pom but with a type value detail of <type>pom.lastUpdated</type>
Select the project pom.xml file -> Maven -> add dependency.
This time the artifact for the 0.0.1-RELEASE is greyed out I can select it, but I guess nothing is actually happening.
The original 0.0.1-SNAPSHOT it selectable, and if I use this I do not have a <type> detail in the pom.
I don't understand why there is a difference in the RELEASE and SNAPSHOT artifacts, as they have both been generated in the same way, and clearly they are both visible in the browser, the contents of the directory on disk are the same. The file names and contents are identical with the exception of the word RELEASE or SNAPSHOT.
I know that I can simply add in the RELEASE jar to my build path, but this seems to be a ridiculous thing to have to do if I intend to use maven (or do I need to do this).
I don't want to use an external repo for storing my artifacts, and I'm not too keen to go to the trouble of installing nexus (or similar) on my local machine (just because I've had trouble with it in the past).
What am I missing so as I can get my maven project to see my local repository and all its artifacts.
Thanks in advance.
David
ps I've already tried things such as mvn dependency:purge-local-repository which definitely pulled in / updated all the local jar dependencies.
So I've managed to work around my problem.
As such this solution is ridiculous, and breaks all the purpose of maven.
So I found (from running maven from the cli) that there was an error in the parent of the project I was attempting to use.
The parent was missing a direct link to the scm plugin (version error).
Once I solved this problem, I then returned to the sub project, and got a lot of errors from missing stuff from the parent.
Essentially it was not 'seeing' all the log4j dependencies.
The solution (well non-solution really).
Add all the log4j dependencies to the sub project.
Edit in SCM and surefire test plugins (as it also started to fail the test code due to missing junit).
So this is great.
I have to define all my dependencies on log4j and in my sub / child project's pom.xml file.
I also need to define them all in my parent's pom.
As it then still refused to run tests in my new project (that used the above as a dependency), and refused to find log4j also. I then decided to add all of these as dependencies for my current project.
Great.
I thought the whole point of maven was I could define my dependency on log4j in my my logging library that I use (which is the dependency), and then it would 'automagically' pull in all the required from this dependency.
Clearly not.
As stated at the start. This is NOT AN ANSWER it is a crazy work around.
My logging library that I use should be able to define its own requirement on a specific log4j version (such as moving from log4j to log4j2), and then when I include this as a maven dependency any change to the required dependency should be seen automatically.
But No : I have to import the dependency on log4j in my other projects also. So now if I had updated my logging library from log4j to log4j2 I would need to go to all my project that use this library and update their pom's to ensure that I have the correct version of log4j.
Seems the whole point of maven has just been lost!
Can someone please tell me where I am going wrong!
David.
I'm using Intellij 13, I've been using Maven quite happily for awhile now to manage the JAR dependencies.
But the last few I've imported are causing a broken classpath issue, and they're not being installed to the repository.
I though it might be just the JSONPath library, but when I tried to install Selenium drivers it also happened with those libs. I checked the local repository and the directories exist, but the JARs haven't downloaded.
This only started happening recently, and a lot of other dependencies have been installed fine (but not since this issue started happening). I'm really not sure what might have caused it.
Does anyone know how to troubleshoot this? Or why the JARs aren't installing? And can I just trigger an update somehow from Intellij to try to reinstall them?
Quick Edit Here:
I tried installing the modules using Intellij's "add library" feature. It installed them fine, whereas before I was just updating them directly in the pom.xml and it was downloading them.
The library feature seems a little better because it automatically adds them to my output artefacts anyway, but it would be nice if it also updated the pom so I can use it outside of the intellij environment.
So I'm not sure why updating the pom.xml isn't working any more...
I've had this issue in IntelliJ IDEA 2017 Ultimate.
After changing dependency versions, the IDE was unable to fix the path on its own. I went to my ~/.m2 directory and deleted all of the dependencies for the problem jar and then executed the "ReImport All Maven Projects" action. When it was complete, the dependency issue was resolved.
I had this problem with the Community version of IntelliJ Community edition. I was able to solve the problem using this process:
Click "Help" menu
Click "Find Action" and type "Maven Settings."
Click "Maven Settings."
Click the arrow next to "Maven" on the left hand side, to see the submenu
Click "Importing"
Check "Import Maven Projects automatically" and click "OK."
This should pull in all of the Maven dependencies from the pom.xml file, without you needing to manually add the libraries.
I hope this helps.
I have encountered a problem like this.
I resolved it as follows:
Project Structure >> Modules >> your module has problem >> Dependencies
then double click the jar that have problem, go to "Configure Project Library",
and then click "+", i.e. I add dependency jar manually, otherwise, the dependency jar is red (i.e failed status) or have none.
It's not really an answer, but I moved some stuff around the POM's and it seems to be working. I've got a bad internet connection, and I found that it kept stalling trying to download some of the jar files, and Intellij didn't seem to time out when it did stall, I ended up having to restart it each time it stalled to get the JAR's to download.
But it's working okay now by just editing the pom files, which is more convenient for me than libraries.
In my case I was having this exact problem because I was trying to import a local jar-with-dependencies without classifier. To solve this I just needed to add <classifier>jar-with-dependencies</classifier> to the maven dependency, e.g.:
<dependency>
<groupId>com.my.group</groupId>
<artifactId>myartifact</artifactId>
<version>1.0</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
Hope this helps someone.
There can be different root causes of this issue. For me problem was that I had a maven settings file with a different name. Problem resolved after I went to intellij maven settings and updated the maven settings file path and then after maven refreshed my projects.
I solved the probelm by deleting it in module dependencies, and then importing it again.
Forgive me asking following questions. I am totally lost in regards to maven+eclipse. I checked out someone's java project (maven built) from SVN to my local eclipse (kepler). When I click Windows > Preferences, I see Maven.
question 1)
Is this a maven plugin? When developers say maven in eclipse, are they referring to maven plugin? maven and maven plugin are two separate components?
question 2)
when I click on user settings, C:\Users\myName.m2\settings.xml is missing. Exact error message is "User settings file doesn't exist". Does it get created when you install maven plugin at first time?
question 3)
I found three folders may have to do with maven C:\workspace\maven_local_repo_artifactory directory, C:\maven_local_repo and C:\Users\myName.m2\respository but not sure how they get created and what is the relationship among them.
question 4)
Is it ok to remove current maven plugin from eclipse and re-install it then check out the java project from SVN? I think my maven or maven plugin settings are not correct in my local box.
1) Is this a maven plugin? When developers say maven in eclipse, are
they referring to maven plugin? maven and maven plugin are two
separate components?
Yes. This is the maven-plugin. maven-plugin uses the configurations of maven (%M2_HOME%/conf).
If you wanna work with maven, you need to install it on your machine. Then you can run maven commmands. In addition, if you want to invoke maven commands within eclipse (conveniently) - you can install the eclipse-plugin. "maven-plugin" is a plugin for eclipse, that lets you use maven within Eclipse conveniently.
2) when I click on user settings, C:\Users\myName.m2\settings.xml is
missing. Exact error message is "User settings file doesn't exist".
Does it get created when you install maven plugin at first time?
By default, the maven-plugin assumes that your settings.xml (which is the configuration file of maven) is in the path you have mentioned. However, there are cases (like in my case) where the config file is not there, but under %M2_HOME%/conf. you can update it in Eclipse, and the error will disappear.
3) I found three folders may have to do with maven
C:\workspace\maven_local_repo_artifactory directory,
C:\maven_local_repo and C:\Users\myName.m2\respository but not sure
how they get created and what is the relationship among them.
C:\Users\myName.m2\respository is the "local repository". If you learned a bit about how maven works, it holds a local repo on the local machine, and it keeps there all artifacts. It downloads them from the "repository" - if you have one in your company (Nexus, Artifactory, etc) or from Maven Central. However, this path is configurable by Maven's settings. So there might be that someone played with it and changed the path, and these other directories were created. You did not mention what resides inside these paths...
4) Is it ok to remove current maven plugin from eclipse and re-install
it then check out the java project from SVN? I think my maven or maven
plugin settings are not correct in my local box.
Sure it is OK. You may remove the plugin, and the source plus maven itself will not be deleted from your machine.
HTH.
so I have started using maven (with eclipse, and a local implementation of Sonatype) not that long ago, after getting through the initial pain I though everything was working.... apparently not !
I have my main project POM and all my child POM (I am using a 'flat' hierarchy, so all the sub projects are in the same folder as the parent POM). This seems to be working OK.
The sub project where all started and 'released' and tested before I started using Maven. I went to maven to solve my 'dependencies' problems... or rather make them more complicated in this instance.
Most of the 'Maven' stuff seems to work fine, but I can't resolve the dependencies of my 'sub projects' that have been released into my local ms/repository
Each day I start up eclipse and have the same problems, I have 'unable to resolve imports' on all my personal libraries, and all those that I use for them (such as Log4j, DDlUtils etc).
I thought the whole point of maven was that I would be able to put in an import declaration for a library, add the 'groupID' and other stuff to the child POM (or parent POM). And then have all the jars downloaded automagically when I run
mvn install
against the parent.
However each day I find I have to re-insert the build path to the libraries (internal and external) via the eclipse workspace and point them to the location of the libraries that I have downloaded as maven can't seem to find them anywhere.
Specifically with running Junit test, I can run them from the workspace (using run as junit) and they all pass fine. But if I try to run them with
mvn test
I get an message saying
java.lang;NoClassDefFoundError: org/junit/Assert
(and this is the same from within eclipse running the mvn test or from CLI)
with an error message in the output of
failed to execute goal org.apache.maven.plugins:maven.surfire-plugin:2.10:test
the POM and jar are in my M2_REPO, and I can find it when I search in sonatype, why can't maven find something that is part of its own system, exists in its repo.
but this obviously works just fine when I run via eclipse and point it to an independently downloaded junit library.
I don't know what extra info you may require, and I'm obviously missing something in either the m2e plugin, my maven install or in sonatype.
please help I'm begining to loose my hair!
and may soon be forced to return to an ant/ivy solution (but don't want to have to learn 'yet another tool' (in this case ivy).
Thanks in advance
David.
ps. i'm on a windows XP platform
edit...
can I get maven to build and release the jar and pom even though it thinks it is failing the tests (which is itn't as I'm doing them manually, and they pass just fine).
If I look in the 'effective POM' tab of my parent POM, the plugin stated above is not in there. I guess this means it is a maven config setting, but where do I add it, and why isn't it automatic when I run my first set of maven tests?
edit 2....
I just found this on the apache plugin comments page (http://maven.apache.org/plugins/maven-surefire-plugin/plugin-info.html), so I ran the code on the CLI, mvn surefire:help -Ddetail=true -Dgoal=test lots of stuff was downloaded, and now the tests run, but they fail within maven ? (remember they pass when run from eclipse using 'run as junit test)... so this is nearly a solution...
It sounds like you need make eclipse aware that the projects in question are Maven projects. You may have POMs set up for your projects, but for the m2e plugin to work you need to have either created the project as a Maven project ('New' -> 'Project...' -> 'Maven' -> 'Maven Project...'), or converted it into a Maven project by right clicking it then selecting 'Configure' -> 'Convert to Maven Project'. You will know that a project has been recognised as a Maven project because there will be a little blue 'M' in the top left of its icon, as shown in the screenshot below:
The main thing to note in the above picture is the 'Maven Dependencies' library. This is set up automatically by the m2e plugin. Whenever you add a dependency to a POM then the project's build path will be configured automatically, although sometimes you may need to force it to do so by right clicking the project and selecting 'Maven' -> 'Update Maven Configuration'. The important thing is that if everything is working then you should never have to update the build path yourself. Moveover, if you do update it yourself then any changes you make will likely get overwritten the next time you run the 'Update Maven Configuration' command.
Also worth noting from the picture is that the two dependencies 'mavenProjectTest' and 'primes' have folder icons next to them. This means that they have been picked up as workspace projects. For this to work the project must have 'workspace resolution' enabled, and the projects to be picked up need to be configured as m2e Maven projects as well.
You mention downloading external libraries. You shouldn't need to download any libraries yourself - by adding the right dependency declaration for an external library then Maven will download it from your configured remote repository (the first time anyway - afterwards it will then be able to get it from your local repository). By default, this is the Maven Central repository. To add an external library to your project just follow that link, enter the library in the search box, click on the version link for the version you require, then you will be taken to a page where there will be the dependency XML declaration that you can just copy and paste into your POM.
One more thing that may help is that you should make sure that your source folders follow the Maven default directory structure. That is, your test packages should be contained in a source folder called 'src/test/java', and the main project packages should go in 'src/main/java'. Otherwise Maven will not know where to find your source code. It is possible to configure a POM to tell Maven to expect your source code to be in different source folders, but it is highly recommended that you follow the standard Maven directory structure.
Since you have child modules, my suggestion would be to simplify things by creating a new Maven project from scratch that you can have a play around with. Once you are comfortable with that then try getting m2e to work for your multi-module project.
I remember your pain when first getting to grips with Maven, but it's great once you understand what it's doing and everything is working. I highly recommend reading through the free online book Maven: The Complete Reference - it helped me out a lot when I was getting started with Maven.
I have experienced the same messages and have found a working solution, thanks to one of my organization's Maven experts.
Here was my pom.xml that reproduces your error:
<dependencies>
<dependency>
<groupId>org.junit4</groupId>
<artifactId>org.junit4</artifactId>
<version>4.3.1</version>
</dependency>
</dependencies>
With it, I would get package org.junit does not exist messages and NoClassDefFoundError: org/junit/Assert. Similar to your experience, it worked great from Eclipse, green bars and all.
Here is the pom.xml that works:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
I copied this from the example at the top of this Using JUnit page.