When working in maven module, what's the difference between doing in intellij build -> Make Project and Maven Projects -> Root pom -> Compile phase.
Does intellij calls maven?
Does both of them compile the sources to the same place?
Do they both copy resources files?
Why do we need both options?
Does intellij download the dependencies automatically and we can just call project make, without using maven compile?
They are actually quite similar in terms of the task they perform which is to compile the source and test paths of the project with javax.tools.JavaCompiler by default.
Does intellij call maven?
No it doesn't by default. Remember that this is just IntelliJ's built in Java compiler and some Java projects don't use maven.
Does both of them compile the sources to the same place?
Yes, they use the same source files to compile if that's what you are asking here.
Do they both copy resources files?
Yes they both copy the resource files to different locations though.
Why do we need both options?
We don't need both options. Maven compile command checks the source code against any syntactical errors which effectively covers the work done by IntelliJ's make option.
Does intellij download the dependencies automatically and we can just call project make, without using maven compile?
Intellij's compiler can be considered as syntax compiler which is why you need maven to handle your project's dependencies.
No, IntelliJ doesn't call maven, but get all information from the pom.xml e.g. output directories libraries etc.
So don't worry, you can call make from IntelliJ for compiling and running your application.
If you have some special goals in your maven build file you can run it from the maven window.
All maven dependencies will be downloaded from IntelliJ an stored in the maven local repository.
Let's think we have a Project A which is use Maven Project B.
If you had changed B project you have to update this project on A. Then you have to compile B in A.
But if you had changed only A you dont have to compile Maven.
Related
I am quite new to eclipse and want to develop a maven project in java.
Compilation from within eclipse works but
If i get a compilation error on the eclipse console,
there is no link to the source code.
I would expect eclipse to have such a link.
Does it exist? and if so, how to activate it???
Maybe the problem is, that i already have a maven project
and now want to use eclipse on it.
If you're developing a Maven project in Eclipse, you should create it as a "Maven Project", which will utilize the "m2e" or "maven2eclipse" plugin. When you do it this way, then Eclipse will use the same source folders your Maven build will use (defaulting to src/main/java and src/test/java), and Eclipse will look at the dependencies specified in the pom.xml file and make sure those dependencies are all downloaded and available for the Eclipse compiler. If this is all done properly, then if there are any red marks in the project, then those represent the same compile errors that you would get if you built the Maven project from the command line. Watch out for any red marks in the pom.xml file itself. When that happens, Eclipse doesn't attempt to compile anything.
I've been coding Java in Eclipse for awhile without needing to specify dependencies. Now that I learned how Maven does it, I'm wondering: how did Eclipse build projects on its own? How did Eclipse figure out which versions of imports, and which dependencies of dependencies, are needed to make everything work?
Finally, what are the advantages and disadvantages of building a project in Eclipse by starting with New->Other->Maven Project instead of New->Java Project?
To the first question: Eclipse doesn't add any dependency in a standard Java project. You have to manually add to the Build Path all needed JARs, otherwise you'll have compilation errors.
To the second question: if you create a standard Java project Maven is not used, even if you create a pom.xml file in the root of the project. You can always convert a standard Java project in a Maven project (see Convert Existing Eclipse Project to Maven Project).
Your dependencies has always to be in the classpath
When you start a project with Maven, Eclipse will automatically add the Maven repository to the classpath.
When you start a Java project you have to link your library manually in Eclipse and the version of the library is the one you've downloaded.
You can see the difference in your project's Properties > Java Build Path > Libraries
Recently I was trying to run 2048 bot. I'm not a java programmer and installing IDE just for running one program would be overkill. So I tried compiling and running it from command line, but that was not a simple task for me, mainly because of the dependencies. Then I was told, that maven might come in handy. So I wonder if one can easily compile and run a program using maven or whatever tool they have without installing IDE?
The pom.xml file will have everything in it you need to compile it. In this particular case, it is only declaring a single dependency, the selenium-firefox-driver. With maven, all POM (Project Object Model) files inherit defaults from a "master" parent POM file. Maven uses a "convention over configuration" philosophy. Anything not explicitly configured, defaults to standard configurations from the parent pom that is part of maven. That is why you can build a project from such a seemingly simple POM file.
You will not be able to run the build from the IntelliJ IDEA module (.iml) file. In fact, IntelliJ IDEA generates that file from the POM.
First, make sure you have a Java JDK installed. Java 8 is the latest current. But a Java 7 JDK would be fine. After that, the Running Maven link #jeroen_de_schutter provided has all the information you need. Click on the top link in that document to Download and Install Maven. Once that is done, from a command line, navigate into the directory that contains the project (i.e. the directory with the pom.xml file in it) and issue the command: mvn compile to compile your code, mvn test to compile and test, or mvn package to compile, test and package the code. You can add clean to that any of those commands so maven will do a clean build. For example: mvn clean package. See the second Quick Start and third Use Maven links in the Running Maven document for more details and information.
Please note that the first time you run a build (any maven build) it will take quite a bit longer than normal. This is because maven has to download (and cache) a ton of plug-ins and dependencies. Once that is done, the builds go much much quicker. However, the first time you build a new project, the first build make take a little longer as it downloads and caches the dependencies and plug-ins needed by that project that have not already been retrieved.
Yes you can, make sure you have a Java Development Kit and Maven installed. Then by following the Maven user guides you should be able to build it and run.
But it might not be straightforward if you have never used maven, so I would recommend to ask the assitance of an experienced java developer, if you happen to know one.
I am trying to add java code from a Maven project (called docx4java) which I checked out from svn to an existing Eclipse project (called DocumentManager). I have tried the normal way, that I thought would work, i.e.:
Right Click on eclipse project>Properties>Java Build Paths> Projects > Add (here I add the Maven project) and >Libraries (here I specify Native Library location e.g. docx4/trunk/docx4/src/) but I still can't get the 'Maven' classes to be recognised in eclipse. I get the message
import docx4j.src.main.java.org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator cannot be resolved
I have tried adding a test project that was compiled in Eclipse and that works fine, Eclipse seems to recognise it i.e. import org.me.TestProject works fine.
How can I get the code from the Maven project docx4java to work in the Eclipse compiled project DocumentManager?
You can generate eclipse poject files (which you can just import into your Workspace) using the maven eclipse plugin
Take a look at these ecplise plugins for a more direct integration of maven into eclipse
You should create a eclipse project for docx4java as #Attila has commented. Once that is done, you should have two projects on your workspace: docx4java and DocumentManager. At this point, what you are doing now (adding a project reference to the Java Build Paths) should work.
It seems that the source path is not configured correctly, this is why the compiler cannot find your "Maven classes".
docx4java.src.main.java...
Maven has a different directory structure and you have to tell Eclipse where to find your sources.
For a "vanilla" eclipse project, remove the standard eclipse build path src and add the maven source path src/main/java (or whereever you added the code), the compiler should correctly pick up your sources.
Note that you still have to add all jars mentioned in the dependencies section of the maven pom.xml file. Otherwise it won't compile, even if it finds your added java classes.
(Addendum: I would recommend to use maven in your existing project as well.)
I am using Buildr with a java/scala project.
Dependencies are descried in the buildfile. An as you may know, Buildr downloads dependencies into ~.m2 folder (as maven2 does).
I am wondering how can I import dependencies (from ~.m2 folder or buildfile) into my Intellij project to enjoy the code completion and error detection among other features offered by Intellij.
Thanks,
-A
buildr has a plugin to generate IntelliJ IDEA projects. It's described here:
If you use IntelliJ IDEA, you can generate project files by issuing:
$ buildr idea
It will generate a .iml file for every project (or subproject) and a .ipr that you can directly open for the root project. To allow IntelliJ Idea to resolve external dependencies properly, you will need to add a M2_REPO variable pointing to your Maven2 repository directory (Settings / Path Variables).
If you’re using IDEA 7 or later, use the buildr idea7x task instead. This task creates the proper .ipr and .iml files for IDEA version 7. It includes the -7x suffix in the generated files, so you can use the idea and idea7x tasks side by side on the same project.