SJSAS 8.1 and the "sun appserv deploy" Ant task

Afternoon all,

I'm currently trying to get cactus working with cruisecontrol as part of an automated build (we're developing in netbeans 5.0 & commiting to cvsnt). As part of this I need to use the sun-appserv-deploy and sun-appserv-undeploy ant tasks to start/stop the server automatically for the running of unit tests.

My biggest problem is I'm no guru with either Ant or the classpath :-/ The relevant part of my Ant build is as follows

<target name="sun-taskdef" depends="compile-test">

<taskdef name="sun-appserv-deploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

<pathelement location="${admin.cli.jar}" />

</classpath>

</taskdef>

<taskdef name="sun-appserv-undeploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.UndeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

<pathelement location="${admin.cli.jar}" />

</classpath>

</taskdef>

</target>

<target name="deploy-sun-test" depends="sun-taskdef">

<sun-appserv-deploy file="${dist.dir}\\test-cactus.war"

contextroot="/CactusTest"

name="CactusTestWAR"

force="true"

precompilejsp="false"

verify="false"

upload="true"

user="admin"

passwordfile="powertec"

host="localhost"

port="4848"

asinstalldir="C:/Sun/AppServer" />

</target>

<target name="undeploy-sun-test">

<sun-appserv-undeploy name="CactusTestWAR"

user="admin"

passwordfile="powertec"

host="localhost"

port="4848" />

</target>

<target name="test" depends="default,sun-taskdef">

<cactifywar destfile="${dist.dir}\\test-cactus.war" srcfile="${dist.dir}\\CactusTest.war" />

<delete file="*.cactus.log"/>

<cactus haltonfailure="yes" showoutput="yes" printsummary="on" warfile="${dist.dir}\\test-cactus.war">

<cactusproperty server="false" propertiesFile="src//conf//cactus.client.log4j.properties"/>

<cactusproperty server="true" propertiesFile="src//conf//cactus.server.log4j.properties"/>

<classpath refid="classpath"/>

<containerset>

<generic name="Sun Appserver 8.1 Q2" port="8080">

<startup target="deploy-sun-test"/>

<shutdown target="undeploy-sun-test"/>

</generic>

</containerset>

</cactus>

<delete file="${dist.dir}\\test-cactus.war"/>

</target>

And the specific error I'm getting is :-

[sun-appserv-deploy] Executing: deploy --user admin --passwordfile"whatpassword?" --host localhost --port 4848 --force=true

--enabled=true --name CactusTestWAR --verify=false --precompilejsp=false --upload=true --contextroot /CactusTest"C:\Do

cuments and Settings\davidl\My Documents\J2EE projects\CactusTest\dist\test-cactus.war"

[cactus] Exiting C:\Documents and Settings\davidl\My Documents\J2EE projects\CactusTest\build.xml.

[cactus] Exception in thread"Thread-5" C:\Documents and Settings\davidl\My Documents\J2EE projects\CactusTest\build.

xml:68: The following error occurredwhile executingthis line:

[cactus] C:\Documents and Settings\davidl\My Documents\J2EE projects\CactusTest\build.xml:53: A Sun Java System Appli

cation Server 8 admin CLIclass could not be found (com.sun.enterprise.cli.framework.InputsAndOutputs). Use the asinsta

lldir attribute, set the asinstall.dir property, or add the appropriate JARs to the classpath.

[cactus]at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:539)

[cactus]at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:384)

[cactus]at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:107)

[cactus]at org.apache.cactus.integration.ant.container.GenericContainer$Hook.execute(GenericContainer.java:110)

[cactus]at org.apache.cactus.integration.ant.container.GenericContainer.startUp(GenericContainer.java:285)

[cactus]at org.apache.cactus.integration.ant.container.ContainerRunner$1.run(ContainerRunner.java:140)

[cactus]at java.lang.Thread.run(Thread.java:595)

[cactus] Caused by: C:\Documents and Settings\davidl\My Documents\J2EE projects\CactusTest\build.xml:53: A Sun Java S

ystem Application Server 8 admin CLIclass could not be found (com.sun.enterprise.cli.framework.InputsAndOutputs). Use

the asinstalldir attribute, set the asinstall.dir property, or add the appropriate JARs to the classpath.

[cactus]at org.apache.tools.ant.taskdefs.optional.sun.appserv.AppServerAdmin.execAdminCommand(AppServerAdmin.jav

a:514)

[cactus]at org.apache.tools.ant.taskdefs.optional.sun.appserv.ComponentAdmin.execute(ComponentAdmin.java:250)

[cactus]at org.apache.tools.ant.taskdefs.optional.sun.appserv.AppServerAdmin.execute(AppServerAdmin.java:404)

[cactus]at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)

[cactus]at org.apache.tools.ant.Task.perform(Task.java:364)

[cactus]at org.apache.tools.ant.Target.execute(Target.java:341)

[cactus]at org.apache.tools.ant.Target.performTasks(Target.java:369)

[cactus]at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)

[cactus]at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)

[cactus]at org.apache.tools.ant.Project.executeTargets(Project.java:1068)

[cactus]at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)

[cactus]... 5 more

[cactus] Nested Exception

[cactus] C:\Documents and Settings\davidl\My Documents\J2EE projects\CactusTest\build.xml:53: A Sun Java System Appli

cation Server 8 admin CLIclass could not be found (com.sun.enterprise.cli.framework.InputsAndOutputs). Use the asinsta

lldir attribute, set the asinstall.dir property, or add the appropriate JARs to the classpath.

[cactus]at org.apache.tools.ant.taskdefs.optional.sun.appserv.AppServerAdmin.execAdminCommand(AppServerAdmin.jav

a:514)

[cactus]at org.apache.tools.ant.taskdefs.optional.sun.appserv.ComponentAdmin.execute(ComponentAdmin.java:250)

[cactus]at org.apache.tools.ant.taskdefs.optional.sun.appserv.AppServerAdmin.execute(AppServerAdmin.java:404)

[cactus]at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)

[cactus]at org.apache.tools.ant.Task.perform(Task.java:364)

[cactus]at org.apache.tools.ant.Target.execute(Target.java:341)

[cactus]at org.apache.tools.ant.Target.performTasks(Target.java:369)

[cactus]at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)

[cactus]at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)

[cactus]at org.apache.tools.ant.Project.executeTargets(Project.java:1068)

[cactus]at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)

[cactus]at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:107)

[cactus]at org.apache.cactus.integration.ant.container.GenericContainer$Hook.execute(GenericContainer.java:110)

[cactus]at org.apache.cactus.integration.ant.container.GenericContainer.startUp(GenericContainer.java:285)

[cactus]at org.apache.cactus.integration.ant.container.ContainerRunner$1.run(ContainerRunner.java:140)

[cactus]at java.lang.Thread.run(Thread.java:595)

I can see that I need to either set asinstalldir in the task, set the asinstall.dir property or make sure the relevant jar's are the classpath and obviously I'm trying to get the correct jar's into the classpath (having unsuccessfully tried the previous two options, even with hard-coded values).

I've also read that it is preferrable to use asant to call these ant tasks, but this is an option I do not have as I am constrained to using normal ant with cruisecontrol.

Any help or advice anyone can provide would be greatly appreciated as I'm proper banging my head against a brickwall here and there's sod all on t'internet from what I can find ;-(

Cheers

Dave Lush

[10094 byte] By [DavidLush] at [2007-11-26 9:01:23]
# 1

Hi David,

I condensed your build file to one build.xml file and I didn't having any problem deploying an application:

Here's the build.xml file I have:

<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE project >

<project name="test-asant" >

<target name="sun-taskdef">

<taskdef name="sun-appserv-deploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

</classpath>

</taskdef>

<taskdef name="sun-appserv-undeploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.UndeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

</classpath>

</taskdef>

</target>

<target name="deploy-sun-test" depends="sun-taskdef">

<!--<target name="deploy-sun-test"> -->

<sun-appserv-deploy file="${fortune.ear}"

name="fortune"

force="true"

precompilejsp="false"

verify="false"

upload="true"

user="admin"

passwordfile="${password.txt}"

host="localhost"

port="5858"

asinstalldir="/export/home/as81pe/SUNWappserver" />

</target>

<target name="undeploy-sun-test" depends="sun-taskdef">

<sun-appserv-undeploy name="fortune"

user="admin"

passwordfile="${passwordfile.txt}"

host="localhost"

port="5858"

asinstalldir="/export/home/as81pe/SUNWappserver" />

</target>

</project>

I tried this on SJSAS8.1PE.

Can you try condensing your xml files to one build.xml file and see if you still see the same error?

Please let me know.

Jane

janeyoung at 2007-7-6 23:07:38 > top of Java-index,Application & Integration Servers,Application Servers...
# 2
Sorry duplicatedMessage was edited by: janeyoung
janeyoung at 2007-7-6 23:07:38 > top of Java-index,Application & Integration Servers,Application Servers...
# 3

Hi Jane,

Thank you for the fast response :-). I've just tried switching out the version I'm working on for your code (with a couple of changes to the parameters as I'm on a windows machine). The only external file I have (nbproject/build-impl.xml) is wholly generated by netbeans and is not designed to be edited as the IDE will just overwrite any changes. So I'm just setting a dependency on the "dist" target of the netbeans file and running my targets last.

I did notice that your project was called "test-asant". You did catch the fact that I don't think I can use asant as part of what I'm doing didn't you? I think I'm stuck with vanilla Ant 1.6.5. I realise this is fast going towards being purely and Ant request :-/ but any further advice you can provide would be greatly appreciated :-)

Cheers

Dave

PS for reference here is my latest build.xml.... oh and I'm using 8.1 Q2

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

<project name="CactusTest" default="deploy-sun-test" basedir=".">

<description>Builds, tests, and runs the project CactusTest.</description>

<import file="nbproject/build-impl.xml"/>

<property name="sun.appserver.antjar" value="T:\\jakarta-cactus-13-1.7.1\\lib\\sun-appserv-ant.jar"/>

<target name="sun-taskdef" depends="dist">

<taskdef name="sun-appserv-deploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

</classpath>

</taskdef>

<taskdef name="sun-appserv-undeploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.UndeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

</classpath>

</taskdef>

</target>

<target name="deploy-sun-test" depends="sun-taskdef">

<!-- <target name="deploy-sun-test"> -->

<sun-appserv-deploy file="dist/CactusTest.war"

name="cactustest"

force="true"

precompilejsp="false"

verify="false"

upload="true"

user="admin"

passwordfile="powertec"

host="localhost"

port="4848"

asinstalldir="C:/Sun/AppServer" />

</target>

<target name="undeploy-sun-test" depends="sun-taskdef">

<sun-appserv-undeploy name="cactustest"

user="admin"

passwordfile="powertec"

host="localhost"

port="4848"

asinstalldir="C:/Sun/AppServer" />

</target>

</project>

Just a bit of an afterthought. The task is looking for the root of my appserver install under asinstalldir isn't it? ie C:/Sun/AppServer ? not the bin folder or the lib folder or anything more obsure? :-)

Message was edited by:

DavidLush

DavidLush at 2007-7-6 23:07:38 > top of Java-index,Application & Integration Servers,Application Servers...
# 4

Hi David,

I used your script and had no problem deploying/undeploying an app. The only change I did was remove the reference to nbproject, "<import file="nbproject/build-impl.xml"/>" and changing the application to something else and the location of asinstalldir.

You have the asinstalldir correct. It is your appserver install directory.

I didn't use asant, I called the build script directly from ant. The version of ant I'm using is 1.6.5 and I'm using 8.1 ur2.

Below is my build.xml:

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

<project name="CactusTest" default="deploy-sun-test" basedir=".">

<description>Builds, tests, and runs the project CactusTest.</description>

<property name="sun.appserver.antjar" value="c:/Sun/as8ee/lib/sun-appserv-ant.jar"/>

<target name="sun-taskdef">

<taskdef name="sun-appserv-deploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

</classpath>

</taskdef>

<taskdef name="sun-appserv-undeploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.UndeployTask">

<classpath>

<pathelement location="${sun.appserver.antjar}" />

</classpath>

</taskdef>

</target>

<target name="deploy-sun-test" depends="sun-taskdef">

<!-- <target name="deploy-sun-test"> -->

<sun-appserv-deploy file="c:/Sun/J2EE_apps/fortune.ear"

name="fortune"

force="true"

precompilejsp="false"

verify="false"

upload="true"

user="admin"

passwordfile="c:/Sun/as8ee/bin/password.txt"

host="localhost"

port="4849"

asinstalldir="c:/Sun/as8ee" />

</target>

<target name="undeploy-sun-test" depends="sun-taskdef">

<sun-appserv-undeploy name="fortune"

user="admin"

passwordfile="c:/Sun/as8ee/bin/password.txt"

host="localhost"

port="4849"

asinstalldir="c:/Sun/as8ee" />

</target>

</project>

Here's my output:

C:\Sun\as8ee\bin>c:\jakarta\apache-ant-1.6.5\bin\ant deploy-sun-test

Buildfile: build.xml

sun-taskdef:

deploy-sun-test:

[sun-appserv-deploy] Executing: deploy --user admin --passwordfile "c:\Sun\as8ee\bin\password.txt" --host localhost --port 4849 --force=true --enabled=true --name fortune --verify=false --precompilejsp=false --upload=true "C:\Sun\J2EE_apps\fortune.ear"

[sun-appserv-deploy] Command deploy executed successfully.

BUILD SUCCESSFUL

Total time: 5 seconds

C:\Sun\as8ee\bin>.\asadmin list-components -u admin --passwordfile .\password.txt --port 4849

fortune <j2ee-application>

Command list-components executed successfully.

C:\Sun\as8ee\bin>c:\jakarta\apache-ant-1.6.5\bin\ant undeploy-sun-test

Buildfile: build.xml

sun-taskdef:

undeploy-sun-test:

[sun-appserv-undeploy] Executing: undeploy --user admin --passwordfile "c:\Sun\as8ee\bin\password.txt" --host localhost --port 4849 fortune

[sun-appserv-undeploy] Command undeploy executed successfully.

BUILD SUCCESSFUL

Total time: 3 seconds

C:\Sun\as8ee\bin>.\asadmin version --user admin --passwordfile .\password.txt --port 4849

Version = Sun Java System Application Server Enterprise Edition 8.1_02

Command version executed successfully.

Question for you: are you trying to execute the build.xml file from netbeans?

Jane

janeyoung at 2007-7-6 23:07:38 > top of Java-index,Application & Integration Servers,Application Servers...