问题
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)
回答1:
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 :
- Right click your project > properties.
- Go to Java Build Path in the preferences window.
- Click the source tab and remove the existing src folder and your desired one.
- Once done with changes checkin the settings file in the version control.
Problem solved for every checkout.
Let me know if that helped.
来源:https://stackoverflow.com/questions/18492293/eclipse-and-external-src-and-web-content-folder-linking-or-mapping