I want use Ant to automate build, deployment,starting & stopping server of applications.
I'm able to build the application through Ant and copied the war file into the Tomcat webapps directory.
On the Internet, I found this article which contains more code to start and stop Tomcat. Since I can successfully deploy without those, I was wondering why they are there.
The code for my build.xml is below.
<?xml version="1.0"?>
<project name="Test" default="build-war">
<property file="build.properties"></property>
<target name="build-war" depends="clean">
<war destfile="Test.war" webxml="${web.dir}/WEB-INF/web.xml" >
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
<classes dir="${build.dir}/classes"></classes>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset
dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<target name="clean" description="Clean Test war directories">
<delete>
<fileset dir="${deploy.path}">
<include name="Test.war"/>
</fileset>
</delete>
</target>
</project>
There is no reliable way to (re)deploy an application to a web server. The reasons why an app might fail to deploy are numerous (thread leak, shutdown hooks, accessing parent classloaders) but in the end, there is no reliable way to tell whether a (complex) application could be deployed successfully.
This means that most developers have learned to use this cycle:
Deploy. Tomcat should automatically notice the new files and restart.
If something is odd, try to reload (ReloadTask). This tells Tomcat "no matter what you believe, the app has changed! Start it again!"
If the app still fails, stop and start Tomcat again.
If that fails, stop tomcat, delete all files, deploy again and after deployment, start Tomcat again.
If that fails, delete Tomcat and all files, reinstall, ...
Yes, I once had a script which could do every of the steps above. :-)
In the end, I gave up on deployment. My current solution is to write a Java application which creates an embedded Tomcat or Jetty server, configures it and starts the app. I have just a single classpath. No file copying, deployment or any such nonsense necessary. That way, I just have a single process, only a single web app in the container and I have all logs in one place.
Related
I'm using ant scripts for initializing my exist-db.
But, I have this script below (dummy version) which is working in my local platform and not on my procution one. As I'm not the one who handle the configuration of this database, I don't know where to look in the conf to fix this.
Here is the script (which is just trying to add a new user) :
<project basedir="." default="default" name="ANTProject">
<property file="load.properties"/>
<path id="classpath.core">
<fileset dir="${path}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${path}\exist.jar"/>
<pathelement path="${path}\exist-optional.jar"/>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<target name="default">
<echo message="Création du compte ${login}"/>
<xdb:adduser xmlns:xdb="http://exist-db.org/ant"
uri="xmldb:exist://${exist.uri}/exist/xmlrpc/db"
name="${login}" secret="${password}" primaryGroup="${user.group}" user="${root.login}"
password="${root.password}"/>
</target>
</project>
I get this error message :
XMLDB exception caught: No such handler: Default.setUser
I get the same thing if I use xdb:users task, but the xdb:store is working well... I'm running exist 2.1, in both my local and production plateform, and as already told, same scripts working well on local one...
I guess, it's something about the exist configuration, but I didn't find anything on enabling this tasks in the documentation.
If someone could help...
Ok, I got it.
Just for completeness, It was an issue on jar librairies. It seems I used ones which support xdb:store, but not others tasks (didn't find any release version of this)...
This ant depandancies is quite tricky and It's hard to know what your jars offer...
I have build a working Java application which I can succesfully build and deploy to my WebLogic11g server.
I'm automating this process now with Ant.
I can build my application, the builded application works fine when deployed manually. But the deployment trough Ant isn't working.
My Ant file:
<!-- GENERAL -->
<property name="project.dir" value="CustomReportingProvider"/>
<!-- JAR -->
<property name="deploy.dir" value="${project.dir}/deploy"/>
<property name="jar.deploy.dir" value="${deploy.dir}/jar"/>
<property name="jar.classes.dir" value="${project.dir}/classes"/>
<property name="jar.meta-inf.dir" value="${jar.classes.dir}/META-INF"/>
<!-- EAR -->
<property name="ear.meta-inf.dir" value="src/META-INF"/>
<target name="clean">
<delete dir="${deploy.dir}"/>
</target>
<target name="package" depends="clean">
<mkdir dir="${deploy.dir}"/>
<mkdir dir="${jar.deploy.dir}"/>
<jar destfile="${deploy.dir}/jar/VSBReportingProvider.jar" basedir="${jar.classes.dir}" includes="**/*/*.class">
<metainf dir="${jar.meta-inf.dir}" includes="*.xml"/>
</jar>
<ear destfile="${deploy.dir}/VSBReportingProvider.ear" basedir="${jar.deploy.dir}" appxml="${ear.meta-inf.dir}/application.xml">
<metainf dir="${ear.meta-inf.dir}" includes="*.xml" excludes="application.xml"/>
</ear>
</target>
<path id="wlappc.classpath">
<fileset dir="C:\Oracle\Middleware10.3.4\wlserver_10.3\server\lib">
<include name="*.jar"/>
</fileset>
</path>
<taskdef name="wldeploy" classpathref="wlappc.classpath" classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="deploy" depends="package">
<wldeploy action="deploy"
name="VSB Reporting Provider"
source="${deploy.dir}/VSBReportingProvider.ear"
user="weblogic"
nostage="true"
password="weblogic1"
verbose="true"
adminurl="t3://localhost:7001"
targets="AdminServer"
debug="true"/>
</target>
The response: http://pastebin.com/x0En9WtA
It keeps saying it can not connect to the server, so I checked the following:
weblogic / weblogic1 account works.
AdminServer is running, can log-on to it.
The 'Enable tunneling' option is enabled.
The same application can be installed trough the web console.
Any help or idea on where to look, would be appreciated.
I find an answer on the Middleware Magic site:
Then please make sure to add "wlfullclient.jar" at the beginning of the CLASSPATH in your >ANT Script...Also please refer to http://forums.oracle.com/forums/thread.jspa?threadID=2188580&tstart=0 - See more at: http://middlewaremagic.com/weblogic/?tag=deploy#sthash.rTLTxQK3.dpuf
see http://middlewaremagic.com/weblogic/?tag=deploy
I figured it out.
I'm working on a Windows 7 machine and was using a linux command-line tool. I don't know the reason, but the linux console wasn't showing all my environment variables, as it couldn't find or read them, I don't know.
All works fine when I deploy from Windows CMD.
I have just started getting Jenkins setup with Phing as the build tool. Although I have used Jenkins before, I'm new to Phing.
I have a project setup in Jenkins that has a Mercurial Repository setup and a Phing Build step.
The build.xml file simply archives the existing file, deletes them and copies the new files from the repository.
I have run phing from the terminal and everything works as planned. However, when running from within Jenkins, I'm getting the following in the Console Output:
[workspace] $ /usr/local/pear/bin/phing -buildfile /Users/Shared/Jenkins/Home/jobs/Project/workspace/build.xml "-Dwebroot=/Volumes/Websites/Project/ -Dcheckoutroot=/Users/Shared/Jenkins/Home/jobs/Project/workspace -Drevision=5" -logger phing.listener.DefaultLogger
/usr/local/pear/bin/phing: fork: Resource temporarily unavailable
Build step 'Invoke Phing targets' marked build as failure
My first thought was that it was permission related, but I've changed Jenkins to run as the same user that I ran Phing manually as and it still got the same issue.
Does anybody have any thoughts as to what might be causing the problem?
I can't find anything related to this error anywhere that isn't related to Cygwin...
The system is running on OS X 10.7.5 with Jenkins 1.518 and Phing 2.5.1
The build.xml file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Project" default="dist">
<property name="revision" value="old" />
<property name="webroot" value="/Volumes/Websites/${phing.project.name}" />
<property name="checkoutroot" value="./" />
<target name="clean">
<echo msg="Backing up old site to ${phing.project.name}-${revision}..." />
<tar destfile="${webroot}/../${phing.project.name}-${revision}.tar.gz" basedir="${webroot}" compression="gzip" />
<echo msg="Deleting site from ${webroot}..." />
<delete>
<fileset dir="${webroot}" />
</delete>
</target>
<target name="dist" depends="clean">
<echo msg="Copying files to website at ${webroot}..." />
<copy todir="${webroot}">
<fileset dir="${checkoutroot}/Website">
<exclude name="**/.hg/**" />
</fileset>
</copy>
</target>
</project>
I've managed to resolve this issue by removing all of the path details in the Phing configuration section within Jenkins.
This makes absolutely no sense to me as to why it's working without these details as I definitely only have one Phing install, so it's not as if it was picking up the wrong one or something.
However, by not specifying anything in the Phing section of the Jenkins project config so it picks up the default path, default build target etc. and this is working flawlessly now!
I have an Ant script which is used to deploy my application on two different machines at a time. With the local machine i do not have a problem, but when it comes to the remote machine, I want to check if Jboss is up or not. If it is up then I want to shut it down but if it is not then nothing should be done. I tried to do this by keeping the attribute of <sshexec> as failonerror="on". This works well when the Jboss is already down and the shutdown command only gives some errors. But the real problem that i faced was when Jboss was running and when the shutdown command was executed, it did not shutdown properly and gave some error. It is in these situations that I want to stop my build script and let the user know that there is something wrong with Jboss on the other machine and it needs to be looked at.
The target code for stopping the remote Jboss is
<target name="stopRemoteJboss" description="Stops Remote Instance of Jboss">
<echo message="Stopping Remote Jboss" />
<sshexec trust="true" host="${jboss.remote.host}" username="${jboss.remote.username}" password="${jboss.remote.password}" command="${jboss.remote.home}/bin/shutdown.sh -S" port="${jboss.remote.port}"/>
</target>
After a short check, I've found following, maybe you could reuse/or use as an inspiration for your script: http://shrubbery.homeip.net/c/display/W/Starting+JBoss+with+ANT
The relevant part for you seem to be:
<java jvm="#{jdkHome}/bin/java"
classname="org.jboss.Shutdown" fork="true" failonerror="false" resultproperty="shutdown.rc">
<arg line="-s jnp://#{bindAddr}:#{jnpPort}"/>
<classpath>
<pathelement path="#{jbossInstallDir}/bin/shutdown.jar"/>
<pathelement path="#{jbossInstallDir}/client/jbossall-client.jar"/>
</classpath>
</java>
<echo>Shutdown rc = ${shutdown.rc}</echo>
<condition property="shutdown.okay">
<equals arg1="${shutdown.rc}" arg2="0"/>
</condition>
<fail unless="shutdown.okay" message="Unable to shut down JBoss (maybe it hasn't fully started yet?)."/>
<echo>Waiting for #{bindAddr}:#{jnpPort} to stop listening...</echo>
Why not check to see if the remote port is active?
<project name="demo" default="check">
<condition property="server.running" value="running" else="not running">
<socket server="remoteserver" port="80"/>
</condition>
<target name="check" description="Print status message">
<echo message="Web server status: ${server.running}"/>
</target>
</project>
If your JBoss instance is configured as a reverse proxy you could use the alternative http condition to check the HTTP response code (which would be 503 "Service unavailable", if the appserver is down)
how can i deploy a app in weblogic only if it is not present in it using wldeploy ant task
when i run ant testapp it deploys fresh everytime over existing app as far as i could see in console messages (ie in sysout).
i call this ant target as dependency in some other target, and i want this to run only if app is not already present in weblogic server (to be more efficient)
<target name="testapp" depends="init-wls">
<wldeploy action="deploy" verbose="true" debug="true"
name="testapp" failonerror="false"
...
source="testapp.war"/>
</target>
an interesting question. I'm not sure if wldeploy can do what you want. One approach that might work would be to use the wlconfig ant task. You could use it to get the ApplicationRuntimeMBeans and then query their ApplicationName attributes (again, with wlconfig task) to see if the application is deployed. Not super straightforward but at least you would avoid the application redeployment.
This is just a quick idea off the top of my head so not sure if it is feasible in practice, sorry.... :)
--edit: tried it out, something like this should work, the assumption here is that if we can find the MBean then it is already deployed which should be a valid assumption since these beans live under AppDeployments:
<project name="test" default="deploy">
<property name="domainName" value="ejbTestDomain"/>
<property name="serverName" value="AdminServer"/>
<property name="appName" value="ejbWebEAR"/>
<target name="findApp">
<wlconfig url="t3://localhost:7001" username="weblogic" password="password_for_weblogic">
<query pattern="${domainName}:ServerRuntime=${serverName},Name=${appName},*,Type=ApplicationRuntime" property="app.is.deployed"/>
</wlconfig>
</target>
<target name="deploy" unless="app.is.deployed" depends="findApp">
<echo message="Deploying..."/>
<!-- deploy using wldeploy task -->
</target>
</project>