|Re: Dynamic Web Project set up [message #900157 is a reply to message #900099]
||Sat, 04 August 2012 19:00
| Aaron Robinson
Registered: August 2012
** Part Solved **|
Creating a new dynamic web project from existing source.
There are a number of different ways that you can tell your project about the files you want to use in your project. The usual approach is to create a new project and then start creating files. Another common way is to create an Eclipse project off the back of existing code. There are a few ways you can do this. You can tell Eclipse to use the directory the existing files are in (by deselecting the 'Use Default Location' when creating the project). Any files you create from hereonin go in there. This is typically what you'd do when creating an Eclipse project for the first time from existing code. The second option is to import files into your project (right click on the project->Import->Import->File System then just select the files you want). This copies the files you specify into your workspace so you may not want this. In the typical scenario you will have checked a project out so the last thing you want to do is copy the files somewhere else to change them. The third option is to link to folders and files. This allows you to share files between projects. When you do this, you are free to change the file contents in your project so take care. You can't create new files in these linkied folders though. No matter where you bring other files from, when you create files they will go in your workspace, nowhere else.
When creating a new dynamic web project it creates two source areas, one for the Java and one for web content. Unless you uncheck the 'Use Default Location' it will create these folders in your workspace. If you want to work with (as in add files, remove files, change the dir structure etc) existing source you need to uncheck this and specify the directory under which your Java and web content exists. Eclipse defaults the Java source directory to 'src' and the web content to 'Web Resources'. Unless you change these you'll just end up with two new directories added to your existing code base. You can change your Java src directory during project creation or after in the build path options. In the version of Eclipse I'm using you have to specify the web content directory in 'content directory' in the 'Web Module' dialog in the project creation wizard. I haven't found a way to change this after the project has been created (unless you edit Eclipse project files directly). Set these to the names of your existing Java source and web content directories. As your directories already exist nothing will happen.
The next issue you may hit is that the web content in the existing source code isn't in WAR structure. In my case the projects I inherited had top level conf, java and web directories. Conf has web.xml, struts.xml etc (which need to go in WEB-XML). The web folder had the tld files in a tld folder yet the JSPs expected to find them in the root context. So the ant file that pulled everything together did some magic. This is fine if you want to use ant to build and deploy but Eclipse offers a very cool hot deployment option to a server of your choice. Just register a server in Eclipse and then select it when you create the project. You can run your project in any target server, see the console and run a web browser from within Eclipse. This is much nicer and quicker than working with ant and a broswer independently. This is what IDEs are all about.
In order to be able to leverage this though you need to tell Eclipse how to deploy your non WAR format file structure in WAR format. You do this in the project properties->Deployment Assembly. By default it has an entry for your Java and your web content. All you do is specify where to put what. In my case I had to tell it to put the files in conf into WEB-INF and to put the tld files in root.
When you're done making changes to the deployment assembly you can see the final structure in your workspace. Shame you can't see this from the IDE: - .metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\
You can export the war at any time by right clicking on the project and exporting it.
The only things I've failed to do are keep the Eclipse .project, .setting etc files and the Java class files away from the svn working directory. It's not that big a deal but it would be nice to be able to not pollute it with files the IDE needs and of course there is always a risk they get checked in.
Anyone know how to do this?
[Updated on: Sat, 04 August 2012 19:13]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.03812 seconds