build.xml: No WEB-INF/web.xml file was added. – Apache Ant 1.7.1

December 24, 2009

Hi,
Recently I faced an issue with Apache Ant version 1.7.1.

I was building a WAR file using the standard dynamic web project in Eclipse Ganymede. It had “src” and “WebContent” directories as per the structure.

When I ran the target “create-war”  which looked like this.


<target name="create-war" depends="clean-dist">
<mkdir dir="${basedir}/dist"/>
<war destfile="${basedir}/dist/myapp.war" casesensitive="true">
<classes dir="${classes}" includes="**/*">
</classes>

<fileset dir="${basedir}/WebContent" casesensitive="yes">
<exclude name="META-INF/**"></exclude>
<exclude name="WEB-INF/**"></exclude>
</fileset>
<lib dir="${lib}"/>
<webinf  dir="${basedir}/WebContent/WEB-INF" casesensitive="true" >
<include name="web.xml"/>
<include name="struts-config.xml"/>
<include name="tiles-defs.xml"/>
</webinf>
<metainf dir="${basedir}/WebContent/META-INF" casesensitive="true"/>
</war>
</target>

This gave me the following error:

Buildfile: build.xml
clean-dist:
create-war:

BUILD FAILED
build.xml:65: No WEB-INF/web.xml file was added.
If this is your intent, set needxml=’false’
Total time: 2 seconds

I had web.xml file in appropriate directory to be picked up by target named “war”. But still keep getting this error.
I tried to fiddle with the attribute mentioned in the error “needxml” without any luck.

Finally I realized that I did not have “dist” directory created in my directory structure. Once I did that “create-war” ran successfully.

I wrote this one because the error that ANT throws, is surprisingly misleading and do not direct us to the actual cause of build failure.
It might be possible that you get similar error message on different use cases as well. This might be just one of it which can be fixed by creating the missing directory.

-Amit

Hi,

Recently I faced an issue with Apache Ant version 1.7.1.

I was building a WAR file using the standard dynamic web project in Eclipse Ganymede. It had “src” and “WebContent” directories as per the structure.

When I ran the target “create-war”  which looked like this.

Advertisements

IE6/HTML Select – ‘Could not set the selected property. Unspecified error.’

December 15, 2009

Hello,
Recently I was developing a control where the HTML select boxes are populated with option elements on the fly within jQuery’s $(document).ready() function.
It worked perfectly fine in all the browsers ( Firefox , Google Chrome and IE7) except IE 6.

I was fortunate enough to find this FINE article that enlightened me about the error and fix for it.
jquery-ie6-and-could-not-set-selected.html

Thanks a ton to the Author of above blog.

Here are the details of problem faced and resolution I used based on the above article/blog.

Upon checking the JavaScript error for IE 6, found that it threw the following error
Error: Could not set the selected property. Unspecified error.

This was not caused due to Java Script programming error while initializing the SELECT boxes with OPTION elements.

This was caused by the line that actually sets the selected item in the HTML SELECT using

//Consider a HTML SELECT control with id=”source” in HTML page.
$("#source").val($("option[index=0]","#source").val());

To resolve this error put the code that selects the value in a try/catch block. For IE6 once this line throws the exception again try to set the selected value using JavaScript function “setTimeout()” with a timeout period of 1 millisecond. This much time-delay is sufficient for IE6 to see the refreshed DOM tree and select the corresponding item.

//Consider a HTML SELECT control with id=”source” in HTML page.
try {
	$("#source").val($("option[index=0]","#source").val());
} catch(ex) {
	setTimeout(function() {
		$("#source").val($("option[index=0]","#source").val());},1);
}

Setting Connection Pool in Tomcat 6.x

December 7, 2009

Hi,

Recently I was configuring a connection pool for Oracle database on Tomcat server. Hence thought of sharing the same with you all.  I am sure that everyone out there must have done this and found it simple. The reason for posting this is that most of my colleagues missed putting the driver JAR file in the server lib directory which is needed by tomcat to refer the driver classes at the start-up.

  1. Make sure you have the JDBC Drivers placed in the {tomcat.home}/lib directory. For Oracle 10g use ojdbc14_g.jar
  2. Create a file named context.xml in <<yourwebapp>>\WebContent\META-INF directory.
  3. Use Resource element to configure the connection pool as shown below.
  4. Sample context.xml file

    <?xml version="1.0" encoding="UTF-8"?>
    <Context antiResourceLocking="false" privileged="true" cookies="true">
    <Resource name="jdbc/mypool" auth="Container"
    type="javax.sql.DataSource"
    driverClassName="oracle.jdbc.OracleDriver"
    url="jdbc:oracle:thin:@<<host:port>>:<<sid>>"
    username=<<username goes here>>
    password=<<password goes here>>
    maxActive="20" maxIdle="10" maxWait="-1"/>
    </Context>
    
  5. Add the resource reference to the DataSource created in Step#3 to the web-application using web.xml.
  6. Refer the DataSource using “<res-ref-name>” as the JNDI name in your source.
  7. E.g.

    <resource-ref>
    <description>DataSource for Web Application</description>
    <res-ref-name>jdbc/mypool</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    

Hope this helps you setting up the connection pool.

Note: Resource element used to configure the connection pool has lot of configurable properties. Only base minimum properties are used above. For further information on DBCP configuration you can refer DBCP Configuration Parameters