m2e maven eclipse plugin not configure the build path - java

I import a project to my workspace and convert it to Maven project using m2e and ran the pom file with goal specify "clean install".
But my project build path is not populating with the jars already downloaded to my local repository which still gives compilation errors in the source.
When i expand "Maven Dependency" variable in the library tab of build path, i can not see the jars already downloaded?

Was there existing Eclipse metadata when you imported the project, perhaps from another developer? This is a frequent cause of failure in Eclipse, especially if you have metadata from the earlier m2eclipse plugin.
I have encountered the situation many times (in Juno and Kepler) where the .classpath is incorrect, resulting in the symptom you describe, and I either have to rewrite the .classpath myself or nuke it and encourage Eclipse to try again.
In your case:
delete the project from your Eclipse workspace (but not the filesystem)
delete the subdirectories .settings and target, and the files .classpath and .project from the project directory
re-import the project into Eclipse via File -> Import... -> Existing Maven Project
The Eclipse dot-directories will be created from scratch, and the project should already be configured as a Maven project; artifact retrieval should start in the background.
If this fails, check the 'Maven Console' in Eclipse for clues, and/or the Eclipse Error Log.
As other people have commented, you need to ensure that your m2 settings file is being correctly interpreted by m2e.
Can you build successfully from the command line?

Related

Why sometimes eclipse doesn't need .project and .classpath file during importing into workspace/How does eclipse recognize projects as projects?

I just checked out some projects from svn to my pc, and I tried to import the projects into my workspace.
But I failed to import some of them, and eclipse didn't recognize those projects(didn't show up in the import window).
And then I turn to google and found a solution -"add .projects and .classpath file to project folder" works.
However, what make me really confusing is that I foundthe projects I successfully imported into workspace without manually adding the files for them also don't contain .projects and .classpath. Eclipse just create the files for them automatically after import, so it seems that the fail of importing projects(or recognizing projects during import) is not just simply because of the lack of .projects and .classpath.
Does anyone know what cause the difference?
How does eclipse exactly recognize a project as importable project?
*eclipse version info here
Eclipse or any other IDE doesn't required .classpath or .project files. These files will be auto created during the project import. IDE can capable to pull the artifacts from maven central repo automatically by using build descriptor file such as pom.xml or build.graddle.
The files .classpath and .project will store the paths from local machine, if we carry them to another system, the artificats and other dependencies may not be present in the same directory, so it will start complaining build errors. Thats why while committing to GIT always there is .gitignore, so that local configuration will not carry to others while contributing.

Eclipse, Tomcat & Maven workspace resolution: wrong folder structure?

I am trying to build a spring-mvc project that has another project (core, as .jar) as dependency.
If I disable "Resolve dependencies from workspace projects" in eclipse, install the core into my maven repo and run it from eclipse, the application works!
What I want to do, is re enable "Resolve dependencies from workspace projects", but there is the problem: When I try to run the project on tomcat (after maven clean, project clean), I get a "FileNotFoundException". The file in question is under src/main/resources/META-INF/spring/applicationContext-core.xml
It seems, the File can not be found in the classpath.
I looked up the deployment location and found out, that everything of the core is under the following folders:
WEB-INF
classes
So the file I am missing can be found here:
/WEB-INF/classes/META-INF/spring/applicationContext-core.xml
But it schould be here:
/META-INF/spring/applicationContext-core.xml
Why is the structure of my core dependency so messed up when I enable the workspace resolution and how can I fix this?
I am using eclipse mars with m2e..
Thanks for any help.
Edit:
Project structure (core) looks like this:
project structure

"Could not find or load main class" after removing Maven nature and files (pom.xml, target/) from an Eclipse Project

I accidentally converted my project to Maven by going to Configure > Convert to Maven Project. Now I want to undo this. I read that I need to right click Maven > Disable Maven Nature and that worked fine. However I want to totally remove Maven, so I deleted the pom.xml and the target folder. When I try to run my code now, I get the error:
Error: Could not find or load main class
So what am I missing? How do I revert from a Maven project to a non-Maven project?
When you convert a Java project to a Maven project in Eclipse, the Maven Integration for Eclipse (m2eclipse) configures the Java incremental compiler to put the compiled class files in the same location as Maven would put them, i.e. target/classes.
So when you remove the Maven nature and delete the target folder, you now also have deleted the compiled class files and your project can no longer run. AFAIK, the incremental compiler doesn't detect when you remove its output files, so you need to trigger a rebuild by cleaning the project (Project > Clean...)
This will fix the problem that you can not launch your project, but may re-create a target folder. If you also want this to be "fixed", you can switch back to some other folder name for the binaries, e.g. bin, in the project's Java Build Path configuration on the Source tab.
Is it basically a Maven project, i.e., do you have and maintain it through a pom.xml? Then my suggestion is to delete the project in Eclipse but keep the files on the disk (i.e., it removes it from the workspace). Then, run a simple mvn eclipse:clean eclipse:eclipse which creates a simple Java project without the Maven nature based on the POM (so the libraries are linked and the source/output directories are set up correctly - this may solve your ClassNotFoundError).
If it's a simple Java project, I would advise deleting it from the workspace, removing the .classpath and .project files and importing it again with the Create a Java project with existing sources wizard.
Either way, make a backup of your project before you start doing anything :-)

Why can I not add .jar to eclipse git repo?

I am using Eclipse Kepler for Java. Normally you can add internal/external .jars to a Java project in the build path located in the properties. Why, when I clone a git repo and import it into my projects, do I lose that ability? I don't understand. I kinda need to do that.
This is probably because the .gitignore has been configured to ignore .jar
Open the .gitignore file and remove the line *.jar, you should be able to add it.
======
As an aside - usually, for Java projects .jar files are not committed to repository (as they are large & it can slow down repository cloning), instead maven or gradle is used to configure dependencies. Example - http://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/
Then when you want to work with eclipse just run mvn eclipse:eclipse to generate the necessary files. .gitgnore is usually set up to ignore *.class, *.jar, .project, .settings, .classpath
I found that if you open the run configurations and go to the Classpath tab that you can add internal/external .jars. The run configuration can be accessed by clicking Run > Run configurations. I added my .jar to the user entries. The bootstrap entry caused a null pointer.
When a project relies on libraries/modules, it's best to use a build tool for dependency management. JVM ecosystem is dominated with three build tools: Gradle, Maven and Ant.
How it works:
In a build script we declare dependencies of the project. This tells the build tool where to retrieve libraries/modules our project depends on. Dependencies are resolved at runtime; downloaded from a remote repository, retrieved from a local directory or if required another project to be built in a multi-project setting.

migration an Maven projet from eclipse to a command line environment

I got an Maven project which is compiled in Eclipse. Now I need to migrate it to a Linux environment, and there won't be GUI interface I can use. I wonder what I should do to migrate it?
Currently , under Eclipse project folder I have the files/folders as the below:
.classpath
.project
.settings
.springBeans
doc
pom.xml
src
target
I figure all those .* folders are Eclipse meta data. so I can remove them. Then I can use the rest to form a Maven project that I can build using Maven command lines?
For a maven project to work command line, all you need is
Maven is installed and correctly exported in the $PATH variable
The pom.xml in your workspace.
Just go to the project directory and run mvn install.
mvn clean
then remove .project .classpath
if you want to lose eclipse project settings while migrating delete .settings (assuming it doesn't have machine specific path/settings)
copy rest to new linux environment
open eclipse, import project as maven project (assuming you have new eclipse with maven plugin setup on linux environment)
Note:
make sure you still have a backup before you successfully migrate over
.classpath contains references to local .m2 when used with eclipse and maven so the path would differ in linux and would create issue
.project contains some configuration that is eclipse maven plugin dependent, so it is good to loose it once and let new environment create new one

Categories

Resources