Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse and external src and web content folder linking or mapping

First thing this is not the question but the solution of the problem which I have faced and waste 4,5 hours to find out the solution. please let me know if there is any better alternative to manage the external src folder with eclipse project.

I am using a version version control system (GIT) to manage my project. Also accessing the Repository using the external Git client (SourceTree)

Note : Same scenario can be possible with SVN and tortoise SVN as well.

In Eclipse : when I am creating a dynamic web project, it also content the "src" and "WebContent" folder, while i want to use the external folder (which I have checkout from Git Repo using Git client) .... I did lots of searching on google to map or link the external src and WebContent folder but not found the way. finally I have got the success. posting this information here .... so may be useful for someone.

(1) Assume you have check out the content at location "C:\MyGitRepo\" which having 2 folder "src" and "WebContent"

(2) create dynamic web project in eclipse : set source folder name to "src2"

Source folder mapping

(3) Right click on project -> New -> folder -> advance -> link to alternative location -> "C:\MyGitRepo\src"

(3) Right click on project -> New -> Source folder -> browser -> "src"

(4) Delete the "Src2"

Web Content folder mapping

(5) Delete the existing "WebContent" folder

(6) Right click on project -> New -> folder -> advance -> link to alternative location -> "C:\MyGitRepo\WebContent"

(7) project property -> Deployment assembly -> Add folder -> next -> select "WebContent" folder

Everything work fine... means there is no src and web content folder in your workspace and you are using the external one

We can use the eclipse plugin as well to do so but it is more convenient to use the external client (tortoise SVN or source tree)

like image 300
Rakesh Soni Avatar asked Aug 28 '13 15:08

Rakesh Soni


People also ask

What is WebContent folder in Eclipse?

This Java classes folder is created while importing a WAR file. You can also use the Java Build Path properties page to create Java classes folders. WebContent. Contains all of the web resources. For example, the HTML files, JSP files, and image files that are used to create a web application.

What is src folder in Eclipse?

When you create an API project, it is set up as a Java project with separate folders for source and class files. The source folder is named src . It contains the Java code of the application. A few Java classes are also created together with the new project.

What is the difference between source folder and folder in Eclipse?

A source folder is marked by Eclipse as containing java sources. Then, when you compile your project Eclipse will look for your source code into all your source folders. You can make any folder become a source folder adding it to the java build path.


1 Answers

When you create a dynamic projects in eclipse it basically stores the settings of the project in ./settings/org.eclipse.wst.common.component. This is not viewable in package explorer you need to use navigator to access that.

Below is the example from the demo project I created:

File : org.eclipse.wst.common.component

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="demo">
        <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
        <property name="context-root" value="demo"/>
        <property name="java-output-path" value="/demo/build/classes"/>
    </wb-module>
</project-modules>

As you can see there is an xml tag <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/> there you can define your webContent directory which contains your web resources (html, jsp, aspx, js, etc.)

The next line <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/> is telling the path where java classes resides. This can be edited to your choice of source folder as well.

Once you are done with that please folow the steps below :

  1. Right click your project > properties.
  2. Go to Java Build Path in the preferences window.
  3. Click the source tab and remove the existing src folder and your desired one.
  4. Once done with changes checkin the settings file in the version control.

Problem solved for every checkout.

Let me know if that helped.

like image 50
Himanshu Chaudhary Avatar answered Oct 22 '22 21:10

Himanshu Chaudhary