I execute the command: mvn eclipse:eclipse to add the required librairies included in my pom file. The problem is that any source folder are deleted after executing that command.
There is any way to add the libraries without deleting the source folders?
I'm not sure what you are doing exactly but the eclipse plugin handles only eclipse configuration and does not touch any source folders. If the source folders are removed from your eclipse project, then the project/pom file is not set up correctly.
Since Juno, eclipse contains the m2e maven integration plugin. I suggest you create your first projects using that. It will take care of handling the build process and project setup for you.
Use the New->Project...->Maven Project menu and create the project using the wizard. When it is complete, copy all your existing sources into the new one and manipulate the pom file with the pom editor (eclipse will open the pom file with this editor by default.)
Important note: If you start using m2e, then don't use the command line eclipse:eclipse target any more as all the house keeping is done by m2e from that time on. If something is really messes up in your eclipse project, then you may delete the project from the workspace (don't tick the delete from disk option), run eclipse:clean (to make sure everything is cleaned up) and import your project with the m2e importer (File->Import...->Existing Maven Projects...)
As allprog wrote: your source folders are probably not deleted. (but probably removed from your .classpath file)
Maven use a standard configuration for all project. Usually there are 2 source folder (for *.java):
/src/main/java for your production code
/src/test/java for your test code
It's a good practice to follow this recommandations, but you can choose another location for your production/test code by adding this in your pom.xml:
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
...
</build>
Using multiple source folder for your production code and/or for your test code is not recommended.
Related
I have a fundamental question, but something which bothers me a lot. We sync code from perforce in my company. and then we are taught to build the code compatible to eclipse. Then we import the code in eclipse as existing project. Then when we hit ctrl-space from an object, we get suggestions of methods.
My question is: Why do we need to build the code for suggestions of methods? . After syncing from perforce, what I have is still an existing java project (right?). So eclipse should be smart enough to be able to index and find out from source code, the methods, when I hit ctrl-space on an object?.
Why do I need to build? What purpose the build serves?
The code does not have to be built, but to be able to import a directory as project via File > Import...: General > Existing Projects into Workspace into Eclipse, at least the file .project must exist.
There are several ways to import, for example, a Maven project:
Execute mvn eclipse:eclipse on the command line and in Eclipse do File > Import...: General > Existing Projects into Workspace
File > Import...: Maven > Existing Maven Projects without a command line call uses by default the in Eclipse embedded Maven
File > Open Projects from File System... (or in Git Repositories view right-click + Import Projects...) detects not only Maven projects but also plain Java projects and automatically configures them accordingly.
In all three ways the following files are created, which are required in Eclipse for the Java content assist (Ctrl+Space) to work:
.project - says whether it is e. g. a Java, a PHP or a C/C++ project (to be more precise, the project name, builders and natures are specified here, e. g. the project folder icon of a Java Maven project will be decorated with a M and a J based on the Java and Maven project natures)
.classpath - tells Eclipse where the source and output folders are and which JARs should be added to the classpath (in Maven projects, the JARs are not listed, but it refers to the Maven dependencies which are computed from the pom.xml file)
.settings/org.eclipse.jdt.core.prefs - contains Java compiler and optional formatter settings (e. g. which Java version; which problems should be ignored or shown as infos, as warnings or as errors, etc.)
With Eclipse Oomph you can automate even more: you select a project and based on a project-specific configuration, for example, a Git repository is automatically cloned and plug-ins necessary to edit the project are automatically installed and configured.
Eclipse uses relfection for the suggestion, it can be possible only if the .class file generated
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.
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
After running Maven - clean, I see sub folders in my M2_REPO folder. junit.jar was created in M2_REPO/junit/junit/4.11/ alone with some other files. Because of this sub folder structure, eclipse is not able to recognize the junit.jar file. What am I missing?
You're looking in the wrong directory. Eclipse shouldn't read the jars directly from this directory, it is the local cache of what maven manages.
The pom.xml is where you should put your dependencies, and eclipse will then use the maven libraries to get the required jar file, put it on the build path, and possibly cache it in the directory you are looking at.
Note that if you want the junit jar file for testing purposes, the typical file in src/main/java will not see it, because testing source code goes in src/test/java.
This means that maven provides (through the libraries) (at least) two classpaths. One for typical compilation and one for test compilation and execution. Adding in a <dependency> tag section puts it on the compilation and run paths; but, to make it "test only" you need a nested <scope> tag.
Maven correctly is creating those directories the first time it tries to acquire those artifacts.
For integrating maven and eclipse, try running mvn eclipse:eclipse
This should enable eclipse to see the jars maven has downloaded.
That is the path of the local M2 repository and the sub-folder structure is exactly how it should look.
Make sure that you import the project in eclipse as a maven project by doing
File -> Import -> Maven -> Existing maven project
I'm trying to check out a svn repo. So far so good, the checkout worked but there are no Packages. Is there a way to get the right packages in eclipse?
All the given data I do have is this:
svn co https://jensembl.svn.sourceforge.net/svnroot/jensembl jensembl
Furthermore, I'll add the link to the program, which i want to get working.
link to JEnsembl
/edit added a link to the explorer view of the current project
link
You need to generate eclipse project files using Maven.
See http://maven.apache.org/guides/mini/guide-ide-eclipse.html
Basically:
$ mvn install
$ mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
$ mvn eclipse:eclipse
You can import as a maven project and I feel that is the better way also
I have gone thru the repo you mentioned.
In Eclipse
File--> Import --> Check out Maven Projects from SCM
select svn and use this url
http://jensembl.svn.sourceforge.net/viewvc/jensembl/trunk/
or any subdirectory which contains the pom.xml
and see you can proceed further
On your harddisk a package is a normal folder. If you have the project in eclipse it has to know which of the folders are source folders. Eclipse will show all folders in a source folder as packages and recognize the classed as part of the project. Open the properties of the project. At first you have to go to the category Project Facets and enable Java. After that you can go to the category Java Build Path and add all source folders in the Source tab.
Furthermore you checked out the whole SVN repository which seems to contain a few projects/modules. You want to check them out (or at least import them to Eclipse) seperatly from the trunk folder. I'm also seeing that your project is a maven project so you might want to read up on maven and how to check out projects in eclipse. Here is a short how-to. Again you only want the trunk folder. If you want to know what that is you can read it up here.