Eclipse and Maven-Wrapper - java

I try to build a project, which is using the Maven Wrapper. The build works fine on command line. There is also a plug-in for IntelliJ Idea. However, I haven't found any article, how to build such project with Eclipse.
Do you have an experience with project build by ./mvnw command instead of mvn in Eclipse, please?

As implied by the comment from LMC, the Java edition of Eclipse will come with the "m2e" plugin, which will automatically recognize a project with a pom.xml file as a Maven project, and it will automatically note the dependencies, download them, and compile your source code with those artifacts as dependencies.
That deals with dependencies and compilation. If your build is running unit tests with Surefire, or generating code with particular plugins, unless there is a specialized m2e connector for that plugin, Eclipse will not know to do that.
Inside Eclipse, if you need to run a Maven build, you don't need to care about "mvn" vs. "mvnw". Eclipse will have an embedded Maven installation.

Related

Automatic Install of Maven Projects in Eclipse upon Build

Is there a way to let eclipse automatically run 'mvn install' when it builds a project (e.g. when a source file in the project is changed)?
My problem at the moment is that I have a large number of projects in eclipse, each of which is a Maven project as well. Projects depend on each other through Maven dependencies but are not parent/child projects.
My workaround is that I have a bash script running in the background which checks for changes in all directories for these projects and triggers 'mvn install' for every changed project. Unfortunately, this creates some problems since for some projects I have to call 'mvn clean' as well and this makes the eclipse projects unusable until I manually rebuild the project in eclipse (Maven -> Update Project ...).
Did you try Eclipse builders?
You may attach a builder to your different projects.
The builder will call your bash script each time its related project is built.
See the following article for reference: Non-Ant project builders

How do I compile and run Intelij IDEA java project without IDE?

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.

Maven dependecny is not available in eclipse java build path

I checked out an existing eclipse project from SVN. Then I converted it to Maven project.
The project is compile with Maven target clean install perfectly no problem. But the eclipse doesn't identify any dependency jar file. Basically it does not know the Maven repo path. It knows only JDK path. So all my java classes are with full of red lines.
Everything in this site and google I checked all fine. But why eclipse can not find the mvn repo?
eclipse version = JUNO Version: 4.2.2. ( I think this has inbuilt maven plugin)
Maven plugin detail = M2E - Maven Integration for Eclipse version - 1.4.0, Provider - Eclipse.org -m2e
UPDATE ======================
If I checkout the source code separately and import it as a maven project that way its working. But I want to know why if I checkout the code through Subclipse and convert it to maven project is not working?
Run
# use maven to control your eclipse .project and .classpath files, that is
mvn eclipse:clean
mvn eclipse:eclipse
and then restart your eclipse (or switch your workspace and then back).
Make sure you have the m2e plugin, - from here, you should read the Release Notes and add this to your update sites - "http://download.eclipse.org/releases/juno" and "http://download.eclipse.org/technology/m2e/releases".
In Eclipse, you can actually create an external tool Run> External Tools> External Tools Configurations. After this you can select your project that you want to setup and run this external tool.
or if you have maven plugin installed in eclipse, select your project right click Run As > Maven Build... (see below image). In Goals put "eclipse:eclipse" and click Run

How can I make eclipse make use of packages downloaded by maven?

When I use Maven compile, it will automatically download the depended java packages for me. Now, to debug the project, I import the project into Eclipse, but in Eclipse, the depended package is still missing. How can I get the packages? Or, can Eclipse use packages downloaded by Maven?
You don't really need to manually add all the dependencies downloaded by maven to the classpath in Eclipse. There is a maven-2-eclipse plugin which integrates maven with Eclipse. Using that plugin you can
import/create a project as Maven project or
convert an existing project into a maven project
Your Eclipse will automatically add all the downloaded dependencies on the class path everytime.
An alternative to the m2e eclipse maven plugin suggested by rocketboy is to use the maven eclipse plugin. This works from the command line (mvn eclipse:eclipse), and generates Eclipse settings for your project by downloading dependencies and putting them onto the Eclipse build path.

Errors after importing Maven project into Eclipse

I imported a Maven project into Eclipse. I was able to deploy it from the command line. In Eclipse it is full of red Xs. I have cleaned the project, updated the configuration and I ran the following command:
mvn -Declipse.workspace=<pathtoworksapce> eclipse:add-maven-repo
and I still have the same problem. The project is dependent on another project.
What I ended up doing was removing all of the projects in Eclipse, but not deleting the source files. Then instead of directly importing the code as Maven->Check out as Maven Projects with SCM, I selected Existing Maven Project and imported the code from my local machine. This got rid of the errors, but when I would right click on code and select "Open Declaration", I would get Error: Could not open the editor: The file does not exist" So I removed all projects again and this time I deleted all the ".project" files and repeated the import Existing Maven Project. So now there are no red Xs (dependency problems) and the lookup functionality within the code works.
Go to your master project and type the following :
mvn install
mvn eclipse:eclipse
After that, import your project. You can also install m2eclipse for better support. If you use gwt or any other framework which has a custom maven execution, you should also install plugins for those in Eclipse.

Categories