Came in the morning fired up eclipse and noticed that eclipse is showing my dependency jars outside the maven dependencies folder. This is a long running workspace and nothing has changed that I am aware of that should cause this behavior.
What's more odd is that the Maven Dependencies folder also has the jars in it as well.
I have tried:
mvn eclipse:clean and mvn eclipse:eclipse which did not work as expected because after this only the parent projects showed as maven folders.
Removed the old workspace and recreated which results in the exact same issue.
Verified maven settings and my poms are good. Which should be.
It looks like some generated files got hosed up. Still not sure what caused the issue...
My solution was to close eclipse, delete the workspace and in the SVN repo made sure all my work was committed.
Right Clicked > Svn option > Revert on an empty screen.
In the gui there was a delete un-revisioned files check box.
This was essentially to get rid of all the maven/eclipse generated files but the target folders go too.
Re-created the workspace imported my maven projects and all cleared up.
The only way I have experimented this situation in which the libraries are shown directly within the project's contents is by meeting these two conditions:
The libraries are specifically set into the libraries tab of the Java Build Project window.
The Libraries from external option is unchecked (from the Customize view option in the project's view menu).
Sounds to me as if your .classpath file has been modified. I always recommend to check it in into the source control system (along with the .project and the rest of metadata files of the Eclipse project), taking care just not to include absolute paths.
Related
I've forked a Github project, used Eclipse to clone it locally, and imported that as a general project into Eclipse.
The accompanying .project file is an Eclipse .project file with the proper "nature" and "buildCommand" xml tags.
So it seems like a valid Eclipse project. However, I'm unable to specify a run configuration or configure the build path.
When I select the Build Path popup menu item, it says "no actions available" in grayed out text. When I select "Run/Run As" from the main menu,
it shows (none applicable). I'm wondering if the problem is that the project imported completely as source folders:
There are no packages to speak of. I created another project from scratch, and created the proper source folders and packages as needed
to match the package statements in the source code. After manually importing the source from the git repo, I can build and run that project.
If the lack of packages is indeed the problem, is there a quick way in Eclipse to convert source folders to packages?
What you did is you have probably cloned the repo in Eclipse and then Imported this project through a New Project Wizard, because in GitHub there is no existing .project (and no .classpath) files.
The "New Project Wizard" will create a set of defaults for a java project (I suspect that you selected just that), but is anaware of Maven structure, so all source folders will not be recognized and you will end up having to define them on your own. Worse, you will be unaware of any special parts of the Maven build that might be configured within pom.xml.
Because this project uses Maven for building, it would be better to use M2Eclipse while importing it. Install it using Help->Install new software.
Then there are a couple of steps required to make it use all Eclipse features.
Keep your cloned copy of the repository or clone again if you want to start from scratch. Then use File->Import feature to import a maven project into the workspace. Select Exisiting Maven Projects and point to the directory containing pom.xml file in the cloned repo. This will use Maven integration in Eclipse to generate .project and .classpath files based on pom.xml contents, so you will be able to more closely mimic Maven build in Eclipse. All source folders should be properly discovered this way. Eclipse might want to install some additional integrations for Maven features that this particular project uses. Let it, if that is the case.
Now, you will have the project operational and compiling in Eclipse, but it will not be aware that it is managed by Git... This is because M2Eclipse and Git Team provider are not integrated (at least they weren't when I last checked). In order to be able to commit to the repository in Eclipse, remove the project from workspace, but without deleting contents. Then, import from Repository view using Import Projects/Import exsisting Eclipse projects. Since necessary .project file is already generated, Eclipse will autodiscover the project and will use the right configuration prepared earlier by M2Eclipse.
In the end you will have a properly configured Maven project with Git as a team provider for it.
If this is a project meant to be built by Maven that contains a pom.xml file, install M2E before importing the project from your local cloned repository. It will handle this.
Right click at root of project select properties, in the sources tab add the folder "src/main/java" as source folder
Other way is to configure facet as java
I have imported a java project into a new eclipse workspace and it gave me a lot of errors:
It says "Project 'myProject' is missing required library: /User/linus/.m2/..." (The directory is longer but not of interest for you)
Now, I have looked inside my Finder to see what is in ".m2" but there is no such directory where it should be. Additionally I let it show all the hidden files but no success. Lastly I tried to get into the folder with the terminal (using cd and then the directory eclipse gave me) but that did not work either.
I saw this post but it did not help me.
I reinstalled Maven to make sure it can be used, this is the output if I type mvn --version and mvn in the terminal:
Does anyone have an idea?
Thanks in advance
EDIT:
I reinstalled Maven and now there is a /.m2 folder. It contains /.m2/repository/ but there is nothing in it...
May I suggest you read a Maven tutorial like http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
IMHO it's a wonderful build tool because it gets required jar files per the specification in the project object model ("pom") file which your Maven-ized project should have, and you don't have to keep track of jars on your own.
Look in your project for pom.xml, you might even post it here.
To check the sanity of the project and maven on your computer (ignoring Eclipse for a moment), be sure you have a good Internet connection, open a Terminal window, change directory ("cd") over to the project directory, and type "mvn install".
This should trigger the usual Maven build cycle. One of the first things it should do is download all the jars as identified in the pom.xml and store them deeply nested within your /Users/linus/.m2/ directory. Then it should compile all your java classes. Eventually it will probably build a jar file and copy it to somewhere.
If all this works, visit http://eclipse.org/m2e/ for directions to add the Maven plugin (m2e) to your Eclipse. Then your Eclipse should understand how to download jars and build the project per the pom.xml file.
Eventually this all should fix the original "Project is missing required library" problem.
I am getting a class not found exception for my Login Controller when I try to login to my application(It is a spring MVC Application). Before running the maven clean command the Application was running perfectly, I used maven clean and then again done a build using maven package command, suddenly it stopped working. I tried restarting the TomCat, re-deployed the application on TomCat, restarted the Eclipse IDE but nothing has worked so far.
Why this happens and what is the possible solution to this ??
Are you trying to run your project under Eclipse?
And does it generate source files?
If these are both true, you probably need to update the project config (select project or pom, right-click, Maven..Update..Project Configuration and Maven..Update..Project Dependencies).
The problem is that when Maven does a clean, it gets rid of the generated directories, which Eclipse observes and removes from your Build Path. But then when Maven rebuilds the directories, Eclipse doesn't notice it - you have to give it a hint.
Check your project for build errors and build path errors.
Make sure you've defined an M2_REPO classpath variable in Eclipse (Preferences - Java - Build Path - Classpath Variables).
If you're using the m2eclipe plugin, right-click your project and click on Maven - Update project configuration. That will configure an Eclipse build path for your project based on your pom dependencies.
If you're not using m2eclipse, execute mvn eclipse:clean eclipse:eclipse in your project folder. Then refresh your project in Eclipse.
What you haven't said is that you've checked and the missing class is in fact present.
A quick way to check is in the code editor SHIFT+CTRL+T and type the name of the missing class. Eclipse should not only show you the class if it exists, on highlighting the class, Eclipse should tell you which jar it is in.
Based on the info you have provided, I would say some dependecy in your POM has been removed by mistake or you need a newer version of some jar. If you find the class is not present, then you can figure out which jar you need by googling something like Maven 2 MyMissingClass jar that usually works for me.
Delete the .metadata folder in your eclipse workspace and then again open the workspace and import the required project.
This will solve your problem.
In .metadata folder it maintains the temporary copy of the project.
what worked in my case was simply removing the project from work space and importing it back again.
But I still don't know why it worked Vs why other things mentioned did not work (I tried updating dependencies in fact I removed all the dependencies from pom.xml and added everything again)
I want to checkin a Dynamic Web Project I created in eclipse into svn. Can someone tell me which files I have to check in and which one I should not? The idea is to be able to check out the project using the New Project Wizard so that I can create the Dynamic Web Project again. More specifically here are the files/directories I have in the project --
src
WebContent
build
dist
build.xml
.project
.classpath
.settings/
The build directory is not supposed to checked in obviously. What about the other ones?
I am guessing all the . files should not be checked in either. Can some one verify this?
What is this dist directory and the .settings directory?
Also where does eclipse store the Server information (tomcat)? I don't want to check it in either.
EDIT:
I initially checked in all of the above except the build directory of course. When I checked out the project from inside Eclipse it did not prompt me to create a new project since the .project is there but Eclipse was creating a JavaEE project or something instead of the Dynamic Web Project. Did anyone else run into this behavior?
** EDIT 2 **
Found it! Turns out I should not check in the following --
.project
.settings/
.classpath
Once these 3 are removed the New project Wizard works as expected and everything is fine.
If you check in .classpath/.project/.settings you make your project Eclipse-specific. What about developers who work with Netbeans or IntelliJ? IMO it is cleaner to keep your project IDE-independent and easy to set up.
I usually go for a Maven build. The pom.xml specifies all the required dependencies and mvn eclipse:eclipse generates the .classpath/.project files for you.
The .settings directory contains local settings (like which Java version you want to use). IMO it is not useful to check this in. You can enforce Java version compliance via the Maven2 pom.
Finally, for your next project, my protip is to svn-ignore the files or directories you don't want in SVN before your first commit. In a Maven2 setup that would be .settings .classpath .project target (the default output directory of Maven2) and any other generated stuff (log files, gfembed directories, etc). In your case you would ignore build and dist instead of target.
You can svn-ignore files or directories with RIGHT_MOUSE->Team->'Add to svn:ignore' (I use the Subclipse plugin). Ignore instructions are stored as svn-properties on the parent directory. The properties on a directory can be viewed by RIGHT_MOUSE->Team->Show properties. You can also edit the properties directly there by clicking on the value field. Make sure there is an end of line after each property.
Now that you have already committed and then removed these files, ignoring is not going to work anymore in my experience. Somehow I have never managed to successfully ignore generated files which have ever been checked into the SVN repository; they are like zombies, always coming back from the dead. Maybe by deleting their entries physically in the SVN repo this can be achieved, but I've never done it.
In our case, we have checked in all you mentioned in the list except, .settings/.
With .classpath and .project checked in, users can quickly check out the project and fire up Eclipse on a new computer and just start working on it; the alternative being to configure the project manually and adding in all the jar dependencies painstakingly (if you use ant). Many open source projects do this.
Read this, there are some really good points to ponder about.
Good Question... Many of us are in a dilemma on whether we want to check in IDE related files or not. I normally go for checking in .classpath for eclipse and I use eclipse variables to make sure that team needs to just change the variable value and it works. We also check in .project so that team need not to create new project in their workspace.
I would omit the .project, .settings/, dist, and build.
The .classpath can be left in if you use variables instead of hardcoded paths. This is useful so you don't have to rebuild your classpath every time you check out the project.
I have checked out a bunch of java code using subversion 1.6 and then I imported those projects into eclipse. Subclipse 1.6 picked up the fact that the plugins are under version control, except for a few folders.
I now get a bunch of errors like:
The resource is a duplicate of
src/.svn/all-wcprops and was not
copied to the output folder
If I delete the project (from eclipse not on disk) and reimport it, that fixes the problem about half the time. But since I have dozens of projects that are having this problem, it means reimporting them 10-20 times before I get them all working. This is very painful, and I am tired of doing it every time someone adds a new plugin to svn or when I need to recreate a workspace for some reason.
Is there an easier way to fix this than delete and reimport? Or is there a way to prevent this problem in the first place?
Add the .svn folder to the Excluded list for your Source Folder.
Project->Properties
Java Build Path
Source tab
Select 'Excluded'
click
Click next to the Exclusion patterns section on the bottom
Add the .svn folder and any others that do not need to be copied to the output directory
Follow the procedure described by Kelly but define the exclusion pattern as **/.svn/*. This will recursively exclude all .svn directories from the various source folders.
This is happening because you checked out a project using an SVN client other than Eclipse and then imported the project in Eclipse and you haven't notified Eclipse that this is an SVN project (that is, Eclipse doesn't know it has to ignore the SVN meta information).
In order to fix this properly, after you have imported the project in Eclipse, have Eclipse be 'aware' of the SVN nature of the project. Do so by
Select the project and go to the Team > Share section.
A dialog will appear asking weather this is a CVS or SVN project. Select the later.
It will prompt for the credentials, enter them.
When you're done, do a clean build. The problem goes away.
Easier way to do this is:
Project > Properties
Resource > Resource Filters > Add...
Filter type > Exclude all
Applies to > Folders
Check All children (recursive)
File and Folder Attributes > Type ".svn"
Hit OK and OK again
Clean/build
------------ Simple way of filtering the output folder-------------
Window->Preferences->Java->Compiler->Building
Make sure "Filtered Resources" includes ".svn/"
The "accepted best answer" described the cause to me, but as my project was already shared, I 1. closed the project, 2. opend it again and 3. cleaned it. The .svn folder is gone and does not come back.