installing packages locally for a new project in Java - java

I have downloaded a simple project from a Git repository and opened it in Intellij. A couple of the import statements are highlighted in red, stating "Cannot resolve symbol." The packages that cannot be resolved are: zaxxer, springframework.
Normally in Perl or Python I would fire up a dependency manager like CPAN and simply install them, but my understanding is that there isn't really any such thing in Java and that dependencies are resolved sort of on a project-by-project basis.
I have Maven 3 installed, and my project has a pom.xml file, for what it's worth. What should I do now?

If you have opened the project in IntelliJ you can right click the module and choose "Add framework support". Choose Maven there, if it isn't there then it is already enabled.
Then, simply open your pom file. When indexed there should appear an dialog in the lower right corner asking you if you want to auto import changes or just import them manually. Click on one of them and the dependencies will be added.
If you can't see this notification it may have already been shown, then simply press on the "Event log" in the bottom right corner and the notification should be displayed (with eventual other info).
Edit from OP: Solution was: 1) Turn on the view in View > Tool Windows > Maven Projects. There was no Maven project here, so I added it (selected the pom.xml). 2) As described in an answer at Failed to Read Artifact Descriptor: IntelliJ "In Intellij, go to File -> Settings -> Build, Execution, Deployments -> Maven Check the box, ‘Always update snapshots’
It's a little weird that "always update snapshots" isn't turned on by default for IntelliJ, but this got things working.

Related

Project name not appearing in debugging Eclipse

I have cloned a Bitbucket project in my Eclipse IDE and I want to debug the project as a remote application.
However, in the debug window (->connect window), the project name is not shown.
Why do I not see it?
I am Attaching Screenshots where you create Debug Configurations for any Remote Java application.
Lets Go step by step:
Within Debug Configuration Window
You right click Remote Java Application > New
In the Connect Tab you browse the project in your Workspace (One you want to debug), Here in my case it is MyApplication
In Source tab You Find below details where you add any dependent projects with the project that you want to debug
When you say Add here, small dialog box comes up and here you can again choose Java Project, that would be one from your workspace.
I think doing this you would find your Project for Remote Debugging.
Hope this helps..!
I didn't see your problems related screenshots, but according to the situation you described, you can try the following method:
On the debugging of threads Right click it
--select Edit Source Lookup Path
--Select Add
--Select the Java Project
--choose the Java Project you worked with then click OK.
The other situation I think about is whether or not you don't have the jar that you're relying on for the project you downloaded
I had same problem. I had imported project as import project from file system. so it was not java or maven project for eclipse i guess.
i just did import as git project and tried again and it worked.

POM.XML add dependency search not Working?

I am using Eclipse Mars 4.5.2 which by default contains Maven.
I created a new Maven project and when I try to add dependencies through pom.xml, by clicking on the dependency tab and adding it. After I entered "spring framework" in search bar, it is not showing any result (in windows 10).
How to fix this issue?
Just manually edit the pom.xml after creation of the project and e.g. search Spring on MavenCentral (e.g. here: http://search.maven.org/#search%7Cga%7C1%7CSpring).
Maybe not ideal on the long run but that should allow you to continue working on your project most quickly.
For some reason, Eclipse did not fetch the index from MavenCentral. Go to the "Maven repositories" view and click on "central" in "Global Repositories". You probably do not see elements in it. Make a right click and check whether the index is enabled. If it is, try "update". An update of central may take 30 minutes or more.
If none of this works (which is quite possible), throw away your local repository (in the .m2 folder in your home directory) and retry everything. Local repositories are sometimes broken.
In eclipse go to Window -> Preferences -> Maven
Then go to Window > Show View > Other > Maven > Maven Repositories
Click on "Full Index Enabled" and then click on "Rebuild index" as shown below

Showing Annotations in Eclipse Mars for Java is Impossible

I am currently trying to get the git annotations in eclipse mars for a Java file, to see when a line was changed. In Luna, this worked (and still works) with Team -> Show annotations. In Mars, this does not work for me. (Also after reinstall and on a different computer). For other files, for example the pom.xml of the maven project, this works. The project is, besides, this problem, working and compiling fine in eclipse and was created based on the pom.xml in eclipse. Also when the project is created via mvn eclipse:eclipse, show annotations is not working.
I've read the settings with Ignore whitespace changes and Preferences > General > Editors > Text Editors > Annotations > Errors > Show in > Vertical ruler (Show annotations not working), which are correct. Also closing and reopening the Java perspective did not work (https://www.eclipse.org/forums/index.php/t/1011988/). I could not find any other recent threads about this.
Is there some configuration for Java that I am missing, or is this an eclipse bug?
Right click on the file . Team -> "Show Revision Information" - in
Eclipse Neon.
Right click on file -> Team -> Show Annotations. - In previous eclipse versions
I had the same problem. Did you check if your Git repository is imported correctly? For some reason mine wasn't.
Check the Git repositories view (Window > Show view > Other > Git > Git Repositories). If you cannot see the repo there, add it and afterwards you should be able to choose "see annotations" under team.
A little bit old, but maybe to close this question.
You will have to "share" your projects.
Right click the project/projects -> Team -> Share Project.
I did select all relevant projects first and then right-clicked to share the projects. Sometimes this does not work, if a project is in the selection list, that has different porperties.
This will connect your project with your git repo.
Good luck.

The project cannot be built until build path errors are resolved [duplicate]

While compiling an android project in eclipse 3.4.2, I am getting The project cannot be built until the build path errors are resolved.
I got a temporary solution from the blog http://www.scottdstrader.com/blog/ether_archives/000921.html
The resolution was to force a resave of the selected projects (and their .classpath files):
Open the project properties
Select Java Build Path > Libraries
Add a new, arbitrary library (to be deleted later) > OK
Wait for the workspace to refresh (or force a refresh of the project)
The error(s) will go away
Remove the dummy library
The only other references I could find were to make minor alterations of contents of the .classpath file.
Is there any permanent fix for this issue?
Have you tried using Project > Clean... from the menu? This will force a new build on the selected projects in Eclipse.
1-Right CLick on your project folder, Choose Build Path > Configure Build Path
2-Select Libraries Tab and delete any arbitrary library present there.
3-Click on Add Library option, Select JRE System Library and click Next.
4-Choose last Radiobutton option Workspace default JRE and click Finish.
5-press f5 for refresh.
6-run ur program .
This what fixed it for me...
I was having an issue with my spring-core.jar.
I deleted the entire release directory located here. (I'm on win 10).
C:\Users********.m2\repository\org\springframework\spring-core\4.3.1.RELEASE
I right clicked on the project > Maven > Update project and my exclamation mark disappeared. No problems any more.
Here is the source where I found the information:
http://crunchify.com/cannot-be-read-or-is-not-a-valid-zip-file-how-to-fix-maven-build-path-error-with-corrupted-jar-file/
This happens when libraries added to the project doesn't have the correct path.
Right click on your project (from package explorer)
Got build path -> configure build path
Select the libraries tab
Fix the path error (give the correct path) by editing jars or classes at fault
This works for me: close the project then re-open it, this will force eclipse to reload a fresh project and detects the correct build path.
None of the other answers worked for me. Even after fixing my build path issues, doing a refresh, clean, rebuild, and restart (of both eclipse and the computer), I was still getting the little red exclamation point.
I fixed it by closing the project (right-click, close project) and reopening it (double-click the closed project), which seemed to force eclipse to "notice" that the build path problems had been corrected.
For my mac osx Eclipse, I followed following steps:
Right CLick on your project, Choose Build Path > Configure Build Path
Select Libraries Tab and delete any arbitrary library or anything else causing errors in Build Path.
Click on Add Library button, Select JRE System Library and click Next.
Choose last Radiobutton option Workspace default JRE and click Finish.
Clean and build your project.
get a cmd and run
mvn eclipse:eclipse
This is what worked for me:
Go to ~/.m2/repository and deleted everything there by running rm
-rf. Make sure everything is deleted.
Re-launch eclipse or STS
Right click on project -> Maven -> update project.
On my Mac this is what worked for me
Project > Clean (errors and warnings will remain or increase after this)
Close Eclipse
Reopen Eclipse (errors show momentarily and then disappear, warnings remain)
You are good to go and can now run your project
I've seen this problem a few times (got it again right now on my home computer with Eclipse 4.2).
Forcing a resave (by changing the classpath e.g. by adding a library, save, change-back) works temporarily. But the problem comes back when Eclipse is restarted :(
Nuking the Eclipse workspace from orbit will permanently fix it (until next time). But there must be a better way!
just check if any unnecessary Jars are added in your library or not. if yes, then simply remove that jars from your library and clean your project once. Its worked for me.
In Eclipse this worked for me: right click project. -> Properties -> Library Section; Add (any library at all) -> select library and click remove -> press okay.
I ran into this annoying issue with the Play framework. It would be nice if there was some way of knowing what build errors Eclipse is unhappy about, but it's not going to tell you. With one project, I was able to close the project, rebuild the Eclipse configuration with sbt eclipse, and reopen. With an almost identical project, that didn't work. But deleting the project, rebuilding the Eclipse configuration with sbt eclipse, and importing, did the trick.
If you think you've done everything correctly but Eclipse still complains about the jars, refresh the folder where the jars are and make sure eclipse knows they've been added to the project. Specifying the file path alone is (apparently) not enough
I've faced this issue a couple of times and following the below steps has resolved both the times.
1. Navigate to C:\Users\
2. locate the ".m2" folder and delete it.
Now navigate to the particular project in eclipse and Right-click on the project > Maven > Update Project
wait until the project is updated and in my case following the above steps resolved both the times.
I was getting an additional warning
The compiler compliance specified is 1.6 but a JRE 1.8 is used
Resolving this warning make the error also go away. The steps are as follows:
I right-clicked on it, then clicked on Quick Fix. From the dialog that opened I selected Open the Compiler Compliance property page, and clicked the Finish button.
(This is same as Java Compiler section.)
In this dialog I found the Compiler compliance level drop down and changed 1.6 to 1.8, and clicked on Apply and close.
I got a message box Compiler Settings Changed which asked if I wanted to Build the project now?. I clicked on Yes.
The build path error went away.
Go to > Right CLick on your project folder > Build Path > Configure Build Path > Libraries Tab > remove project and external dependencies > apply & close
Now, Gradle refresh your project.
Added below to pom.xml file and it worked eventually:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
Goto to Project=>Build Automatically . Make sure it is ticked

Error in Eclipse: "The project cannot be built until build path errors are resolved"

I am a computer science student learning Java, so I do some work at home and at college on a mixture of Linux and Windows. I have a problem after copying a new project into the Eclipse workspace. The project shows up, but with a red exclamation mark and an error saying:
The project cannot be built until build path errors are resolved
How can I fix this? I tried the solution described here, but it didn't work.
Identify "project navigator" or "package explorer" view.
Right click on your project, select Build Path --> Configure build Path.
In the emerging window, you will find four tabs, select "Libraries".There, under "Web app libraries" (expand it), you will see the libraries added to the project's classpath. Check if all of them are available. If one or more are not (they'll have "missing" beside their name and a red mark on their icon), check if you need them (perhaps you don't); if you don't need them, remove it, if you need them, exit this window, look out for the missing jar and IMPORT it into your project.
Open the Problems view. You can open this view by clicking on the small + sign at the left hand bottom corner of eclipse. It's a very tiny plus with a rectangle around it. Click on it and select problems.
The problem view will show you the problems that need to be resolved.
If the message says "the project is missing the required libraries...", you need to configure your build path by right clicking on your project, selecting properties, then build path. Add the required jar files using the libraries tab.
-If there are other problems other than missing libraries, you need to post the exact problems here to get a precise solution.
If you can't find the build path error, sometimes menu Project → Clean... works like a charm.
In my case, all libraries in the build path were OK.
To solve it, I deleted all project metadata (.project, .classpath, .settings) and re-imported the project as a Maven project.
Right click your Project > Properties > Java Build Path > Libraries
Remove the file with red "X" (something like JRE...)
Add Library
That's how I solved my problem.
I also had this problem in my system, but after looking inside the project I saw the XML structure of the .classpath file in the project path was incorrect. After amending that file the problem was solved.
If not working in any case...then delete your project from the Eclipse workspace and again import as a Maven project if that is a Maven project. Else import as an existing project.
I tried all the previous given solutions, but they didn't work, but it works for me.
In Eclipse, go to Build Path, click "Add Library", select JRE System Library, click "Next", select option "Workspace default JRE(i)", and click "Finish".
This worked for me.
Go to Project > Properties > Java Compiler > Building
Look under Build Path Problems
Un-check "Abort build when build path error occurs"
It won't solve all your errors but at least it will let you run your program :)

Categories

Resources