m2e (eclipse) Throwing error after converting to a maven project - eclipse

I'm trying to convert an eclipse Java project to a Maven project. When I convert the project to a Maven project, the pom.xml displays the following error:
Cannot read lifecycle mapping metadata for artifact
org.apache.maven.plugins:maven-jar-plugin:maven-plugin:2.3.2:runtime
Cause: error in opening zip file
When I check the lifecycle file, it's blank. Any idea of why I can't convert this project without getting this error?
Thanks for the assistance!

If that file is empty, it might have been caused by a bad download of the maven artifact. Therefore check your proxy settings in Eclipse as well as in Maven itself (~/.m2/settings.xml)

One thing you can try is deleting the project(from the workspace, not from your computer!) and importing it as a maven project using the deleted project's folder as your source. I've had a lot of trouble in the past with converting projects with m2e, but deleting/re-importing always seems to do the trick.
To import an existing project as a maven project go to file->import and select "Existing Maven Project". Select your project's folder, and import. I realize it's basically the equivalent of "turn it off and turn it on again", but like I said, it has always worked for me in the past. At the very least it will help you narrow your scope.
Hope this helps!

Related

pom.xml greyed out when importing maven project into eclipse

In eclipse Mars, I could always clone a git repository and then import it as a maven project. But this time, the pom.xml is greyed out. On the next screen only the pom of another project is showing and I can't proceed.
Are you sure you have not already imported the project into the workspace? Maybe you just don't see it. One reason can be that you are using working sets and the project is not in the group you'd expect it to be in?
If the project is already imported into your workspace, and you are trying to import another copy of the same project that resides in a different folder, you can try adding some string for Name Template under Advanced and the importing.

maven project in eclipse keeps normal package structure

I am trying to import a maven project (import->existing maven project) into eclipse and it is showing up in eclipse using the generic java project structure as opposed to the maven one. I have tried several versions of the m2e connection and all have the same problem. So for example instead of the following folders/packages/files I have:
src/
main.java.my.package.name
myfile.java
test.java.my.package.name
testfile.java
etc.
instead of the maven project structure
src/main/java
my.package.name
myfile.java
etc.
Any assistance appreciated, thanks!
For the sake of completeness:
This happens sometimes due to a race condition in eclipse.
As you already found out: if it happens, it happens only once, on initial import. So your way was almost correct:
Remove all source paths
do not add them manually
instead, right-click on the project and select "Maven -> Update project" and accept the default settings. Now the source paths will be set correctly
Woops, right after posting I was able to get it to work.
I had to go to project -> build path -> Source and remove the src/ folder and add the src/main/java, src/main/resources, etc. folders and it all works now.
Thanks for looking y'all!

Eclipse Debugger: Source not found for project references

I am seeing a problem whereby the Eclipse Debugger cannot find the source for classes that are included as project references.
My application contains 2 types of referenced libraries: those in the Maven repository, and those that are included as part of a project reference to another project in my workspace.
The debugger has no issue showing source for any classes in the Maven repository.
However, when it tries to debug classes included using a project reference then it cannot find the source. Even when I click on the "Edit Source Lookup Path" and specify the location of the project it cannot find the source. I have confirmed that the class in question does exist in the project's output folder so I'm not sure what the problem is here.
Can someone please help?
Thanks
OK, I've resolved this almost as quick as I opened it.
The problem seems to have been caused by the way I was importing my application's project.
So in Eclipse, I imported this using m2e's File > Import > maven > Existing Maven Projects.
This resulted in dependencies that existed in my workspace being included as project references instead of actual jar file references to the Maven repository.
To get the actual jar file references to the Maven repository, I ran mvn eclipse:eclipse and my debugger was able to pick up the source code.
Is this a known problem with the m2e plugin?

Eclipse build path with other projects

I've got several projects in Eclipse (all are Maven projects) and one main project (also Maven project) which depends on the rest. I tried add this dependency by setting java build path (right click on project -> preferences -> java build path -> (tab) projects -> add). But there is a problem while executing maven install goal - this is compilation error: ... (class) ... "cannot be resolved" ... - this is definitely looks like maven does't see my resources from other projects. Eclipse is only warning me something like this: "Classpath entry /my-subproject1 will not be exported or published. Runtime ClassNotFoundExceptions may result." These warnings referenced to each subproject and occurs in main project. There is no error messages from Eclipse. In my main project, where I'm importing classes from subprojects, I can right-click on one of the import and choose "Open declaration" and there is valid reference to class from one of my subproject - so it looks like Eclipse sees my dependencies (there is no eclipse errors while building workspace - only these warnings mentioned above) from other projects, but maven doesn't see them while compilation.
Have you got any ideas how can I fix this?
Thanks for help.
You have to declare your dependencies in the pom.xml for Maven. Maven doesn't recognize any Eclipse specific configurations (like Build Path etc.): Maven Tutorial
If you use the m2eclipse plugin, it will configure your Eclipse build path according to your pom.xml configuration
Isn't this maven problem?
Maven needs jar file made from other project inside maven repository.
I don't know much about maven eclipse plugin but so far, in my observation, it seems like it works this way.
So that this case need to build other project so that create it's jar file.
But this takes so much time.

how to fix Eclipse losing reference to third party jar in project sets

Occasionally I see eclipse lose the reference to the third party jars contained in the a projects. (you get the the build path error stating the jar cannot be found)
Its easy enough to fix as you can remove the jar, save the properties of the project and then go in and re-add the jar that it could not find, eclipse can then see the path to the jar and you can then compile again.
the problem is that if you have a lot of projects in your build you would have to do this task a lot.
Is there anything you can do to force eclipse to recognise that it actually has the jar on its classpath?
I have also faced the similar situation many times with my projects in eclipse. The jar file path is correct in the .classpath file and the jar is present still eclipse do that. To fix it you open the .classpath file and resave it and refresh the probject in eclipse and it builds fine.
That's a weird behaviour...
If that's ok you can use Maven 2 for your projects. This means that you have to follow Maven's project structure, which is quite ok, but it can be a pain if you decide to migrate old projects.
Then you can run mvn eclipse:eclipse whenever you want and that will fix your problem in a few seconds.