Presentation is loading. Please wait.

Presentation is loading. Please wait.

Developing CAS in Eclipse

Similar presentations

Presentation on theme: "Developing CAS in Eclipse"— Presentation transcript:

1 Developing CAS in Eclipse
Edit and Debug

2 Maven is Best Practice Compile and Zip WAR file with Maven 2
Manage “dependencies” (external JARs from other software libraries or products) Run tests to validate each change cycle Build JAR, WAR, or other standard “artifacts” Edit with Eclipse Syntax and help for Java and XML Widely used, modularly extensible IDE How about simple testing with Eclipse? Maven 2 has been widely adopted as a best practice for release engineering. It organizes the entire project into components, each with source, resources, and test cases. It runs tests to validate each change cycle, and builds JAR, WAR, and other final form product files that it calls “artifacts”. You definitely want to use Maven 2 to build any production releases, and before integration or final test cycles. However, when you are editing a new class and debugging it for the first time, a full cycle that compiles everything and runs all the tests is more than is necessary. The CAS source repository has checked in files to define the CAS server as an Eclipse project. Eclipse is an open source IDE environment for developing Java (and other languages). It has context sensitive editing and the usual intelligent help capabilities. Eclipse can also compile, deploy, and test programs, including J2EE or Servlet applications like CAS. However, the official CAS distribution does not use this capability. Instead, Eclipse is used simply to edit source, and Maven 2 is used to compile and package. This presentation shows how to extend the CAS Eclipse project to allow simple build, run, and debug. This can be regarded as a preliminary step to a full Maven 2 build cycle and not as a substitute.

3 Maven Compile Main POM Core project source + POM
Option project source + POM artifact jar artifact jar artifact jar Option project source + POM artifact jar CAS is distributed as a main Maven project directory with subprojects. There is a required “core” subproject and then various optional subprojects that provide additional specialized support. Each Maven project is defined by a POM (pom.xml file). In these Java Source projects, the POM defines the name, type, and version number of the “artifact” being created (a JAR file in these cases). The POM also lists the names of standard external library JAR files needed by each project when it is compiled. Option project source + POM

4 Top level Maven POM optional projects are compiled
<modules> <module>cas-server-core</module> <module>cas-server-support-generic</module> <module>cas-server-support-jdbc</module> <module>cas-server-support-ldap</module> <module>cas-server-support-openid</module> <module>cas-server-support-radius</module> <module>cas-server-support-spnego</module> <module>cas-server-support-trusted</module> <module>cas-server-support-x509</module> <module>cas-server-integration-jboss</module> <module>cas-server-webapp</module> </modules> Options The top level POM in the root directory has a list of subprojects that need to be processed. The cas-server-core component goes first. The cas-server-webapp goes last. The optional components go in the middle. If you don’t intend to use an option, you can delete the reference to that project and speed up the Maven 2 build. The presence of an optional project in this top level list only means that the project will be compiled and a JAR file will be created. In order for the classes in that JAR file to be available when CAS runs, you also have to add the JAR file to the list of dependencies in the cas-server-webapp project POM.

5 Java Subproject POM Generated result JAR for Compile
<artifactId>cas-server-support-trusted</artifactId> <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.jasig.cas</groupId> <artifactId>cas-server-core</artifactId> <version>${project.version}</version> </dependency> <groupId>cas</groupId> <artifactId>casclient</artifactId> <version>2.1.1</version> Generated result Each Maven subproject has a POM file. For the subprojects that compile Java source code, the result of building the project is a JAR library containing the classes from the compile. The POM lists any library JAR files (external or previously compiled) that this project needs to satisfy references at compile time. JAR for Compile

6 Maven build WAR Main POM cas.war webapp HTML + POM WEB-INF/lib
artifact jar artifact jar artifact jar artifact jar cas.war The last subproject named in the top level main POM is the “cas-server-webapp” subdirectory. This is the subproject that builds the Web application represented by a WAR file artifact. Since the WAR must include all the JAR files built during the Java Source project compile steps, this project has to be run last. The project contains the HTML, JSP, CSS and other Web files that will be deployed to the Java Web Server. Maven automatically copies the JAR files from the compiles and external JAR libraries downloaded from public repositories. webapp HTML + POM WEB-INF/lib

7 cas-server-webapp/pom.xml core required, add option JARs
<dependency> <groupId>org.jasig.cas</groupId> <artifactId>cas-server-core</artifactId> <version>${project.version}</version> </dependency> <artifactId>cas-server-support-trusted</artifactId> <artifactId>cas-server-support-x509</artifactId> Default is core only Add option artifacts you choose The POM in the cas-server-webapp project also has a list of dependencies. However, while the dependencies in a Java source project become part of the compile time classpath, the dependencies in a WAR building project are JAR files moved to the WEB-INF/lib of the generated WAR directory. While the checked out top level POM lists all the optional subprojects, causing all to be compiled and tested, the checked out cas-server-webapp POM only lists the cas- server-core JAR file as a dependency. In this example, the administrator has added the cas-server-support-trusted and cas-server-support-x509 projects to the lists so that they too are copied to the WAR file and their classes are available for use in the Spring configuration of CAS.

8 Eclipse “workspace”, CAS “project” Maven projects
{$home}/workspace CAS3xx [Eclipse project] Main POM subproject subproject When Eclipse starts up, you select a Workspace directory. Later on you can switch from one Workspace to another. Each Workspace has a set of projects represented by subdirectories of the Workspace. (Note: projects can be external directories, in which case the Workspace only contains the path to the external project, but normally projects are subdirectories inside the workspace.) Each Eclipse project is configured by a “.project” and “.classpath” XML file. When you check out CAS from the JA-SIG SVN source repository, starter versions of these files will be downloaded and used as defaults for the new Eclipse project. To avoid versioning problems when the next release comes out, a good practice is to name the project for the tagged version number you are checking out. Thus the CAS release becomes an Eclipse project named “CAS330” (but this is just a suggestion). The Eclipse project you check out will also have a pom.xml file and subprojects. So it is a “project” to both CAS and Maven, thanks to two different sets of files. subproject

9 Assume You Know How Install current Java Install Apache Tomcat
Install and use Maven 2.0.9 You download and install Java from Sun. Then you define the JAVA_HOME environment variable. You download and upzip Tomcat from Apache. You download and uzip Maven from Apache. Then you define the M2_HOME environment variable and add the mvn batch file or shell file to the path. These are all steps from the standard CAS development sequence, so they are not discussed in detail here. Because this is all part of the standard CAS development instructions.

10 Fork In the Road Eclipse Web Standard Tools MyEclipse Free
Part of Eclipse project Open source New release each June Independent plugins don’t work smoothly together $31.75 /year Includes WST, plus Spring, WS, Hibernate, JPA, … A particular group of plugins have been integrated The first choice you have to make is whether to use the Web Standard Tools (WST) from the Eclipse Web Tools Project (WTP), or whether to spend $31.75 per year per programmer to license MyEclipse. The whole Eclipse project releases a new version every June. The current version is 3.4, and the code name for this release is Ganymede. MyEclipse adds a lot of its own separate features on its own schedule. Since the WST is open source, MyEclipse can incorporate any desirable features from each new release. Vanilla Eclipse has a lot of projects that generate plugin support for optional features: EE, JPA, JSF, Maven, Spring, etc. Since each plugin is developed separately, they do not integrate with each other. As will be shown, the EE support doesn’t know about Maven external dependencies in the Maven repository. MyEclipse has a different approach to deployment and debugging. However, it also makes changes to the various open source plugins so that they do operate together more seamlessly.

11 WST Debugging Eclipse CAS classes Servers /conf Web project Tomcat
WST does not come with any Java Application Servers. Before you can do EE development, you must install at least one server, such as Tomcat 6. You configure Tomcat in the Servers tab of the Eclipse properties. However, WST does not “run” that server. It uses the Tomcat directory as a source of classes, but it builds a configuration file in the Eclipse Workspace and runs the Tomcat classes from within Eclipse. More importantly, it hooks the Tomcat ClassLoader so the /cas application finds its Web files in the Web project and finds the CAS class files in the CAS Java source project inside the Workspace directory. The Tomcat directory is not modified, so when you shut Eclipse down and run Tomcat, it is empty and has no idea what CAS is. This strategy gives WST more control over Tomcat’s execution behavior, but at the cost that Tomcat’s environment is non-standard. If some class is not found, there is no way to figure how to fix it. Tomcat directory Tomcat process

12 MyEclipse Eclipse CAS Project Java Source Tomcat, JBoss, … WebContent
/webapps or /deploy MyEclipse has a much less exotic solution. The CAS project contains a directory that is an exact image of the unzipped WAR file. You put the HTML, JSP, and CSS files where they belong and build the web.xml configuration file. MyEclipse compiles the CAS source into the WEB-INF/classes subdirectory. This directory can then be deployed to one or more Application Servers. For Tomcat, all the files are copied over to the /webapps subdirectory of Tomcat, but MyEclipse also knows how to deploy files to Geronimo, JBoss, Glassfish, and other types of servers. Then the configured server is run normally. So with MyEclipse, if you exit Eclipse and run Tomcat then the most recent version of CAS is deployed normally and runs under the standalone Tomcat. After the classes are compiled and deployed the first time, MyEclipse automatically copies recompiled class files to the server directory every time the editor saves a source file. If the server is running it knows which files can be replaced “on the fly” and which require that the context be recycled or the editor be stopped. WEB-INF/classes

13 By any other Name A “project” in Eclipse or Maven is a directory with source subdirectories that can be compiled to produce a JAR file or zipped up to produce a WAR file A “Java Project” has source to compile. It can produce a program or a JAR library. A “static Web project” is a bunch of HTML, CSS, and image files that you can deploy to any Web Server. It has no Java. Eclipse has many types of projects. Each project is a directory in the Workspace. Now in theory projects can contain C, PHP, or even COBOL source. We are not interested in those. A Java Project contains Java source. The source is compiled and if there is a class with a main() method it can run as an application. If not, then it could be used to export a JAR library file. A static Web project is just a bunch of HTML, stylesheets, and XML files. These files could be copied to any Web server including ISS or Apache.

14 By Any Other Name A “dynamic Web application project” has a WEB-INF subdirectory with a web.xml file A “WAR file” is a zipped up copy of the dynamic Web application, but the unzipped directory is also sometimes called a WAR too. A “context” is the runtime environment created by the Web server to run the code in a dynamic Web application A Dynamic Web Project has a WEB-INF subdirectory containing a web.xml configuration file. It can run Java Servlets and Filters. It can run in a simple Java Servlet container like Tomcat, or it can provide the user interface layer for a more complicated J2EE application that also uses ESBs. To deploy a dynamic Web application on a server, its directory can be zipped up to create a WAR file. Maven creates a cas.war file as the final step of the build process. Eclipse can produce a WAR file, but since it is most useful for quick one-line-change compile and test scenarios, it typically arranges to use unzipped individual files without either WAR or JAR packaging. Each WAR file creates a new top level directory on the Web server. The cas.war file is unzipped to produce the /cas application as in “ The control blocks and environment shared by code in a dynamic Web application is called a “context” when the application is running.

15 Ganymede WST Dynamic Web projects can only be created empty. A Java SE project cannot be converted into a dynamic Web project. The JA-SIG CAS source is an ordinary Java SE source project. Create an empty dynamic Web project. Copy the cas-server-webapp contents. Configure the CAS project as a “library module” for the Web project . Finally, copy external JAR dependencies into the WEB-INF/lib. The Eclipse WST project decided that a Dynamic Web Project had to be created empty and then populated with Web Content (HTML) and Java Source. Therefore, there is no way to convert or add WST to the existing CAS plain Java SE source project that SVN requires you to check out in one directory. The solution is to check out CAS and then create a second separate WST Dynamic Web Project. The only thing you have to copy is the Web application directory from the cas-server-webapp subproject of CAS. All the CAS source can stay where it is because the CAS project can be linked to the Dynamic Web Project as a “library”. WST treats the CAS project as if its classes were logically (though not physically) included in the WEB-INF/classes of the Web application.

16 WST Runtime Magic <Context docBase="casx" path="/casx“ source="org.eclipse.jst.jee.server:casx"/> Get files from the dynamic Web project dir. Get classes from the CAS compiler output directory. No support for Maven dependencies. Normally Tomcat finds the files for a context in its “webapps” subdirectory, although a context can be defined that uses some other directory path. However, when Tomcat runs under WST, the context is defined to be associated with a Java ClassLoader supplied by Eclipse. This ClassLoader finds ordinary files in the dynamic Web application project directory in the Eclipse workspace. It loads classes from the associated library projects. In this case, this is the main CAS project in the Workspace. Eclipse is a modular, extensible system. You can add J2EE support and you can add Maven 2 support. Just don’t expect two such options to know about each other and work together well. The WTP magic ClassLoader doesn’t know about the external JAR files in the Maven repository referenced as POM dependencies. The Maven plugin adds these JAR files to the Classpath for the source compile, but it doesn’t know how to communicate with the WTP Magic ClassLoader so they will be searched when Tomcat runs under Eclipse debugging.

17 Library Project (CAS source)
Create WST project Eclipse Library Project (CAS source) copy from cas-server-webapp project the src/main/webapp files and target/cas-server-webapp-3.3/WEB-INF/lib jars new dynamic Web proj So, you have to run a Maven 2 build of the CAS source project. Exit Eclipse and run “mvn install” from the command prompt in the CAS main source project directory. This builds the WAR directory with all the external JAR files. Now copy these external JAR files from the cas-server-webapp/target/cas-server- webapp-3.3/WEB-INF/lib directory just created by the Maven build to the WEB- INF/lib subdirectory of the new dynamic Web application project. Exclude the cas- server-*.jar files created as artifacts by the Maven compile steps, because the WST gets the latest version of all CAS classes from the output directory of the Eclipse compiler, and you don’t want the confusion of having two copies of the same class file one compiled by Maven and one by Eclipse. dynamic web project (WAR) Tomcat /conf Tomcat directory Server

18 MyEclipse Good News: MyEclipse can add “dynamic Web application” behavior to an existing Java (SE) project. Bad News: MyEclipse uses the WEB-INF/classes directory as a build work area, so the WebContent directory can’t be in cas-server-webapp Copy cas-server-webapp source to an new WebContent directory MyEclipse was started as a separate J2EE development product before the Eclipse project decided to add vanilla EE support. In a lot of small ways, MyEclipse is better and easier to use. The MyEclipse developers did not believe that it would be too hard to convert a plain Java Eclipse project into a dynamic Web application, so they made that possible from the beginning. As with vanilla Eclipse EE support, you configure external servers (Tomcat 6) and when you add dynamic Web application capability to an existing Java source project you have to nominate a directory that will contain all the HTML, JSP, XML, CSS, and other Web application source files. However, MyEclipse was less fancy and doesn’t use magic. The simple and obvious way to create a Web application directory that uses all the classes created from all the Java source directories is to tell the compiler to store its output in the WEB- INF/classes subdirectory of whatever directory you specify to hold the Web content. Since WEB-INF/classes is being used as a work area, MyEclipse hides that directory from you and it doesn’t appear in the tree of subdirectories under the project. This is, however, incompatible with the way that Maven uses the cas-server-webapp subproject structure. Therefore, you cannot use cas-server-webapp as the MyEclipse web content directory. You have to create a new empty web content directory and copy over the HTML and JSP files from cas-server-webapp. The end result is not that much different from vanilla Eclipse. You have to copy all the cas-server-webapp files, except in vanilla Eclipse you copy them to a new project while in MyEclipse you copy them to a new directory in the same project.

19 MyEclipse Deployment Web application is copied to the real external {tomcat}/webapps directory and the real external server configuration is started Tomcat runs with normal environment, under with Eclipse debugging Any problems can be fixed by standard Tomcat documentation and configuration Application can also run under Tomcat without Eclipse Now we get to the really important difference. Again, MyEclipse does the simple thing rather than the fancy thing. Instead or running the external Web application server in some manufactured internal configuration so that the HTML and CSS files in the project directory can be used in place, MyEclipse “deploys” the application by copying all the files, including HTML source and Java class files, to the deployment directory of the external Web Server. Then it starts the external server in basically the same way with the same environment and the same configuration as if you ran {tomcat}/bin/startup. Since there is no magic, you have complete control over the Application Server environment using the standard configuration tools. You can install certificates, configure SSL ports, turn on client certificates, and whatever else you would do for a production environment. Even better, MyEclipse knows how to do this not only for Tomcat, but also for JBoss, Geronimo, Glassfish, and all the other widely used J2EE Application Servers.

20 Download Ganymede EE from
Go to Click the Downloads option. Select the Eclipse Packages tab. Choose the Eclipse IDE for Java EE Developers package. Select the package for your OS. The download is a zip or tar file that you unpack to a directory anywhere on disk. You run the Eclipse program in this directory.

21 Download MyEclipse 7.0 (M2 or later)
Go to Select Try Now/Download. Find MyEclipse 7.0 or later under either released versions or Development Releases. Accept the license terms. The All in One package contains a JRE, copy of Eclipse, and the MyEclipse additions. It is the simplest to install, but larger than other packages that assume you already have Java and Eclipse. The Windows version comes as a setup program you run, and it produces a MyEclipse entry in your Start menu.

22 Common Steps

23 Add update sites Help – Software Updates – Available Software
Eclipse is configured with the URL of Web directories that contain updates to installed features and new features. CAS development requires the M2ECLIPSE Eclipse plugin for Maven 2 and a Subversion source repository client. You need to configure the URLs for these features. M2ECLIPSE is built into MyEclipse 7.0 M2 or later. For vanilla Eclipse WST, it comes from “ The Subversive code used to come from, but it has now been broken up into two distributions. The base support is now part of the Eclipse project itself and can be downloaded from [although the release number 0.7 may change] Polarion still distributes back end “providers” from a separate update site: Help – Software Updates – Available Software

24 Subversion Windows-only Native Java 1.5 HL 1.5 HL Win32 binaries
Polarion Subversive SVN Connectors Eclipse Subversion Team Provider Unix or Windows SVNKit 1.2.0 In concept, the Subversion Team Provider that the Eclipse project took over could use any external or plug-in SVN connector. The SVN connectors provided by Polarion have a common required code base, and then alternative optional connector packages. In Windows you can choose to use the JavaHL code which comes in two pieces, a native Java piece and Win32 Binary programs. In other operating systems you choose the pure Java “SVNKit”. If you install both on a Windows box, then the Eclipse preferences (Window – Preferences – Team – SVN – SVN Connector) lets you choose which of the two to use. Unless you have some reason to use the Native binaries, it is simpler to select SVNKit in all operating systems and have Pure Java everywhere.

25 SVN Repository Exploring
Menu sequence: Window – Open Perspective – Other – SVN Repository Exploring Right click in the SVN Repositories area and create a new repository. the URL is “ If you did not install all the pieces of the Polarion package required by your OS, the attempt to contact the library will fail and you will get an error message that will suggest you go back an pick up all the pieces.

26 Checkout JA-SIG source repository looks like a tree of projects
Select the trunk or a tagged release and check out as a Java (SE) project The JA-SIG SVN source repository appears as a tree of projects. Under CAS3 you can select the “trunk” (the currently active development code) or one of the tagged releases. Right click on Trunk or a Release and select Check out as … Although you will eventually be building a Servlet application, the project you are checking out will be an ordinary Java SE library application. From Eclipse’s point of view, it will be a bunch of source directories that create a JAR file.

27 Update Dependencies When you check the project out with subversion, the M2Eclipse code that you added to WST or that comes built into MyEclipse 7.0 M2 (or later) scanned the Eclipse project configuration and the POM files. It may or may not have followed up to download all the external dependent JAR files. You will know if this was done because downloading all these files takes about 40 minutes and there is a listing with each file as it is downloaded. If checking out does not download the libraries automatically, right click the project in Project Explorer, and select Maven (or Maven4MyEcipse) and select Update Dependencies from the submenu.

28 Maven: cas-server-core is a “project” Eclipse: cas-server-core/src/main/java is a “src dir”
From the Maven point of view, each subdirectory of the Eclipse Workspace project is a Maven subproject. Each subproject has a standard directory structure with source files in src/main/java and JUnit tests in src/test/java. Maven knows how to compile and test projects with this structure, and the POM file tells Maven what JAR file to build. Eclipse sees this same directory structure different. Eclipse can have subprojects, but that is not how this directory tree is configured. Instead, Eclipse is configured to see each {subproject}/src/main/java directory as what Eclipse thinks of as a Java source directory. Each configured Java source directory has a target output directory where the compiler stores the *.class files generated from the *.java source. Anything that isn’t a *.java source file is copied from the source to the target output directory as a “resource” (data file). Maven turns each subproject into a JAR file. Eclipse is configured to compile all the source files and dump them as individual *.class files in a common output directory. If you want, you could separate out the actual production CAS server files from the JUnit tests by reconfiguring the test output directory. Since Eclipse has been configured to know that cas-server-core/src/main/java is a special “source” directory, it has to know what to do with all the other directories in the cas-server-source tree. In the Project Explorer window of the Eclipse perspective, pieces of the same directory can be listed more than one time. First Eclipse lists all the configured source subdirectories, then it goes back and lists all the other non- source directories in the project.

29 Build Path (GUI to .classpath)
The “.classpath” file in the top project directory configures what the Eclipse UI calls the “Build Path”. The “Source” tab defines which directories in the project are to be regarded as containing Java source files or “resources”. In Java, a “resource” is a data file that is stored in the classpath and is located and loaded through standard library routines. Java source files are compiled and the generated *.class file is placed in the output directory. Any non-Java source file is simply copied over as is (typically these are .properties, .xml, .jpg, or other types of data used internally by the application). There is a default output folder (at the bottom) and each individual source file can have its own output folder. Because the JA-SIG Eclipse project expects that Eclipse will only be used for editing and Maven will be used to compile and deploy, the configured output folder (target/classes in this example) is just a dummy location that is not used for anything. If you use Ganymede WTP, this output directory will be the location from which the runtime Magic ClassLoaded picks up *.class files as the Web application executes. If you use MyEclipse, then the output directory must be changed to point to the WEB- INF/classes subdirectory of whatever directory you create to hold the Web application contents.

30 Build Path (GUI to .classpath)
The “Libraries” tab defines the JAR libraries needed to compile the Java source and/or to run the Web application. Some JAR files are combined in packages, while others are defined individually. Packages come from several sources: Every Java runtime (JRE) has a bunch of “standard” JAR files in its /lib directory. Eclipse finds your default JRE when it first runs, but you can configure other JREs that represent other Java releases (1.4, 5, 6, …). This becomes the JAR files in the JRE System Library. The external dependency modules listed in the POM files are identified by the M2Eclipse plugin, which packages them together in the Maven Dependencies group. The libraries in this group have all been downloaded by the Maven support and placed in the Maven 2 repository in your home directory. The checked out CAS source project is a Java SE library project, so it doesn’t initially have any J2EE libraries (except for the Servlet 2.4 JAR that Maven dragged in). A dynamic Web application project, however, has a package of EE libraries. The vanilla Ganymede WTP support obtains these JAR files from the library subdirectory of the Application Server you associated with the project when you created it. MyEclipse, however, has some pre-built named packages of generic J2EE 1.4 and J2EE 5 libraries (though it can also supply the library of a particular configured external server). MyEclipse is better because, if you use one of the named generic packages, you can build an application that uses all but only the APIs that are part of the EE standard and not accidentally become dependent on something that is only in Tomcat or JBoss.

31 Package Explorer - Libraries
The libraries configured in the Build Path (.classpath) are also displayed in the more prominent Project Explorer window as if they were subdirectories of the project. From this list you can not only open the folder, but also open the JAR file and see its packages and classes. This can be helpful if you are having trouble finding a class that is supposed to be automatically part of the classpath.

32 WST in Ganymede EE First, consider the steps to use the free open source Eclipse WST project as packaged in the Ganymede EE distribution.

33 WST New Dynamic Web Project
The vanilla Ganymede WST cannot add Dynamic Web capability to an existing project, so you have to create a new project (and a new Workspace subdirectory) of type Dynamic Web Project.

34 New Dynamic Web Project Wizard
You give the new project a name, which becomes the name of the subdirectory of the Eclipse Workspace. Here you might use the name “cas”, or “casx” if you prefer. The dynamic Web project is associated with a previously configured external Application Server, which is Tomcat 6 in this example.

35 In the second Wizard page, you select a context name for the application when it runs on the Server, and you select a name for the project subdirectory that will hold the HTML, JSP, CSS, and other files and will contain the WEB-INF directory. The name of the Java source directory doesn’t matter because this project has no Java source.

36 Cut and Paste Copy (cut and paste) the Web application files (cas-server-webapp/src/main/webapp/*) from the CAS source project to the WebContent directory of the new dynamic Web project Click OK to replace the generated web.xml file in WEB-INF Now copy over all the Web pages, stylesheets, property files, and the Spring configuration XML from the webapp subproject of the JA-SIG source project and put it in the directory you configured as the WebContent directory in the second Wizard page of project creation.

37 WST Java EE Module Dependencies
Right click on the new project in Project Explorer and select Properties. The Java EE Module Dependencies option allow you to specify other Java projects in the Workspace that can be regarded as “library module projects” providing classes used when the Web application executes. Select the name given to the CAS3 source previously checked out. Now it is as if all the class files produced by the CAS project were virtually copied to the WEB-INF/classes (although they don’t actually move).

38 Get the POM dependencies
“cd” to Workspace, CAS source project directory run “mvn install” command Refresh the Eclipse view of the project. Go to cas-server-webapp/target/cas-server-webapp-3.3/WEB-INF/lib Copy all the external JAR files (exclude the cas-server-*.jar files) to the WEB-INF/lib of the new dynamic Web project The M2Eclipse plugin adds the external dependencies listed in the POM to the Build Path for CAS compiles, but the WST (and its Magic ClassLoader) doesn’t recognize this list of JAR files at runtime. The only way to make these JAR files available during debugging is to physically copy them to the WEB-INF/lib directory of the dynamic Web project. The easiest way to get all these JAR files in one place to copy is to run a real Maven build. Unfortunately, running Maven under Eclipse generates a Maven plugin configuration error message for the Clover plugin. So either you have to delete the Clover plugin configuration from the main POM, or else you have to run Maven from the command line outside Eclipse. Note that Maven not only consolidates all the external JAR dependencies, but it also adds the JAR “artifacts” built during the compile step of each optional project listed as a dependency in the webapp subproject POM. Since those class files were just picked up by the Java EE Module Dependency step, it is a bad idea to have two copies of the same classes one of which becomes stale. So exclude the cas-server-*.jar files from the list of files copied here. If you run Maven outside Eclipse, Eclipse will not notice the new files that have been added to WEB-INF/lib unless you tell it to scan for external changes by selecting Refresh from the right click menu for the project.

39 Validation WST has validators for HTML, XML, etc.
Some CAS source files fail validation (headers, footers, etc.) In WST, only option is to disable validation for the entire project. WST has syntax validators that scan certain types of files for errors. Unfortunately, some CAS source files use JSP “include” capability to reference header and footer files. The header may have a <body> without an end, while the footer may have a </body> without the start. MyEclipse allows you to ignore certain files and directories for validation, but leave validation on for the rest of the project. WST doesn’t have this capability. So the only option is to live with the error messages, or turn off validation for the entire project.

40 MyEclipse

41 Add Web Project Capabilities to existing CAS project
MyEclipse can add J2EE Web project capability to an existing ordinary Java project. This makes things simpler, but it converts the Eclipse project into one that will only run with the MyEclipse extensions.

42 MyEclipse Wizard The MyEclipse Wizard does not associate the dynamic Web project with any particular server. That will be done later. Instead, it selects a generic package of JAR libraries that correspond to a level of the J2EE standard. The default J2EE 1.4 is the best choice for CAS. You define a directory (inside the CAS source project) that will contain the Web content. This example choses the same “/WebContent” directory name as the WST default. The difference is that in WST, the WebContent directory was in another project subdirectory of the Workspace, while in MyEclipse the WebContent directory is a newly created directory in the same project that contains all the Maven subprojects and CAS source directories. You might be tempted to use the cas-server-webapp directory that already contains all the Web files, but that is not a good idea. MyEclipse intends to use the WEB- INF/classes directory as scratch space, while in cas-server-webapp the corresponding directory contains properties files that must be preserved.

43 Adding Web capabilities
MyEclipse changes the default compiler output directory to WebContent/WEB-INF/classes MyEclipse adds its editors and syntax filters to the project MyEclipse adds the J2EE (1.4 or 5) package of libraries to the compiler classpath There are now HTML and XML files with “errors”. [Right click the directories, select MyEclipse, Exclude from Validation] Because you added MyEclipse Web Project capabilities to what was previously a vanilla Eclipse Java project, MyEclipse adds its extra stuff to the project configuration. It changes the default output directory so that now source directories compile into WebContent/WEB-INF/classes. This is a good thing for “core” and all the optional projects you intend to use. Later on you may want to delete the source directory designation for the options you don’t want to use, and you may want to change the JUnit source directories to store their classes someplace else. MyEclipse adds its editors and syntax scanners to the project. The good news is that you now have some native XML editing ability and an editor that understands Spring configuration files. The bad news is that there are some XML files and HTML fragments that are not well formed. So when the rebuild completes, there will be some new errors associated with header and footer files and some XML problems. The solution will be to right click on the directories with “bad syntax” XML files and select the MyEclipse menu option to exclude those directories from syntax validation. MyEclipse now adds its own J2EE library package.

44 J2EE 1.4 Libraries MyEclipse has built in libraries for the Interfaces whose implementation must be provided by a J2EE container at any configurable level of the J2EE standard. Since you chose the 1.4 button when adding the Web project capability, it added the package of API Interface libraries associated with the 1.4 standard. For CAS, the only important contribution is the javax.servlet stuff. Tomcat will only implement a subset of the J2EE standard. Each real J2EE container will have its own implementation classes for each service. However, they all share the same Interface definitions, so code compiled with this set of libraries will work under JBoss, Geronimo, or Glassfish. It will also work under Tomcat if you have the common sense to just use the Servlet stuff and don’t try to use an EJB interface. These interfaces reflect stuff that a J2EE container supplies itself and that don’t need implementations in the WEB-INF/lib part of the WAR file. This is why you don’t want to select the J2EE 5.0 button when you configure the WebContent unless you are sure that you will install CAS in a real J2EE 5 server or promise you won’t use JSF or JPA or any of the other Java interfaces that were added to the J2EE 5 standard but are not provided by Tomcat or a J2EE 1.4 server.

45 Sanity Check cas-server-webapp WebContent
will be used as the source for Maven should reflect your production environment (probably on another host) is associated through SVN to the ja-sig source WebContent used by Eclipse (tell SVN to ignore it) reflects your local test Tomcat environment Normally having two copies of the same file is a bad idea. However, these particular files (especially the Spring XML configuration files and properties files) are rather specific to a particular deployment or test environment. In the real world, you typically need at least four copies of these files: The WebContent we have just created will contain files that are deployed to Tomcat or another Web Server on your personal machine for local compile and debug development. Once you have something that works, you will probably use Maven 2 to run all the tests and build a version that you can deploy on your integration test server. If that works, you may have an different directory for the configuration you deploy to your production CAS server. Eventually, if you are going to commit changes back to ja-sig, you need a version that corresponds to the ja-sig SVN repository and not to any local test or production configuration. So maybe having at least two directories in you Eclipse Workspace is not really so bad.

46 WEB-INF/classes Source directories are compiled and classes are stored here Data files (resources) are copied here add “cas-server-webapp/src/main/webapp/ WEB-INF/classes” as a MyEclipse “source” directory to get *.properties files Put JUnit class files someplace else (/test-bin) When you create the WebContent directory and add Web project capabilities to the MyEclipse project, the output directory in the Build Path is changed to its WEB- INF/classes. MyEclipse expects the Java source to compile into this directory so that the WebContent subdirectory is an exact image of a deployable WAR. Non-Java files in any source directory are copied to the output directory as “resources”. In particular, there is one block of resource files in cas-server- webapps/src/main/webapp/WEB-INF/classes. These are the *.properties files need by CAS. You might try to copy them over to the WebContent directory, but they will be deleted whenever a Clean build is triggered by MyEclipse. So the safe thing is to define that directory as a MyEclipse “source” directory in the Java Build Path. It doesn’t actually have any Java source, but then the contents of the directory are copied to WebContent/WEB-INF/classes as part of every clean build.

47 In WST the Application Server has to be defined before the dynamic Web application project is created. In MyEclipse it can be defined any time.

48 Select one or more J2EE App Servers
A MyEclipse EE project can be associated with one or more external Application Servers. The WebContent directory is deployed to each configured Application Server. After initial deployment, individual files are copied as they are changed. Exploded deployments are changed “on the fly” after save and compile.

49 Application Server Buttons
Run Application Server (Tomcat) Manually redeploy When you define an Application Server deployment, MyEclipse copies all the files for the Web Application, including all the dependency JAR files, to the deployment directory for that type of server. Whenever you edit and save source, the changed Java .class file (or HTML, JSP, XML, or .properties file) is copied to the active deployed application servers. However, a few changes require a complete redeployment. If, for example, you add a new JAR file to the Build Path Libraries, then you have to click the Deployment button and manually redeploy the entire project. MyEclipse will start and stop the Application Server for you using the Run Server button. Application Servers run in the background under the control of Eclipse, but you decide when to start or stop them. MyEclipse runs each server under its configured JDK environment, and runs it in Debug mode so you can set breakpoints, view variables, and step through the code.

50 Start the Server Start the Application Server (Tomcat) if all the dependency libraries were added to the Build Path, it will initialize without problems. Run a Browser and you should be able to run the usual CAS 3 initial test (where the userid and password equal each other). You are now prepared to develop.

Download ppt "Developing CAS in Eclipse"

Similar presentations

Ads by Google