When running the following command in the terminal, I can see in the target directory the JAR file, whereas when building with IntelliJ I only see the compiled classes.
Why?
To get the jar built by IDE you need to configure the jar Artifact to build:
If you want to build your project and execute run actions through Maven, you need to delegate all those actions to Maven with the Delegate IDE build/run actions to maven option located in the Maven settings.
Build a project with Maven #
Click icons general settings svg in the Maven tool window. Alternatively, from the main menu select File | Settings/Preferences | Build, Execution, Deployment |Build Tools | Maven.
Click Maven and from the list, select Runner.
On the Runner page, select Delegate IDE build/run actions to maven.
more detail see here
Related
I'm cloning my maven project from GIT and then doing mvn clean install. My dependencies are downloaded successfully, but I'm not able to see it in External Libraries. Also my code shows red colored as if dependencies are not available. I did Invalidate cache/restart, did re-cloning, removed .idea folder, but no luck.
Any solution to this?
THanks!
Make sure you have opened the Project as Maven project and that it has been imported successfully from Maven pom.xml build file. In an existing project you can import Maven from Maven tool window. See Link a Maven project
steps:
Open the Maven tool window.
In the Maven tool window, click the + icon to attach a Maven project.
In the dialog that opens, select the desired pom.xml file, and click OK.
I'm using Intellij IDE for Spring projects. Whenever I add a dependency in pom file, it's not downloading it. In the case of Eclipse IDE, it automatically downloads the dependency whenever a dependency is added in pom.xml file.
I added the highlighted dependencies in the pom.file but it's not downloading. How to configure the IDE for auto-download dependencies whenever the pom.xml is updated?
You can tick the checkbox "Import Maven Projects automatically"
under "settings" -> "Build, Execution, Deployment "
-> "Build Tools" -> "Maven" -> "Import Maven projects automatically"
Usually, if do some modification in pom.xml, the Intellij will give always suggest you to enable Auto Import in a small pop-up(). I think it might have suggested you already. Anyways, you can do the above.
In Eclipse project build automatically it that option is enabled as build automatically
but idea we can not load maven dependency just by adding it in pom.xml but we can build the project by
IntelliJ Idea - Preferences
Select “Build, Execution, Deployment -> Compiler” -- build Project automatically
Above will build the project but it will not download the dependency
We have to click reload all maven project icon under maven tool window which can be activated by view - Tools Windows - maven
I have one project open in IntelliJ. In that I am able to see maven tab in its left sidebar:
Also, I am able to see Maven in View > Tool Windows > Maven:
I tried to open another project in another IntelliJ window, but it does not have both of the above:
It may be not required to have that maven tool window for the project that you have opened in the second Idea instance.
If the opened project is a maven project (at least if you have a pom.xml associated with that project) you will have this option available in View -> Tool Windows -> maven
If it's a maven project, try importing the project as a maven project as well
I've installed the spring example RESTful Web Service. And I have it building fine in IntelliJ. But how do I get IntelliJ to create gs-rest-service-0.1.0.jar? There are menu commands to synchronize gradle & maven, but nothing to use them to build the jar.
A standard POM/Maven-based project can be built via the console by typing:
mvn package
the maven lifecycle, by default, will place the output artifact (i.e. JAR / WAR file) under the target folder.
Alternatively, since you are using IntelliJ, you can also use the IDE to run the build for you. The simplest way is to navigate on the right side tab
mvn > your_project > lifecycles > package
the output will continue to be placed in the same target folder.
Assuming the project has a pom file. And it was mentioned building fine in the post. Assumption: STS/Eclipse users
Right click on pom file -> run as maven build. In the console it displays where the jar file is created.
Go to: project folder -> target folder -> gs-rest-service-0.1.0.jar
file
I am trying to run eclipse:eclipse on a maven project from an ant build file.
But its failing with error:
Eclipsify:
[echo] Converting Maven Project to Eclipse Project
[artifact:mvn] -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.org.apache.tools.ant.ExitExceptio
n: Permission ("java.lang.RuntimePermission" "exitVM") was not granted.
[artifact:mvn] at org.apache.tools.ant.types.Permissions$MySM.checkExit(Permissions.java:194)
[artifact:mvn] at java.lang.Runtime.exit(Runtime.java:107)
[artifact:mvn] at java.lang.System.exit(System.java:962)
Below are the configurations in my build.xml
<project name="ConnectAll"
default="default"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
And in the ant target I have added eclipse goal as given below
<artifact:mvn pom="${pom}" mavenhome="${MVN_HOME}">
<arg value="eclipse:eclipse" />
<arg value="-Dmaven.multiModuleProjectDirectory=true"/>
</artifact:mvn>
Also i have verified that the ${MVN_HOME} property and the actual M2_HOME are same.
Can someone help me figure out what am I missing here.
Since Eclipse Juno (v4.2) it contains Maven integration.
Maven projects should be imported using the import wizard:
Eclipse Menu: File -> Import...
The dialog Import, on the page Select opens
Select from tree select Maven -> Existing Maven Projects
Press the button Next
The page Maven Projects opens
Fill in the field Root Directory, with the location where the Maven project(s) are located (Use the button Browse... to easliy select the location (This will show a selection window, when pressing OK, or seleecting a directory, it can take a while, before all the Maven projects are fuond, as all underlaying directories are scanned))
From the Projects view select the project you like to import (project which already have been imported, are shown in gray (not selectable). This can also happen if different Maven project / modules do have the same artifactid. As the Maven artifactid, is used as the Eclipse project name).
Press the button Finish, to start importing the selected Maven projects
Warning This will take a while, as many times, lost of dependencies need to be downloaded as well.
Remark Never use the mvn eclipse:eclipse, when using Eclipse with integrated Maven support, as these conflict with each other.