Eclipse add source files to package explorer - eclipse

I checked out a Maven project folder from SVN. It is coming up as folders in the Package Explorer, and when I right click -> Build Path -> no actions available.
Is there anyway to add the source folder to appear as a package?

The project is not set up as an Java or Maven project inside Eclipse. You can apply the Maven and Java nature afterwards in the project properties, you could run mvn eclipse:eclipse outside of Eclipse and import the created Eclipse project into your workspace (it could even exist as option in the project's context menu under "Maven", depending on how the project is setup right now).
Or, much easier, you just checkout a Maven project from SVN. Within the "New Project..." dialog there should be an option "Maven > Check Out Maven Projects from SVN". Then it will be configured automatically.

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.

Subclipse checking out as folder not Java project

I'm trying to import a Java project from my teams subversion repository. So I go through the import GUI for subversion, select my repository and the project, then choose to check it out as a project into the workspace.
However, the project now appears in my workspace simply as a folder:
Trying to add a new class tells me "source folder is not a java project". Is there something I am missing? Thanks.
Check out as a project only does what you want if you have checked-in the Eclipse .project, .classpath files etc. In that scenario those files get checked out and configure the Eclipse project. Otherwise you are just getting an Eclipse "Simple Project" which does not have the Java tools configured.
I assume you do not have those Eclipse files in your repository, so you want to use the other option that lets you run the Eclipse Create Project wizard as part of the checkout. This lets you choose the project type and setup some of the configuration. You can skip most of the configuration since you can also do that after the checkout finishes if you prefer.
See: Subclipse Checkout Documentation

Can't run project in Eclipse imported from Git

I have a project in my Eclipse workspace from Github (via File -> Import -> Projects from GIT).
However, I am unable to run the example because the only option I have under "Run As" is "Run Configurations."
After going to "Run Configurations" I click "browse" and the project that I imported from GIT isn't there.
Any ideas?
The question is already answered in the comments but I am providing this answer to possibly clear up some misunderstandings.
In order to recognize a folder as a (Java) project, Eclipse needs to read (or create) a few files for each project, like .project and .classpath. If you do not have them in your project, or do no create them during the import, then Eclipse just imports it as a resource, or a dumb folder.
If your project is tracked by git and is also a maven project, you can clone it locally with Git (command line or GUI tool) and then "Import as existing Maven project" in Eclipse. This will use your pom.xml to create the two files mentioned above and your project will be buildable.
Alternatively, if you have already imported it as you described in your question, you can right click on your project on Package Explorer and choose Configure-->Convert to Maven Project. This will create the .project and allow you to build the project using Maven (right click->Run as..-> Maven build) and Eclipse's incremental builder (where necessary). If your maven project builds an executable, the option to execute it will also be available in the Run as.. menu.
If you have a more complex maven project (like an aggregate pom), and want a Run Configuration that runs a specific program, you will have to write it yourself by opening the Run Configurations window and explicitly referencing the java class.
Don't import the project using git clone. Download it as zip file and extract it. Add it using Project>import> General> Projects from folder and Archive.
Provide path of extracted folder into import source and finish and go to eclipse and clean and build safely run and right click on project and run it.
It should work

Importing maven sourceproject into eclipse

I have imported my maven project in eclipse using Import Maven project. It got import in eclipse project explorer, but all the source folder are opening as files and folders, its not opening as java source folder. Since its opening as files and folder, it doesnot have compilation unit, found very difficult to code using it.
What do I need to do inorder to make the source folder as java source folder so that I can code easily?
Select the project and from the context menu choose Maven -> Update Project Configuration (This menu item gets reworded across various maven releases so look for something similar). You may also need to choose Update Dependencies.
In the shell/command line, execute mvn eclipse:eclipse

Maven dynamic web project in eclipse deploys invalid jar files for dependent project(s)

I have a maven web project that imported into eclipse. I have another maven project (generates a jar file) that the web project depends on.
Both of these projects work correctly when executed from the command line. mvn package creates a war file which pulls the jar it depends on from the maven repository for the web project. mvn package creates a valid jar file when run for the library.
When I import the library into Eclipse, m2e recognizes that the web project depends on the library and updates parts of the project to take advantage of the fact that both maven projects are hosted within a single Eclipse workspace. The "Maven Dependencies" section of the "Libraries" tab of the "Java Build Path" preference for the web project removes the library jar file and replaces it with the library project. As the library is updated in Eclipse, the web project recognizes those changes without having to install/deploy the library.
The problem occurs when I attempt to run the web application in Eclipse. Because Eclipse is actually building the Web project against the version of the library in Eclipse, it does not deploy the library file from the maven repository, it creates a new jar file that's a snapshot of the current version of the library in Eclipse. All of this has generally worked well for me, but on the project I'm currently working on there's a problem with the jar file that Eclipse is creating. Instead of inserting the class files for the library, it appears that it's taking the "src" directory of my Maven project and zipping it up as the jar file. The contents of the jar file look something like:
-main
-java
-com
-... *.java
-resources
-...
-test
-java
-com
-... *.java
Where I would expect it to look more like:
-com
-... *.class
Since I have successfully used this type of project before, I'm trying to figure out if there's something I need to configure or if I've just run into a bug.
I'm using the latest update of m2e (1.0.200.20111228-1245) on Eclipse Indigo (Build id: 20120216-1857).
In Eclipse, we can disable the "Workspace Resolution" so that it will use our dependencies directly from the local maven repository as the following steps: -
Disable Workspace Resolution
Right click at the project inside the eclipse
Select "Maven" from the context menu.
If it display "Disable Workspace Resolution" which means it is enable. We click it with purpose to disable it. Please note, after that it will display "Enable Workspace Resolution" which means we have disabled already.
We may need to update the project configuration and other related dependencies as the following steps: -
Update Project Configuration
Right click at the project inside the eclipse
Select "Maven" from the context menu.
Click the "Update Project Configuration..."
The "Update Maven Dependencies" windows will be displayed.
Select the required projects and click "OK".
Update Dependencies
Right click at the project inside the eclipse
Select "Maven" from the context menu.
Click the "*Update Dependencies"
The "Update Maven Dependencies" windows will be displayed.
Select the required projects and click "OK".
Please take a note, since we not use the related dependencies directly from the workspace anymore, It will use directly from our local maven repository. Then all related artifacts should be installed to our local maven repository by using the following command line.
mvn install
Anyhow it can be done by using the context menu inside the Eclipse as the following steps:-
Right click at the project inside the eclipse
Select "Run As" ---> "Maven Install".
Here's the solution that I came up with.
It appears that in my case the rules for the "Deployment Assembly" for the library project are still followed.
To change it go to the library properties->Deployment Assembly
In my case that just contained a mapping from '/src' -> '/'. I removed that entry and replaced it with a mapping from '/target/classes' -> '/' and '/src/main/resources' -> '/'.
Once I had that mapping in place, when the jar file was deployed it contained exactly what I had configured in the Deployment Assembly. That allows Eclipse to continue to be used without explicitly republishing the library for every change. But, it doesn't seem to auto redeploy to tomcat for me when the library is updated -- I still need to manually restart tomcat for library changes to be reflected.
It's still not entirely clear to me what's going on with this project. I do have previous projects that have a similar structure, and in those projects the Deployment Assembly has not been updated to explicitly include the class files and yet the proper jar file is still deployed.