SnipSnap, Eclispe 3.0, and MyEclipse
I've managed to get SnipSnap to work
well using Eclipse 3.0 and MyEclipse 3.8.2. The way it works is a bit hacky, so bear with me.
Goals
- Use MyEclipse to automatically build and deploy SnipSnap during development.
- Use CVS to manage the source tree such that updates from the official SnipSnap distribution can be easily incorporated.
Plan
The basic idea is to use CVS's module features to extract pieces of the monolithic SnipSnap tree into a MyEclipse-oriented project. The end result is the
SnipSnapApp project - the webapp that contains all of the JSP, images, etc. that make SnipSnap tick.
The project follows the standard MyEclipse Web Application directory structure. For example, there should be no files in
../WEB-INF/classes that can't be deleted when the project is rebuilt automatically.
The target directory structure is:
SnipSnapApp
plugins
META-INF/services
src
org.snipsnap.*
test
org.snipsnap.test
conf
org/snipsnap/config/defaults.conf
org/snipsnap/config/globals.conf
defaults
defaults
locale
i18n
documentation
lib
WebApp
META-INF/*
WEB-INF
lib
themes
admin/*
static/*
util/*
*.jsp
favicon.ico
default.css
Note: I have not found a way to make the
test directory contain only the tests
and allow classes not in org.snipsnap.test to be checked in to CVS. As a result, I've left the tests in the
src directory and excluded them from the build. (This is necessary to get a clean build, too.)
Prerequisites:
- Eclipse 3.0 (
latest)
- MyEclipse 3.8.2 (
latest)
- a CVS server that you control that is accessable from Eclipse (pserver/ssh)
- about an hour of free time
Steps:
Tip 1 Before starting, you may want to disable automatic building in Eclipse - it may save you from the occasional lock-up.Tip 2 If something doesn't behave properly, quit Eclipse and re-start it. I spent hours chasing non-existant CVS problems because Eclipse refused to read the CVSROOT/modules file.
- Download SnipSnap.
- In Eclispe (or whatever) checkout the CVSROOT module. (This is where all of the administrative files are stored.)
- Change cvswrappers to ensure that CVS will automatically check-in jar files in binary mode. If you don't, you'll have no end of problems later on. You should also make sure that .png and .ico files are binary, too. My
cvswrappers file adds several common types.
- Import SnipSnap into CVS.
I used: cvs -d ~/Projects/SnipSnap/CVSRepository import -m "Import of SnipSnap release uttoxeter-1.0b1." SnipSnap FIRST uttoxeter v1_0b1
- Import an empty directory into CVS under the name SnipSnapAppRoot.
- Take the entries in this
modules file and add them to your CVSROOT/modules.
- Checkin this file. Do not try to use the CVS Explorer to verify that you can see these new modules. I'm not sure why, but it really freaks Eclipse out.
- Checkout the module SnipAll as a Simple project using File -> Import in Eclipse. This should checkout all of SnipSnap under the project name "SnipAll". Again, do not browse for this module, type in the name and hit Finish.
- In the Resource perspective, do an ant build by right-clicking on build.xml and selecting Run > Ant build.... (Add the -verbose argument, to ant if you want.) This should build the project. If your build hangs after SnipSnapPingHandler.java, you probably have corrupt libraries. Check that they are all using binary keyword substitution and try again.
- Refresh the project so that all the new files and directories are visible.
- Using the Team menu, add .cvsignore files for the directory cls and all of the new jar files. (You'll find some in lib and some under src/apps/default/WEB-INF/lib.) You can check the .cvsignore files into CVS if you'd like.
- There should be two new java files, Configuration.java and Globals.java. Check these into CVS. You can check in the .project file that Eclipse creates because we use a different directory for the root of the web app.
- Using the File -> Import command again, check out the SnipSnapApp module as a Simple project. Again, type the name in and hit Finish.
- To convert the SnipSnapApp project to a Java project with the right path, add this
.classpath, this
.project, and this
.mymetadata. Note that we exclude the ../cookbook/Diff.java, and all of the tests from compilation because they cause problems.
- Next, you need to replace the contents WEB-INF/web.xml file with the contents of the WEB-INF/web-xml.tmpl file. Near the top, you'll find a @VERSION@ marker. You can replace this with whatever you want. Further down, you'll find @PRECOMPILED-JSP@. Comment this out.
- You'll need to change some of the values in org.snipsnap.config.defaults.conf and org.snipsnap.config.globals.conf to match where you plan to deploy to. In defaults.conf, I change app.prefix. In globals.conf I change app.host, __app.port__, and app.path to match my Tomcat installation, plus snipsnap.server.version.
- Finally, you need to copy the copyright.txt file from conf in the SnipAll project to defaults/defaults in the SnipSnapApp folder.
Tip 3 Never try to CVS update any of the directories. Only Synchronize with Repository in outgoing mode. When you want to import updates to SnipSnap, do the merging using the SnipAll project, then very carefully update SnipSnapApp. If you don't, Eclipse will import all of the directories in CVS that we very carefully avoided importing and you'll wind up with a horrible mess.Tip 4 If you use file-based storage on anything that saves data in the web app's space, doing a Redeploy will blow away all of your data. You have been warned.Tip 5 You can avoid the redeployment problems (when using file-based storage) when you change the following line in global.conf: app.file.store = %WEBINF%/filesI have set it to app.file.store = /snipsnapNow a top level directory "snipsnap" is used as storage (on the same drive as your tomcat installation if you use Windows)
If you find any problems with these instructions, have any questions, or have a better way, please let me know.