Hitachi

Hitachi Application Server V10 User's Guide (For Windows® Systems)


7.5.4 Creating an application archive

To create an application archive, you have to edit the build file (build.xml) to build the Eclipse project. Edit the build file as appropriate to the type of project. This subsection describes how to create an archive for the EJB project, the dynamic web project, and the enterprise application project as examples.

Prerequisites

Intended users

Procedure

  1. From the Project Explorer view, select the project to which to add build.xml, and then from the context menu, select New > File.

    The New File dialog box appears.

  2. With the project to which to add build.xml selected, enter build.xml in the File name: field, and then click the Finish button.

    build.xml is added to the selected project.

    Reference note

    In Step 3 and the following steps in this build file example, -DHJAVAEE_HOME=installation-directory-for-Application-Server-for-Developers is specified for "VM parameter" when executing the build file.

  3. Include the following statements in the build file for the EJB project:

    Line

    Example of statement

    Description

    1

    <?xml version="1.0" encoding="UTF-8"?>

    This is the XML declaration.

    2

    <project name="Bank_EJB" default="create" basedir="./">

    Specifies the root of the build file.

    3

    <property name="classPath" value="${HJAVAEE_HOME}/javaee/glassfish/lib/javaee.jar"/>

    Specifies, in the property, the path to the Java EE library of Application Server.

    4

    <property name="ejbArchiveName" value="Bank_EJB.jar"/>

    Adds, to the property, the specification of the archive file name to be generated by the EJB project.

    5

    <property name="javacPath" value="${HJAVAEE_HOME}/jdk/bin/javac.exe"/>

    Specifies, in the property, the path to the javac command of Application Server.

    6

    <property name="tempFolder" value="ant"/>

    Specifies, in the property, the name of the temporary directory to be used for the build process. Any name can be specified for this directory.

    7

    <target name="create">

    This is the start tag for the create target.

    8

    <delete file="./${ejbArchiveName}"/>

    Deletes the existing archive file.

    9

    <mkdir dir="./${tempFolder}"/>

    Creates a temporary directory for the build process.

    10

    <copy todir="./${tempFolder}">

    Copies the file to be included in the archive to the temporary directory for the build process.

    11

    <fileset dir="./ejbModule" excludes="**/*.java"/>

    Excludes Java source code from the copy targets.

    12

    </copy>

    This is the end tag for the copy task in the 10th line.

    13

    <javac srcdir="./ejbModule" destdir="./${tempFolder}" executable="${javacPath}" classpath="${classPath}"/>

    Compiles the Java source code. The javac command of Application Server is used for compilation.

    14

    <jar destfile="./${ejbArchiveName}" basedir="./${tempFolder}"/>

    Archives the folders and files located under the temporary directory for the build process and then generates a jar file.

    15

    <delete dir="./${tempFolder}"/>

    Deletes the temporary directory for the build process.

    16

    </target>

    This is the end tag for the create target in the 7th line.

    17

    </project>

    This is the end tag for the build file.

  4. Execute the build file for the EJB project.

    The EJB-JAR file is generated.

  5. Include the following statements in the build file for the dynamic web project:

    Line

    Example of statement

    Description

    1

    <?xml version="1.0" encoding="UTF-8"?>

    This is the XML declaration.

    2

    <project name="Bank_Web" default="create" basedir="./">

    Specifies the root of the build file.

    3

    <property name="jspcdir" value="${HJAVAEE_HOME}/javaee/glassfish/bin"/>

    Specifies, in the property, the path to the JSP pre-compile command of Application Server.

    4

    <property name="ejbJarPath" value="../Bank_EJB/Bank_EJB.jar"/>

    Specifies, in the property, the path to the EJB project's archive.

    5

    <property name="classPath" value="${HJAVAEE_HOME}/javaee/glassfish/lib/javaee.jar;${ejbJarPath}"/>

    Specifies, in the property, the path to the J2EE library of Application Server as well as the path to the EJB project's archive.

    6

    <property name="javacPath" value="${HJAVAEE_HOME}/jdk/bin/javac.exe"/>

    Specifies, in the property, the path to the javac command of Application Server.

    7

    <property name="tempFolder" value="ant"/>

    Specifies, in the property, the name of the temporary directory to be used for the build process. Any name can be specified for this directory.

    8

    <property name="webArchiveName" value="Bank_Web.war"/>

    Specifies, in the property, the archive file name to be generated by the dynamic web project.

    9

    <property name="webRoot" value="WebContent"/>

    Specifies, in the property, the root of the dynamic web project.

    10

    <target name="compile">

    This is the start tag for the compile target for JSP pre-compilation.

    11

    <exec executable="${jspcdir}/jspc.bat" newenvironment="true">

    Executes Application Server's command for JSP pre-compilation.

    12

    <arg line='-classpath ${ejbJarPath}'/>

    If the class of the EJB project is to be referenced during JSP pre-compilation, use this statement to specify EJB project's classpath.

    13

    <argline='-webapp"./${tempFolder}"'/>

    Specifies the root path of the application for the command parameter.

    14

    <argline='-v'/>

    Specifies the detailed information output during JSP compilation for the command parameter.

    15

    <argline='-compile'/>

    Specifies class file creation for the command parameter.

    16

    <argline='-d"./${tempFolder}/WEB-INF/classes"'/>

    Specifies the directory path for outputting the JSP compilation results for the command parameter.

    17

    </exec>

    This is the end tag for command execution in the 11th line.

    18

    </target>

    This is the end tag for the compile target in the 10th line.

    19

    <target name="create">

    Specifies the root of the create target.

    20

    <delete file="./${webArchiveName}"/>

    Deletes the existing archive file.

    21

    <mkdir dir="./${tempFolder}"/>

    Creates a temporary directory for the build process.

    22

    <copy todir="./${tempFolder}">

    Copies the files to be included in the archive to the temporary directory.

    23

    <fileset dir="./${webRoot}" excludes="**/classes/**/*.class"/>

    Excludes Java classes from the copy targets.

    24

    </copy>

    This is the end tag for the copy task in the 22nd line.

    25

    <mkdir dir="./${tempFolder}/WEB-INF/classes"/>

    Creates the output directory for the JSP compilation results.

    26

    <javac srcdir="./src" destdir="./${tempFolder}/WEB-INF/classes" executable="${javacPath}" classpath="${classPath}"/>

    Compiles the Java source code. The javac command of Application Server is used for compilation.

    27

    <antcall target="compile"/>

    Calls up the compile target for JSP pre-compilation. Do not use this statement when JSP pre-compilation is not to be performed.

    28

    <war destfile="./${webArchiveName}" basedir="./${tempFolder}" webxml="./${tempFolder}/WEB-INF/web.xml" excludes="WEB-INF/web.xml"/>

    Archives the directories and files located under the temporary directory and then generates a WAR file.

    29

    <delete dir="./${tempFolder}"/>

    Deletes the temporary directory.

    30

    </target>

    This is the end tag for the create target in the 19th line.

    31

    </project>

    This is the end tag for the build file.

  6. Execute the build file for the dynamic web project.

    The WAR file is generated.

  7. Include the following statements in the build file for the enterprise application project:

    Line

    Example of statement

    Description

    1

    <?xml version="1.0" encoding="UTF-8"?>

    This is the XML declaration.

    2

    <project name="Bank" default="create" basedir="./">

    Specifies the root of the build file.

    3

    <property name="earArchiveName" value="Bank.ear"/>

    Specifies, in the property, the archive file name to be generated by the enterprise application project.

    4

    <property name="ejbArchiveName" value="Bank_EJB.jar"/>

    Specifies, in the property, the archive file name to be generated by the EJB project.

    5

    <property name="ejbProjectName" value="Bank_EJB"/>

    Specifies, in the property, the name of the EJB project.

    6

    <property name="webArchiveName" value="Bank_Web.war"/>

    Specifies, in the property, the archive file name to be generated by the dynamic web project.

    7

    <property name="webProjectName" value="Bank_Web"/>

    Specifies, in the property, the name of the dynamic web project.

    8

    <property name="excludes" value=".classpath, .mymetadata, .project, build-user.xml"/>

    Specifies, in the property, the file to be excluded during the generation of EAR files.

    9

    <target name="create">

    This is the start tag for the create target.

    10

    <ant antfile="../${ejbProjectName}/build.xml" dir="../${ejbProjectName}" inheritall="false"/>

    Execute the build file for the EJB project.

    11

    <ant antfile="../${webProjectName}/build.xml" dir="../${webProjectName}" inheritall="false"/>

    Execute the build file for the dynamic web project.

    12

    <delete file="./${earArchiveName}"/>

    Deletes the existing archive file.

    13

    <ear destfile="./${earArchiveName}" basedir="./" appxml="./EarContent/META-INF/application.xml"excludes="${excludes}">

    Generates the EAR file.

    14

    <fileset file="../${ejbProjectName}/${ejbArchiveName}"/>

    Specifies the EJB-JAR file to be included in the EAR file.

    15

    <fileset file="../${webProjectName}/${webArchiveName}"/>

    Specifies the WAR file to be included in the EAR file.

    16

    </ear>

    This is the end tag for the ear task in the 13th line.

    17

    </target>

    This is the end tag for the create target in the 9th line.

    18

    </project>

    This is the end tag for the build file.

  8. Execute the build file for the enterprise application project.

    After the enterprise application project is built, the EJB project, the dynamic web project, and the enterprise application project are built in that order, and the EAR file containing both the EJB-JAR file and the WAR file is generated.

  9. Using the Administration Console's Deploy Application window, import the created archive file to the execution environment.

    The developed applications are deployed to the execution environment.