eclipse project not importing the jar packages in local Maven repository - eclipse

I am facing a problem in setting my eclipse project.
The problem is whenever I am creating a new project and import the code.Eclipse is not resolving the packages which are present in the jar files which are present in the C;/..../user/.m2/repository.
Hence it's giving a lot of compilation errors until I add all the required jar files manually in the build-path by going to "Add External Jars"
I saw that M2_REPO is present in my Eclipse classpath.But still it is not resolving the packages.
Please suggest how this problem can be resolved.
Gaurav

I've been having a similar error in Eclipse on OSX. In Eclipse on the Mac, there is no "Maven" entry when you right-click on a project in the explorer.
However!
I just discovered that if I right click and then click "Validate", it suddenly magically resolves all the dependencies. No idea why, but maybe this will help.

I've had this issue on Eclipse Kepler EE which comes prebuilt with m2e, I finally got it working by doing the following on each project:
Right click on the Project
Select Properties
Select Maven
Uncheck the option that says: Resolve Dependencies from Workspace projects
It should pop up with a box that says Maven setting has changed. Do you want to update project configuration. Click Yes to this.
To confirm:
Right click on the project
Select Properties
Select Java Build Path
Check the Libraries tab under Maven dependencies that all the jar you
expected are now there.

close your project, and remove your project settings files: .project, .classpath, .settings/. Then re-import this project. It will be ok.

Though this answer is late. But it can help the future audience.
You can give it a try using Project(Right-Click) -> Maven -> Update Project. To select all or the number of projects you want to update.
This worked for me.

Have you put all needed dependencies in the pom.xml? Even if the Jars are already in your local repository, each project needs its dependencies mentioned in the pom.xml to resolve the dependencies. If you do that, m2eclipse will automatically resolve the build path.

Another possibility. Are you running Eclipse using JDK or JRE - the default is JRE. You will see a warning in Eclipse console, if so.
maven eclipse plugin will not work correctly unless run with JDK.

I just had a similar problem. The JDK was there, the problems view was set to Show All, and yet there were hundreds of unresolved type errors. Not even Refresh (F5) would work.
In the Project|Properties|Java Build Path|Libraries window I was seeing only the JRE System Library, but not the desired "Maven Dependencies" entry. And "Maven Dependencies" was also missing from the Package Explorer view as well.
I finally fixed this by right clicking on the project in the Package Explorer, selecting Maven from the menu, then selecting "Update Project Configuration." This added "Maven Dependencies" and all the errors went away.
This was nice because prior to this fix I had to treat Eclipse like a dumb editor and run mvn compile on the commandline to find errors.

Related

Maven Standard Directory Layout

I am trying to get the Maven standard directory layout on my Eclipse project with the expected
src/main/java
src/main/resources
src/test/java
src/test/resources
However, all I am seeing after building the project is the following:
Can someone give me some specific instructions as to what I need to do to fix this?
As I can deduce from your screen-shots
the Eclipse project is correctly configured to be a Maven project (it has the Maven nature - that can be seen by the M icon on the project folder icon)
the M2Eclipse plugin is correctly up-to-date
Now, the first error is that your POM is incorrect. You should remove the declaration <sourceDirectory>.
Then my guess is that you arrived at your current situation because, in Eclipse, you created a "Java Project" and then converted it to a "Maven Project" by right-clicking and selecting "Configure > Convert to Maven Project" (what makes me thinks that is your current source folder being src, which is the default after creating a "Java Project").
What you seem to be missing is a clean refresh of your project. You should right-click the project, go into "Maven > Update Project...", and click "OK". This should resolve your problem.
If this does not work for some reason, I suggest you remove your current project (from the workspace and the content on disk) and, instead of creating a "Java Project", create a "Maven Project", by going to "File > New... > Maven Project". The M2Eclipse plugin will kick in and this new project will be correctly configured.
Remove the <sourceDirectory> tags. You are using the defaults and these do not need to be declared.
Also, as the esteemed #Tunaki mentioned, use the M2Eclipse (m2e) plugin or right-click the project and select "Enable Dependency Management". If you are using Eclipse Luna or later, m2e is already included. If you don't do this, you'll be able to build just fine from the Command Prompt, but Eclipse will be confused.

maven integration in eclipse new project checked out but can't navigate

I am struggling with maven in Eclipse even though I have m2e.
I checked out a maven project from CVS and cannot navigate anywhere. If I try References > Project, I get a pop up saying:
"Problems opening an editor Reason: services does not exist".
services is the name of the main project, which has sub projects within it. It all builds successfully so I am not sure why Eclipse does not work.
I suspect something related to classpath but have no idea how to edit it since it is not available from the project's properties. I actually tried to manually create a .classpath file but it did not help.
I also converted the project to a maven project but that did not help either.
Any ideas? I am using Eclipse JUNO.
I figured out my issue. I had to check out the project from CVS. Then (that's the important part), perform a maven import of an existing project within eclipse. That created maven "ready" projects where I could use all of the IDE's functionality.
Yes, you're right. If you import directly from a repository, hovering, linking and opening declarations isn't gonna work. Your solution is right, although another one more direct is use the "File->New->Other->Maven->Checkout Maven Projects from SCM". If then, you have problems because you can't select any SCM type, check Checkout Maven project from SCM - no connectors. If with connectors installed you still have problems: http://forum.springsource.org/showthread.php?102665-SCM-types-not-available-in-Checkout-Maven-Projects-from-SCM.
If you have checked out project from svn, project checked out is not generally a eclipse project thats why general functionality of eclipse does not work for the same.
To achieve the same functionality of eclipse like eclipse reader and all other shortcuts,we have to convert the checked out project to eclipse project.
Steps to Convert checked out project to eclipse project:
Right Click on Checked-out Project.
Point to Configure.
Click on Convert to Maven Project.(if checked out project is maven project)
These steps will convert the project to Maven project.
All the eclipse functionality will work for the same.
In addition to ensuring that the projects are configured as Maven projects, you may also go to Project Properties (right-click on the project in Package explorer) > Project References, and add projects in the workspace that the selected project may have references to.
I had this problem, too.
It looks like after a search-in-workspace Eclipse opened a wrong file.
I pressed Strl+Shift+H (Open Type in Hierarchy), typed in the class name, and opened it. The file opened in a new tab, and everything was navigable again.
The difference in icons is:

file not found manifest.mf eclipse

I'm using the following configuration :
Eclipse Indigo
Maven 2
ClearCase (like SVN and CVS)
and every time I want to run an application within eclipse a popup appears telling me that a Problem has occured : File not found : ...\target\classes\META-INF\MANIFEST.MF.
Go to the root of the project. Wherever the pom is located then try to do a
mvn eclipse:clean
Then refresh your projects and see where that leaves you
Right click on project then click on maven then do update project.It work for me.
I had the similar issue. What I did is:
Right click on project > Maven > Disable Maven Nature
Right click on project > configure> Convert to maven project
Error gone
If you're also using Maven and sometimes compiling outside of Eclipse, it could be removing Eclipse's manifest, and Eclipse won't recognize the manifest that external Maven creates.
TL;DR Uncheck "Maven Archiver generates files under the build
directory" in Window > Preferences > Maven > WTP.
Read more in #cosjav's answer on another question.
Right click on project -> Maven -> Update
DEBUG or RUN the server in order to fetch the recently created war file.
Make sure to check "Force update snapshots/releases" while doing MAVEN UPDATE
clean all (involved) projects and refresh your open projects in your workspace
I know this question has already been answered. After several tries, what worked for me was expanded my project in eclipse, right clicked on target directory and clicked refresh and that has been working ever since. Hope this works for someone if all the above fails.
All. For me, there was an error in pom.xml. I formatted the code (Ctrl+Shift+F) and the error is gone. After that I was able to run the application.
Close the eclipse and start the eclipse again. This will refresh the projects and problem will be solved.
I had the same problem but it got resolved just
disturb the formatting of
POM.xml
and press
ctrl+a and ctrl+shift+f then save the document
Right click on project then select maven and then click on Update project after select the project name and update it'll be work fine.
This issue appeared to me while I updated eclipse [updated to Eclipse 2020-12 (4.18)] as my project was open in eclipse. Then I closed my CLI (as I was running mvn test command), closed the project in eclipse and restarted my eclipse.
Thereafter the issue was gone. Hopefully this will resolve your issue too.

How to have Eclipse recognize dependencies from SBT

I am trying to figure out how to make Eclipse recognize dependencies that are retrieved using SBT? SBT download the correct dependencies and puts them in my ~/.ivy directory but eclipse doesn't see them. Is there a way to do this?
thanks
If you are using sbteclipse plugin it's achievable in a simple way. In sbt type:
reload
eclipse with-source=true
Then in eclipse, hit F5 on a project folder to refresh it. Or right-click and choose "Refresh". Just works.
This is probably not the answer you are looking for and I admit it is not elegant but it currently works for me, meaning that I think it takes less time for me to periodically do the following instead of researching and finding a more elegant solution.
I assume you are using the sbt-eclipse plugin ( https://github.com/typesafehub/sbteclipse ). When I add new dependencies to my project ( which is actually pretty rare ) I simply regenerate my eclipse project files from the plugin. The downside of this is that I have a multiple module project and after I refresh the projects in eclipse I need to re-add the inter-project dependencies in the eclipse build path editor.
Like I mentioned it is pretty hacky but all in all I really don't loose that much time doing it. It's not pretty but it works.
Best of luck,
Andy
I use the Apache IvyDE plugin for Eclipse, and I've had more luck with this approach. It's only described in the old sbt docs, but works with sbt 0.11
First, install the IvyDE plugin in Eclipse and restart.
Run the sbt command deliver-local - this will create an XML ivy file of your dependencies.
In Eclipse, under your Project/Properties - Java Build Path - Libraries, click "Add Library" and choose "IvyDE Managed Dependencies" then select the file target/scala-2.9.1/ivy-projectversion.xml
When you add a new dependency to build.sbt, run the sbt commands reload and deliver-local again. Then right-click the Ivy library for your project in the Package Explorer - it will be called "target/scala-2.9.1/ivy-projectversion.xml [compile,test]", and click the second "Refresh" menu item (between "Refresh" and "Reload Settings" - not "F5 Refresh" ).
In command prompt go to the project folder and type
sbt eclipse
This should generate the appropriate .classpath entries in eclipse project.
Go back to eclipse, select the project and press f5, this will reload the referenced libs.
All you need is execute from your project home:
sbt "eclipse with-source=true"
or enter sbt console and write:
eclipse with-source=true
BTW: I don't know if from Jan '12 something has changed but now it seems much more simple.
The following works for me:
1) close project in Eclipse
2) in my file explorer, browse to my Eclipse project, make sure hidden files are visible
3) open .classpath in a simple text editor
4) copy the bottom entry. For example, in my current project, it is <classpathentry path="/home/natalie/.ivy2/cache/org.scalatest/scalatest_2.9.1/jars/scalatest_2.9.1-1.8.jar" kind="lib"></classpathentry>
5) navigate to my .ivy folder, cache, then down to the library I have added via sbt
6) right click on jar file, select properties, copy the path and jar file name and replace it in the entry I copied in step 4
7) save .classpath
8) open my project on Eclipse
New dependency is now available in Eclipse.

How can I add my application to Tomcat in Eclipse?

I have a web app built with Maven.
Most of the time, I built the application using Intellij IDEA, but now I want to import the application in Eclipse to see something in this IDE.
After mvn eclipse:eclipse, I add in Eclipse the app, but when I try to add the app to the server (tomcat), I receive:
There are no resources that can be added or removed from the server
Solutions?
You need the project to have a Eclipse Dynamic Web Module facet. You can try doing this via the project properties dialog and looking at project facets, then clicking the appropriate check box. This may not be available however, so you may need to do the next thing.
Create a backup of your project and follow the directions at dzone.com. This'll allow you to modify the project facets via your eclipse .project file.
Keep in mind, once you add those facets, you cannot change them back via Eclipse. Definitely make sure you have a backup before starting.
This step worked for me:
Right-Click on the Project Name, then
Maven-->Update Project..
Click OK
After doing this I was able to see my project in Add/Remove Programs.
As mentioned somewhere else adding Eclipse WTP didn't do any good, however I performed the above step after I had already added Eclipse WTP, so I am guessing that may not be needed.
This was done for Eclipse Juno.
Hope this helps someone.
Edited: You can follow this link as above mentioned I think might have needed WTP and that add a lot of other things into the workspace.
http://blog.teamextension.com/maven-as-eclipse-dynamic-web-module-556
Check whether Maven Integration for Eclipse WTP is installed. If not, install it from Eclipse Marketplace
After installation restart Eclipse
Right click your project and Maven--> update project configuration
Delete tomcat and re create tomcat (clean tomcat,add your project,publish and enjoy)
I've got Tomcat 6, Java 1.6, and was trying to get it to work in Eclipse Juno Service Release 1's "internal server" (whatever that's called.) Here's what I did that worked for me:
(Found these instructions at http://www.mkyong.com/eclipse/eclipse-ide-tomcat-version-6-0-only-supports-j2ee-1-2-1-3-1-4-and-java-ee-5-web-modules/)
I should point out that I followed ClutchDude's instructions to make my project a Dynamic Web Module facet. It didn't work on its own for me, but maybe it was part of making it work in the end.
Using Eclipse (or other text editor), open the file
.settings/org.eclipse.wst.common.project.facet.core.xml
Find the line that reads
<installed facet="jst.web" version="3.0"/>
3.0 is for Tomcat 7.x (so says mkyong.) Change it to 2.5 (or 2.4).
I restarted Eclipse and it worked for my project.
The reason why this is happening is because eclipse by default looks for the deployment descriptor in the folder {project.home}/Webcontent/WEB-INF/web.xml where as the Maven puts them in src/main/webapp/WEB-INF/web.xml.
So when you are trying to add your project onto the server eclipse cannot find a deployment descriptor and hence you get the annoying message.
This can be solved by adding the following entries in .settings/org.eclipse.wst.common which can be found in
Project home folder in your workspace if it is a new maven project.
The folder where you already imported from if you are using Import -> Maven projects.
Make the following changes in to the org.eclipse.wst.common
wb-resource deploy-path="/" source-path="/src/main/webapp"/. Add this entry.
Edit --> property name="java-output-path"
Please check the following link from more details. http://java.dzone.com/articles/webapps-eclipse-and-maven.
The comments section has an excellent example with a working project.
This issue was fixed for me my installing additional eclipse modules. in particular, the ones related to m2e-wtp. just do a search for m2e in the plugins search listing for your version of eclipse
If you face an error like "There are no resources that can be added or removed from the server",
then
1) Go to the META_INF of your websvcsEAR and go to the application.xml.
2) Goto modules-> clickDetails and add the module that is existing. i.e., some EAR which your project demands.
3) Click ok
4) Now go to your server -> right click -> add and remove -> add your EAR.
Maybe you don't need add your application to the server's configuration. I think that you must use m2e eclipse plugin in order to launch the app.
For example, in your eclipse you will see a contextual menu called "Run as" if you right-click on your pom file. You can clicking on "Maven build" and Maven will download all the information needed to start tomcat.
I hope this helps you.
I used
mvn eclipse:eclipse -Dwtpversion=2.0
in command line in the folder where I had my pom.xml. Then I refreshed the project in eclipse IDE. After that I was able to add my project.
I was able to resolve this by removing my EAR project from my Eclipse workspace, then re-importing it.
Well, with a Spring and maven project, i got it that way:
Eclipse Version: 2019-06 (4.12.0)
Java 1.8
Tomcat 7
Yes, go to Project Properties >> Facets >> select Dynamic Web Module but dont apply yet!!!
Right under, it should appear a link Further Configuration Available. Click on it, otherwise one will have to edit .settings/org.eclipse.wst.common.component manually. Update source directory to src/main/java. (source)
Then in Facets window check Java - mine was pointing to 11 even though i don't have Java 11 installed or configured like a JRE runtime. I could only add/remove when changed to 1.8. (source). Note: That was really the problem, why don't Eclipse get this configuration automatically from the project?
Finally Eclipse creates some directories like WEB-INF and META-INF, just delete them.