Title: Starting JBoss from ANT

Hi,
I had posted a message earlier about running JUnit tests inside the same VM as JBoss so as to enable the testing of local interfaces and I did get a few responses back. Thanks everyone!

Now one of the most common response was to start Jboss environment from within my tests.Hence i started by adding the following lines in my build.xml to start JBoss server

.
   <!-- =================================================================== -->
   <!-- Starts up JBoss                                                     -->
   <!-- =================================================================== -->
  
     <target name="runjboss" depends="init">
          <exec dir = "${jboss.home}/bin"
         executable = "${jboss.home}/bin/run.bat"
           os = "Windows 2000">
          </exec>   
    </target>

However, now it starts JBoss but then does not execute any tasks after this one as JBoss just holds on to the VM. Exec task does not support the FORK option either, but in any case I do not wish to use the fork option as it will beat the whole purpose of running the tests inside the same JVM as JBoss. Does anyone has any idea how to get around this problem?

P.S I know Cactus is one of the way out but at the moment, my project team is not too keen on trialling out another new tool and Junit would be the easiest way for our implementation.

In short I would apprecate if anyone has already done this and could give me specific directions or advise me on how to run the JUnit tests inside the same VM as JBoss so that I can test my local interfaces as well!

Also attached is my build.xml file for anyone who wants to investigate this further,

Thanks a lot in advance,

Cheers
Dushy
______________________
DUSHYANT SHRIVASTAVA
Software Engineer

YAMBAY

tel      +61 (0) 8 9323 6999
mob  +61 (0) 402 902 652
fax     +61 (0) 8 9325 2688
web   www.yambay.com


Yambay Technologies Pty Ltd
7th Floor, The Victoria, 14-16 Victoria Ave, Perth. WA, 6000, Australia
_________________________________________________________________________________________________

This message and any files transmitted with it are confidential and are intended solely for the use of those persons to
whom the message is addressed. If you have received this message in error, please destroy and delete this
message from your computer. Any unauthorised form of reproduction of this message or any files transmitted with
it is strictly prohibited. yambay does not make any warranty concerning the security of any information electronically
transmitted and disclaims all liability for the proper and complete transmission of any information contained or purportedly
contained in this message, nor for any delay in its receipt. If you receive this message in error please notify the sender.
_________________________________________________________________________________________________

<<build.xml>>

<?xml version="1.0"?>

<!-- ======================================================================= -->
<!-- Template build file                                                     -->
<!-- ======================================================================= -->

<project name="ejbtest" default="mail" basedir=".">
   
  <!-- =================================================================== -->
   <!-- CHECK THAT JAVA/J2EE ENVIRONMENT IS CORRECTLY CONFIGURED                                                                      -->
   <!-- =================================================================== -->

   <!--
      Give user a chance to override without editing this file
      (and without typing -D each time they run it)
   -->
   <property file=".ant.properties" />
   <property environment="env"/>
   <property name="jboss.home" 		value="${env.JBOSS_HOME}"/>
   <property name="xdoclet.home" 	value="${env.XDOCLET_HOME}"/>
   <property name="ant.home" 		value="${env.ANT_HOME}"/>
   <property name="junit.home" 		value="${env.JUNIT_HOME}"/>
   <property name="project.libs" 	value="${basedir}/../../Libs"/>


   <property name="version" value="1.1"/>


   <target name="check-environment">
      <antcall 	    target   ="check-jboss"/>
      <available    property ="jboss.present" file="${jboss.home}/bin/run.jar"/>
      <antcall 	    target   ="wrong-jboss"/>
      <antcall 	    target   ="check-xdoclet"/>
      <available    property ="xdoclet.present" file="${xdoclet.home}/lib/xdoclet.jar"/>
      <antcall      target   ="wrong-xdoclet"/>
   </target>

   <target name="check-jboss" unless="jboss.home">
      <fail>
         Property "jboss.home" is not set. Please use the file
         "ant.properties" in this directory ${basedir} to
         set this property. It must point to the directory which
         contains the following directory: "deploy", "conf", "tmp"
         etc.
      </fail>
   </target>

   <target name="wrong-jboss" unless="jboss.present">
      <fail>
         Property "jboss.home" is set but it does not seem
         to point to the right directory. The file "run.jar"
         must be available at ${jboss.home}/bin.
      </fail>
   </target>

   <target name="check-xdoclet" unless="xdoclet.home">
      <fail>
         Property "xdoclet.home" is not set. Please use the file
         "ant.properties" in this directory ${basedir} to
         set this property. It must point to the root directory of
         XDoclet distribution.
      </fail>
   </target>

   <target name="wrong-xdoclet" unless="xdoclet.present">
      <fail>
         Property "xdoclet.home" is set but it does not seem
         to point to the right directory. The file "xdoclet.jar"
         must be available at ${xdoclet.home}/lib.
      </fail>
   </target>

   <!-- ======================================================================= -->


   <!-- =================== INITIALISE VARIABLES (PATHS ETC) ================== -->
   <!--                                                                         -->
   <!-- ======================================================================= -->

   <target name="init" depends="check-environment">
      <echo message="basedir = ${basedir}"/>
      <echo message="project.libs = ${project.libs}"/>
      <echo message="user.home = ${user.home}"/>
      <echo message="java.home = ${java.home}"/>
      <echo message="ant.home = ${ant.home}"/>
      <echo message="jboss.home = ${jboss.home}"/>
      <echo message="xdoclet.home = ${xdoclet.home}"/>
      <echo message="junit.home = ${junit.home}"/>
      <echo message="remote.jboss.deploy = ${remote.jboss.deploy}"/>      
      <echo message="java.class.path = ${java.class.path}"/>
      <echo message="ejb-jar.includes = ${ejb-jar.includes}"/>
      <echo message=""/>


      <available property="jdk1.3+" classname="java.lang.StrictMath" />
   </target>

   <property name="jboss.lib"             value="${jboss.home}/lib" />
   <property name="jboss.client"          value="${jboss.home}/client" />
   <property name="jboss.deploy"          value="${jboss.home}/server/${jboss.configuration}/deploy" />
   <property name="servlet-lib.path"	  value="${jboss.home}/server/${jboss.configuration}/lib/javax.servlet.jar"/>

   <property name="test.dir"              value="${basedir}/test"/>
   <property name="test.main.dir"         value="${test.dir}/main/"/>

   <property name="test.client.dir"       value="${test.main.dir}/client"/>
   <property name="test.ejb.dir"          value="${test.main.dir}/ejb"/>
   
   <property name="reports" 			  value="${basedir}/reports"/>
   
   <property name="src.etc.dir"           value="${src.dir}/etc"/>
   <property name="build.dir"             value="${basedir}/build"/>
   <property name="build.deploy.dir"      value="${build.dir}/deploy"/>
   <property name="build.generate.dir"    value="${build.dir}/generate"/>
   <property name="build.classes.dir"     value="${build.dir}/classes"/>
   <property name="build.war.dir"         value="${build.dir}/war"/>
   <property name="build.client.dir"      value="${build.dir}/client"/>
   <property name="build.bin.dir"         value="${build.dir}/bin"/>
   <property name="build.javadocs.dir"    value="${build.dir}/docs/api"/>


   <path id="xdoclet.path">
      <pathelement location="${ant.home}/lib/ant.jar" />
      <pathelement location="${ant.home}/lib/optional.jar" />
<!-- AS Maybe necessary for Ant 1.5 and XDoclet 1.3
      <pathelement location="${ant.home}/lib/xmlParserAPIs.jar" />
      <pathelement location="${ant.home}/lib/xercesImpl.jar" />
      <pathelement location="${ant.home}/lib/bcel.jar" />
      <pathelement location="${xdoclet.home}/lib/xjavadoc.jar" />
-->
      <pathelement location="${xdoclet.home}/lib/xdoclet.jar" />
      <pathelement location="${jboss.client}/log4j.jar" />
   </path>

   <path id="base.path">
      <path refid="xdoclet.path"/>
      <pathelement location="${jboss.client}/jboss-j2ee.jar" />
      <pathelement location="${jboss.client}/jnp-client.jar" />
      <pathelement location="${jboss.client}/jbossmq-client.jar" />
      <pathelement location="${jboss.client}/jbosssx-client.jar" />
      <pathelement location="${jboss.client}/concurrent.jar" />
      <pathelement location="${jboss.client}/jaas.jar" />
      <pathelement location="${jboss.lib}/jboss-jmx.jar" />
      <pathelement location="${jboss.lib}/jboss-system.jar" />
      <pathelement location="${jboss.home}/server/${jboss.configuration}/lib/jbosssx.jar" />
      <pathelement location="${jboss.home}/server/${jboss.configuration}/lib/mail.jar" />
	<pathelement location="${jboss.home}/server/${jboss.configuration}/lib/j2ee.jar" />

      <pathelement location="${build.classes.dir}" />
      <pathelement location="${junit.home}/junit.jar" />
      <pathelement location="/MACH/jacob.jar" />
      <pathelement location="${ant.home}/lib/optional.jar" />
         
     <fileset dir="${project.libs}">
        <include name="**/*.jar"/>
     </fileset>
               
   </path>
   
   <!-- =================================================================== -->
   <!-- Starts up JBoss                                                     -->
   <!-- =================================================================== -->
   
     <target name="runjboss" depends="init">
  	  <exec dir = "${jboss.home}/bin" 
         executable = "${jboss.home}/bin/run.bat"
	   os = "Windows 2000">
	  </exec>    
    </target>

    
   <!-- =================================================================== -->
   <!-- Compiles the source code                                            -->
   <!-- =================================================================== -->
   
     <target name="compile" depends="runjboss">
      <mkdir dir="${build.classes.dir}"/>
  
      <javac
         destdir="${build.classes.dir}"
         debug="on"
fork = "yes"
         deprecation="off"
         optimize="on"
         classpathref="base.path">
         <src path="${test.main.dir}"/>
         
      </javac>
    </target>

   <!-- =================================================================== -->
   <!-- Creates the jar archives                                            -->
   <!-- =================================================================== -->
   
   <target name="jar" depends="compile">
      <mkdir dir="${build.deploy.dir}"/>
      <mkdir dir="${build.bin.dir}"/>
      <jar
         jarfile="${build.deploy.dir}/${Name}.jar">
         <fileset
            dir="${build.classes.dir}"
            includes="com/yambay/nps/istesting/**">
         </fileset>
         <fileset
            dir="${build.dir}"
            includes="META-INF/**" >
         </fileset>
      </jar>
   </target>

   <!-- =================================================================== -->
   <!-- Creates the client binary                                           -->
   <!-- =================================================================== -->
   
   <target name="deploy-server" depends="jar">
      <copy todir="${jboss.deploy}">
         <fileset dir="${build.deploy.dir}" includes="*.jar">
         </fileset>
      </copy>
   </target>


   <!-- =================================================================== -->
   <!-- Runs the test			                                        -->
   <!-- =================================================================== -->
   

<target name="test" depends="jar, deploy-server">
   <mkdir dir="${reports}"/>
   <junit printsummary="true" >	

          <formatter type="xml" />
		<jvmarg value = "-Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory" />
		<jvmarg value = "-Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces"/>
		<jvmarg value = "-Djava.naming.provider.url=10.61.6.142"/>
		<jvmarg value = "-Djava.security.policy=C:/J2EE/jboss-3.0.0/server/default/conf/server.policy"/>

          <test  name="com.yambay.nps.istesting.MessagingTestCase" 
                    todir="${reports}" /> 

          <classpath>   
		   <pathelement location="/MACH/jacob.jar"/>

   		  <fileset dir="${ant.home}/lib">
                    <include name="**/*.jar"/>
              </fileset>


              <fileset dir="\junit\junit3.8.1">
                    <include name="**/*.jar"/>
              </fileset>
  
		  <fileset dir="${jboss.home}/client">
                    <include name="**/*.jar"/>
              </fileset>

              <fileset dir="${jboss.home}/server/default/deploy" >
                    <include name="**/*.jar"/>
              </fileset>

		  <fileset dir="${jboss.home}/server/default/lib" >
                    <include name="**/*.jar"/>
              </fileset>


	
          </classpath>

  </junit>
        <junitreport todir="${reports}">
          <fileset dir="${reports}">
             <include name="TEST-*.xml"/>
          </fileset>
          <report format="frames" todir="${reports}"/>
       </junitreport>
</target>

<!-- =================================================================== -->
<!-- Send mail out									 -->
<!-- =================================================================== -->

<target name="mail" depends="test, compile"> 
<taskdef name="mimemail" classname="org.apache.tools.ant.taskdefs.optional.net.MimeMail"/> 
<tstamp/> 
	<mimemail messageMimeType="text/html"
	          messageFile="${reports}/overview-summary.html" 
              tolist="[EMAIL PROTECTED]" 
              mailhost="pluto" 
              subject="JUnit Test Results: ${TODAY}" 
              from="[EMAIL PROTECTED]"> 
	<fileset dir="${reports}">
		   <include name="TESTS-*.xml"/>
 	</fileset> 
	</mimemail> 

</target> 


   <!-- =================================================================== -->
   <!-- Cleans up the current build                                         -->
   <!-- =================================================================== -->
   
   <target name="clean" depends="init">
      <delete dir="${build.dir}"/>
   </target>
   
   <!-- =================================================================== -->
   <!-- Copy deploy files to remote server                                  -->
   <!-- =================================================================== -->

   <target name="remote-deploy" depends="deploy-server">
      <copy todir="${remote.jboss.deploy}">
         <fileset dir="${build.deploy.dir}" includes="*.jar">
         </fileset>
      </copy>
   </target>

</project>



Reply via email to