Creating a lenya Project in Eclipse

Instructions are specific to Eclipse 3.0.2 but should be similar in other version's. Also check out the instructions over at the Cocoon wiki

  • Download a Java Development Kit if you do not have one. Set up the JAVA_HOME environmental variable.
  • Check your JAVA_HOME definition to make sure that it points to a JDK not just a run-time.
  • Get Eclipse from http://eclipse.org
  • Install Subclipse from http://subclipse.tigris.org (see instructions for adding "New Remote Site")
  • Get Lenya source from svn if you don't already have it (see http://lenya.apache.org/1_4/installation/subversion.html). You can also just download it and extract it to a directory if you are not intending to share your mods with the Lenya project.
  • Follow the install instructions (using the built-in Jetty) for lenya (see http://lenya.apache.org/1_4/installation/source_version.html)
  • Remove .classpath and .project from your Lenya source dist if you have already built Lenya (Apparently they fool Eclipse into thinking that a project has already been created)
  • Get the latest Cocoon source and extract the files into a directory (eg. C:\Cocoon-2.1.7). It does not have to be in the Eclipse Workspace since it will only be referenced. Cocoon will not be built but pieces of it will be incorporated into the Lenya build.
  • Create a local.build.properties file in the same directory as the lenya build.properties file.
  • Modify the cocoon.src.dir to match the folder where you have extracted Cocoon (eg. cocoon.src.dir=C:\Cocoon-2.1.7).
  • If you are using Java 1.5, you need to make sure that you download the latest xalan from apache.org and copy the jar files into the Java lib/endorsed folder. You may have to create the folder if you have not added libraries to this java release in the past.
  • Open Eclipse and create a new java project
    • file -> new project, select "Java Project" and click next
    • check "Create project at external location" and select your lenya source dist, click next
    • under the "Source" tab remove all build paths other than {project name}/src/java
    • click on the "Libraries" tab, click "Add Library..."
    • select "User Library" and click next
    • click on "User Libraries..." button, click on "New..." button
    • give your cocoon library a name (perhaps something like "cocoon") and click "ok"
    • with your new library selected, click on "Add JARs..."
    • select all of the jar files from your cocoon/build/webapp/WEB-INF/lib directory and click "open"
    • click "ok", click "finish", click "finish" again
    • add the Lenya jars by clicking Add JARs on the Libraries tab, and including lib/ and tools/lib
    • If you are using Java 1.5, you also need to add the xalan libraries to your Lenya project classpath as you did above for Cocoon.
    • wait while Eclipse builds your workspace (don't be surprised if you get some errors)
    • NOTE: Eclipse is simply compiling the files in your project, You will still need to "build" and "build clean" to build lenya (deploy publications)
    • if you got build errors in the Problems pane, make sure that jdk compliance is set to 1.4
      • open your projects properties
      • select "Java Compiler"
      • check the "Use project settings" radio and then the "Compliance and Classfiles" tab
      • be sure to uncheck "Use default compliance settings"
      • make sure "Compiler compliance level", "Generated .class files compatibility", and "Source compatibility" are set to 1.4
      • click "ok", your project should be re-built, hopefully you don't get any errors
    • add svn support to your project if you intend to share your project with the Lenya team.
    • right click on your project, select "Team"
    • select "Share Project..."
    • select "SVN" as the repository type and click next button, click "finish"

You should be ready to roll, this was my experience. If you have other issues or hints, please add them (smile)

Running Lenya in the Eclipse debugger

First way

_ ripped from http://wiki.apache.org/cocoon/LoadInEclipse_

Preparation

  • Create Lenya Project in Eclipse (see above)

Eclipse Setup

  • in the resource perspective, refresh the project
  • open the Debug perspective
  • launch the Run configurations wizard (Run > Run...)
  • create a new Java Application Configuration for Lenya Jetty
    • give it a name ("Lenya Jetty" for instance)
    • on the 'Main' tab:
      • Project: click Browse... and select the Lenya project you loaded in Eclipse (this will load a default classpath)
      • Main class: 'Loader' (without the quotes)
    • on the 'Classpath' tab, remove 'default classpath'
    • add './tools/jetty/lib/jetty-x.y.z.jar' and './tools/jetty/lib/servlet-2.3.jar' to the classpath (Add JARs...)
    • add the './tools/loader/' Folder to the classpath (Advanced...> Add Folder)
    • on the 'Arguments' tab set:
      • Program arguments: "tools\jetty\conf\main.xml" (with quotes)
      • VM arguments:
        -Djava.endorsed.dirs=./lib/endorsed
        -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser
        -Djetty.port=8888
        -Dloader.jar.repositories=./tools/jetty/lib:./lib/endorsed
        -Dwebapp=./build/lenya/webapp
        -Dhome=.
        -Dloader.main.class=org.mortbay.jetty.Server
        
    • Apply
    • Run

This will launch Jetty from within Eclipse and you'll see Jetty's output in the console of your debug perspective. Your application should run at http://localhost:8888/.

ProgramArguments

./tools/jetty/conf/main.xml

VMArguments

-Djava.endorsed.dirs=./lib/endorsed
-Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser
-Djetty.port=8888
-Dloader.jar.repositories=./tools/jetty/lib:./lib/endorsed
-Dwebapp=./build/lenya/webapp
-Dhome=.
-Dloader.main.class=org.mortbay.jetty.Server

MainClass

Loader

Classpath

Add all libs under build/lenya/webapp/WEB-INF/lib to your project classpath. This is needed to compile Lenya in Eclipse and that the VM finds all libs if Lenya/Cocoon is started by Eclipse.

Addionally add tools/loader to the classpath of your newly created program.

To start Lenya in debugger choose Run->Debug... and choose your application and press debug.

2nd way

  • Create Lenya Project in Eclipse (see above)
  • Start Lenya in a concole using
./lenya.sh servlet-debug
  • Now open in Eclipse the class you want to debug
  • Goto the Java or debug perspective and choose Run->Debug...
  • Click on "New" to create a new Remote Java Application for your Lenya project.
  • Make sure to use 127.0.0.1 instead of localhost.
  • In the Source tab, add your Lenya project. Cocoon should be added automatically.
  • Press debug.
  • In your class, add breakpoints
  • Run lenya and debug in Eclipse

Another Way (Tomcat&Eclipse)

Download and install: http://www.sysdeo.com/eclipse/tomcatplugin

configure: Window->Preferences... Tomcat, Tomcat Version, Tomcat Home, Context declaration Mode.

now you can start your tomcat from within eclipse. if you do so you can use the debugger.

  • No labels