Maven Project using Eclipse doesn't compile - java

I have been trying to make a simple Spring project using Eclipse and Maven but I am running into problems. The first one I am trying to resolve is the fact that my code doesn't seem to compile.
For example, if in a class I type Strrrring test = new String(); there is not error at all displayed by Eclipse. I checked the Properties of the project, under Java Compiler and everything seems to be fine.

Command Line
If you have maven installed, you can make maven project working in Eclipse via mvn command. At the root of the project run:
mvn eclipse:eclipse
If you want to view the source/doc of the artifact used in your project, you can run following command instead:
mvn eclipse:eclipse -DdownloadSources=true
Eclipse Plugin
Or if you prefer use Eclipse plugin, you can install m2eclipse plugin and re-import project

Right click the project and do run as maven clean and maven install . It will work fine .

Related

Eclipse and Maven-Wrapper

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.

how to run maven project from github in eclipse

I use eclipse and I want to compile and run this code from gitub https://github.com/openphacts/Validator ,it needs maven project to build it but unfortunately I don't know how to proceed with it. Can someone help me how to get this project into eclipse to run it and test it in my machine please? It's emergency
Once you've checked out the project from github, you need to utilize maven to install the dependencies and build the project. In the root folder of the project (where the pom.xml is located), enter the following in your command line:
mvn install
More details can be found here: https://maven.apache.org/run-maven/
Additionally, you must first download the maven command line tool: https://maven.apache.org/download.cgi
And install it: https://maven.apache.org/install.html

Maven from command line with multiple eclipse projects

Suppose I have the following file/project structure.
MSPCommon/trunk/pom.xml
MSPWebManager/trunk/pom.xml
and MSPWebManager depends on MSPCommon and MSPCommon and MSPWebManager are in the same directory.
I have imported these projects into eclipse, and within eclipse I can successfully do maven builds on MSPWebManager (like mvn clean compile) IF I do it the following way. Go to Run -> Run configurations, type in the maven commands AND select Resolve Workspace artifacts.
That's all great, but what I would like to be able to do is run the same maven commands from the command line. So I navigate to the MSPWebManager/trunk directory, do a mvn command like mvn clean compile and this is the result:
As you can see there is one other local jar that is missing, but for simplicity I only included one in this question because I'm assuming the fix is the same for them all.
Also, if I do some type of build within eclipse but I do NOT check the Resolve Workspace artifacts, I get the same error as I do on the command line.
Any suggestions on how to get this to work from the command line?
Thanks
Go to the module MSPCommon and run a mvn clean install then go to MSPWebManager and do the mvn clean compile
mvn install resolves the dependencies and installs your build inside of your .m2 repository / folder.

Java Eclipse Build Path Errors Maven

I am just starting out with Maven. Is there any way to get maven dependencies to be added to the Eclipse project's build path? As of right now, my project is full of red x's due to Eclipse not being able to include some external class from one of these dependencies.
First you need to setup you M2_REPO variable. This is a class path variable that tells eclipse where your designated maven repository is located.
You can setup M2_REPO by running the following command in your workspace.
mvn -Declipse.workspace="replace with your Eclipse Workspace" eclipse:configure-workspace
Next make sure that your project has a maven fact applied by running the following command
mvn eclipse:eclipse
in the workspace of your project. run
mvn clean package
just for good measure to make sure all your dependencies are resolved and available before restarting eclipse.
Once you restart eclipse again and bring your project up your issues should be resolved.
You should look up more information about these 2 commands and how to use them effectively.
Save yourself a ton of hassle and get the M2Eclipse plugin. The plugin will handle all of the project setup for you and you don't have to worry about doing the mvn eclipse:eclipse commands.
http://www.sonatype.org/m2eclipse/
have you executed
mvn eclipse:configure-workspace -Declipse.workspace=/path/to/workspace
?
You need to execute it so maven set the M2_REPO path to eclipse. Or you can set it manually.
Remenber to restart eclipse after you do so :P

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