We are using jspc ant task to pre-compile JSP files into classes/(then package into war)
Now we are switching to Jetty 8. According to the doc, there exists a maven plugin to do this. Do we have ant task to do the same?
Its best if you use the JSP libs that comes with the jetty distribution.
Here's an example, using jetty-distribution-8.1.5.v20120716
<?xml version="1.0" ?>
<project name="AntExample1" default="war">
<property name="jetty.home" value="${user.home}/code/intalio/distros/jetty-distribution-8.1.5.v20120716" />
<path id="compile.jspc">
<fileset dir="${jetty.home}">
<include name="lib/servlet-api-*.jar" />
<include name="lib/jsp/*.jar" />
</fileset>
</path>
<path id="compile.classpath">
<fileset dir="WebContent/WEB-INF/lib">
<include name="*.jar" />
</fileset>
<path refid="compile.jspc" />
</path>
<target name="jspc" depends="compile">
<taskdef classname="org.apache.jasper.JspC" name="jasper2" classpathref="compile.jspc" />
<jasper2 validateXml="false"
uriroot="WebContent"
addWebXmlMappings="true"
webXmlFragment="WebContent/WEB-INF/generated_web.xml"
compilerSourceVM="1.6"
compilerTargetVM="1.6"
outputDir="build/gen-src"
verbose="9" />
</target>
<target name="init">
<mkdir dir="build/classes" />
<mkdir dir="build/gen-src" />
<mkdir dir="dist" />
<copy todir="build/gen-src">
<fileset dir="src" includes="**/*.java" />
</copy>
</target>
<target name="compile" depends="init">
<javac destdir="build/classes" debug="true" srcdir="build/gen-src">
<classpath refid="compile.classpath" />
</javac>
</target>
<target name="war" depends="jspc">
<war destfile="dist/AntExample.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" />
<classes dir="build/classes" />
</war>
</target>
<target name="clean">
<delete dir="dist" />
<delete dir="build" />
</target>
</project>
Update: April 8, 2013
Pushed an example project with this build to github.
https://github.com/jetty-project/jetty-example-jspc-ant
Jasper has jspc; the linked page has ant code for calling it.
From your first sentence you are apparently already using an ant task to pre-compile the jsp files...so using jetty-8 doesn't mean you have to change that process at all, you will still just pre-compile as you have been, building your war file as you have been and then just deploy into jetty-8. You will need to add jsp to the OPTIONS in the start.ini to get the jsp engine into the server classloader.
Related
I am using GlassFish 4 with Eclipse Kepler.
I'd like to add PrimeFaces to my JSF project, but I can't seem to import it. I keep getting this error:
Warning: This page calls for XML namespace http://primefaces.org/ui
declared with prefix p but no taglibrary exists for that namespace
Which baffles me as I imported the PrimeFaces 4 jars and rebuild (using an ANT build supplied by my lecturer) and redeployed.
Here is my Ant build -
<project name="JavaEE Build" default="BuildAll">
<!-- This needs to be changed before you build your code -->
<property name="glassfish_libs" value="C:\glassfish4\glassfish\modules"/>
<property name="bin" value="./bin"/>
<property name="lib" value="./lib"/>
<property name="src" value="./src"/>
<property name="dist" value="./dist"/>
<property name="jarfile" value="${dist}/ejb.jar"/>
<property name="warfile" value="${dist}/webapp.war"/>
<property name="html" value="./WebContent"/>
<path id="my.classpath">
<pathelement path="${java.class.path}"/>
<pathelement location="${bin}"/>
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
<fileset dir="${glassfish_libs}">
<include name="**/javax*.jar"/>
<include name="jsf-api.jar"/>
<include name="security.jar"/>
</fileset>
</path>
<target name="BuildAll"
depends="clean, prep, compile, jar, war"
description="Complete rebuild.">
<echo message="Build complete."/>
</target>
<target name="classpath">
<property name="current.classpath" refid="my.classpath"/>
<echo level="info">
Classpath is :
${current.classpath}
</echo>
</target>
<target name="clean">
<delete dir="${bin}"/>
<delete dir="${dist}"/>
<delete>
<fileset dir=".">
<include name="TEST*.xml"/>
</fileset>
</delete>
</target>
<target name="prep">
<mkdir dir="${bin}"/>
<mkdir dir="${dist}"/>
</target>
<target name="compile"
description="Compile all Java classes"
depends="prep">
<javac srcdir="${src}" destdir="${bin}" debug="true" encoding="ISO-8859-1">
<classpath refid="my.classpath"/>
</javac>
<echo message="Compiled."/>
</target>
<target name="jar" depends="compile"
description="Build EJB Jar files.">
<delete file="${jarfile}"/>
<jar destfile="${jarfile}" basedir="${bin}">
<metainf dir="${src}/META-INF">
<include name="persistence.xml"/>
</metainf>
</jar>
</target>
<target name="war" depends="compile"
description="Build WAR file.">
<copy todir="${bin}">
<fileset dir="${src}">
<include name="**/persistence.xml"/>
</fileset>
</copy>
<delete file="${warfile}"/>
<war destfile="${warfile}" webxml="web.xml">
<classes dir="${bin}">
</classes>
<lib dir="${lib}"/>
<fileset dir="${html}"/> <!-- html files -->
<!-- The following block is commented out, until
the chapter on security. Please leave it until then! -->
<!--
<webinf dir="${src}/META-INF">
<include name="sun-ejb-jar.xml"/>
</webinf>
-->
</war>
</target>
<target name="ear" depends="war, jar" description="The full ear file">
<ear destfile="${dist}/fullapplication.ear" appxml="application.xml">
<fileset dir="${dist}" includes="*.jar,*.war"/>
</ear>
</target>
Then here is a simple Facelet - it is called entry.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:body>
<p:spinner></p:spinner>
</h:body>
I imported the primefaces-4.0.jar and primeface-4.0-sources.jar by right clicking the project -> build path -> configure build path -> add external jars
If anyone can help that will be lovely
The taglib definition is quite strange. I use primefaces 4.0 and the path for the PF taglib is this:
<html ...
xmlns:p="http://primefaces.org/ui">
The namespace you are using was in the Primefaces 2
If that doesn't help, check if the primefaces library is really in the war you're deploying.
I can run my tests via Ant in IDE.
But, While i try to run it from Command Line - it fails, because cant find the Excel from Resources
I added:
`<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>`
the file copied but still fail.
Looks like code doesnt look in correct place..
Any idea?
full build.xml:
<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.8.5.jar"/>
</classpath>
</taskdef>
<property name="testdir" location="test" />
<property name="srcdir" location="src" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<property name="Resources" location="Resources"/>
<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>
<path id="classpath.base"/>
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testdir}" />
<pathelement location="${srcdir}" />
<path refid="classpath.base" />
</path>
<target name="clean" >
<delete verbose="${full-compile}">
<fileset dir="${testdir}" includes="**/*.class" />
</delete>
</target>
<target name="compile" depends="clean">
<javac srcdir="${srcdir}" destdir="${testdir}"
verbose="${full-compile}">
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test" depends="compile">
<testng outputdir=".test-output" classpathref="classpath.test"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
</project>'
i found the problem.
in code i use the System.getProperty("user.dir") and when running from ant it finds my "user" folder.
So i can manually put there the excel ant it works.
Now, i need to find the way to change the System.getProperty("user.dir") to something that points to projects root
I am trying to build a runnable JAR file of a project by using build.xml file and the prompt code
cd <the directory of you application>
ant -f bin/build.xml jar
But I have exceptions when I run the JAR because I cannot add the external JAR.
the build.xml is as follows:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
This file was generated by Jason 1.3.9-alpha
http://jason.sf.net
Ocak 11, 2014 - 01:09:12
-->
<project name ="virtualClassroom"
basedir=".."
default="run">
<property name="mas2j.project.file" value="virtualClassroom.mas2j"/>
<property name="debug" value=""/> <!-- use "-debug" to run in debug mode -->
<property name="build.dir" value="${basedir}/bin/classes" />
<property name="jasonJar" value="C:\Users\Emre\Desktop\MasterThesis-BDI\Jason-1.3.9\Jason-1.3.9\lib\jason.jar"/>
<property name="JavaCsBridgeJar" value="C:\Users\Emre\Desktop\MasterThesis-BDI\virtualClassroom\lib\JavaCsBridge.jar"/>
<path id="project.classpath">
<pathelement location="${basedir}"/>
<pathelement location="${build.dir}"/>
<pathelement location="${JavaCsBridgeJar}"/>
<pathelement location="${jasonJar}"/>
<fileset dir="${basedir}/lib" > <include name="*.jar" /> </fileset>
</path>
<!-- tasks the user can override in his/her c-build.xml script -->
<target name="user-init">
</target>
<target name="user-end">
</target>
<target name="init">
<mkdir dir="${build.dir}" />
<antcall target="user-init" />
</target>
<target name="compile" depends="init">
<condition property="srcdir" value="${basedir}/src/java" else="${basedir}" >
<available file="${basedir}/src/java" />
</condition>
<javac srcdir="${srcdir}" destdir="${build.dir}" debug="true" optimize="true" includeantruntime="false" >
<classpath refid="project.classpath"/>
</javac>
</target>
<target name="jar" depends="compile">
<delete file="${ant.project.name}.jar" />
<copy file="${jasonJar}" tofile="${ant.project.name}.jar" />
<copy file="${JavaCsBridge}" tofile="${ant.project.name}.jar" />
<copy file="${mas2j.project.file}" tofile="default.mas2j" />
<jar update="yes" jarfile="${ant.project.name}.jar" >
<fileset dir="${basedir}">
<include name="**/*.asl" />
<include name="**/*.mas2j" />
</fileset>
<fileset dir="${build.dir}">
<include name="**/*.class" />
</fileset>
<manifest>
<attribute name="Main-Class" value="jason.infra.centralised.RunCentralisedMAS"/>
</manifest>
</jar>
<delete file="default.mas2j" />
</target>
<target name="jnlp" depends="jar" >
<mkdir dir="${basedir}/${ant.project.name}-jws"/>
<java classname="jason.infra.centralised.CreateJNLP"
failonerror="true" fork="yes" dir="${basedir}/${ant.project.name}-jws" >
<classpath refid="project.classpath"/>
<arg line="${ant.project.name} ${mas2j.project.file}"/>
</java>
<copy todir="${basedir}/${ant.project.name}-jws" failonerror="no">
<fileset dir="${basedir}/lib" includes="**/*.jar" />
<fileset dir="${basedir}" includes="${ant.project.name}.jar" />
<fileset dir="C:\Users\Emre\Desktop\MasterThesis-BDI\Jason-1.3.9\Jason-1.3.9/src/images" includes="Jason-GMoreau-Icon.jpg" />
</copy>
<signjar jar="${basedir}/${ant.project.name}-jws/${ant.project.name}.jar" alias="jason"
storepass="rbjhja" keypass="rbjhja" keystore="C:\Users\Emre\Desktop\MasterThesis-BDI\Jason-1.3.9\Jason-1.3.9/src/jasonKeystore" />
<echo message="**" />
<echo message="** Java Web Start application created in directory ${ant.project.name}-jws" />
<echo message="** Update the codebase (in the second line of the .jnlp file)" />
<echo message="** with the URL where you will upload the application." />
<echo message="**" />
</target>
<target name="run" depends="compile" >
<echo message="Running project ${ant.project.name}" />
<java classname="jason.infra.centralised.RunCentralisedMAS"
failonerror="true" fork="yes" dir="${basedir}" >
<classpath refid="project.classpath"/>
<arg line="${mas2j.project.file} ${debug} "/>
<!-- jvmarg line="-Xmx500M -Xss8M"/ -->
</java>
<antcall target="user-end" />
</target>
<target name="clean" >
<delete failonerror="no" includeEmptyDirs="true" verbose="true">
<fileset dir="${basedir}" includes="**/*.class"/>
</delete>
</target>
</project>
Do anyone know what to do?
Thanks
Firstly, you need to tell us exactly which class is giving a NoClassDefFoundError
As a generic answer, the explanation is that the particular class was available during compile time but missing during runtime. This is a common issue with jar executables.
Solution : Either include the missing classes in the jar itself or add those to the system classpath.
At present I have the following build.xml:
<project name="Bccn" default="help" basedir=".">
<!-- Define the properties used by the build -->
<property name="app.name" value="bccn" />
<property name="app.version" value="0.1-dev" />
<property name="tcserver.home" value="/home/abhishek/tomcat" />
<property name="work.home" value="${basedir}/work" />
<property name="dist.home" value="${basedir}/dist" />
<property name="src.home" value="${basedir}/src" />
<property name="web.home" value="${basedir}/web" />
<property name="lib.dir" value="${basedir}/lib" />
<target name="help">
<echo>You can use the following targets:</echo>
<echo>
</echo>
<echo> help : (default) Prints this message </echo>
<echo> all : Cleans, compiles, and packages application</echo>
<echo> clean : Deletes work directories</echo>
<echo> compile : Compiles servlets into class files</echo>
<echo> dist : Packages artifacts into a deployable WAR</echo>
<echo>
</echo>
<echo>For example, to clean, compile, and package all at once, run:</echo>
<echo>prompt> ant all </echo>
</target>
<!-- Define the CLASSPATH -->
<path id="compile.classpath">
<fileset dir="${tcserver.home}/bin">
<include name="*.jar" />
</fileset>
<pathelement location="${tcserver.home}/lib" />
<fileset dir="${tcserver.home}/lib">
<include name="*.jar" />
</fileset>
</path>
<target name="all" depends="clean,compile,dist" description="Clean work dirs, then compile and create a WAR" />
<target name="clean" description="Delete old work and dist directories">
<delete dir="${work.home}" />
<delete dir="${dist.home}" />
</target>
<target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
<mkdir dir="${dist.home}" />
<mkdir dir="${work.home}/WEB-INF/classes" />
<!-- Copy static HTML and JSP files to work dir -->
<copy todir="${work.home}">
<fileset dir="${web.home}" />
</copy>
</target>
<target name="compile" depends="prepare" description="Compile Java sources and copy to WEB-INF/classes dir">
<javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes">
<classpath refid="compile.classpath" />
</javac>
<copy todir="${work.home}/WEB-INF/classes">
<fileset dir="${src.home}" excludes="**/*.java" />
</copy>
</target>
<target name="dist" depends="compile" description="Create WAR file for binary distribution">
<jar jarfile="${dist.home}/${app.name}-${app.version}.war" basedir="${work.home}" />
</target>
Now I included log4j as a local dependency and want to include it when I create my .war file. However, ANT is not able to find the dependency. Is there a way to get it working? Sorry for the basic question, I am a noob at it.
Update (and thanks for the help I got already):
I didn't want to add the "war" thing so I modified my build.xml as follows:
``
<target name="help">
<echo>You can use the following targets:</echo>
<echo>
</echo>
<echo> help : (default) Prints this message </echo>
<echo> all : Cleans, compiles, and packages application</echo>
<echo> clean : Deletes work directories</echo>
<echo> compile : Compiles servlets into class files</echo>
<echo> dist : Packages artifacts into a deployable WAR</echo>
<echo>
</echo>
<echo>For example, to clean, compile, and package all at once, run:</echo>
<echo>prompt> ant all </echo>
</target>
<!-- Define the CLASSPATH -->
<path id="compile.classpath">
<fileset dir="${tcserver.home}/bin">
<include name="*.jar" />
</fileset>
<pathelement location="${tcserver.home}/lib" />
<fileset dir="${tcserver.home}/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<target name="all" depends="clean,compile,dist" description="Clean work dirs, then compile and create a WAR" />
<target name="clean" description="Delete old work and dist directories">
<delete dir="${work.home}" />
<delete dir="${dist.home}" />
</target>
<target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
<mkdir dir="${dist.home}" />
<mkdir dir="${work.home}/WEB-INF/classes" />
<!-- Copy static HTML and JSP files to work dir -->
<copy todir="${work.home}">
<fileset dir="${web.home}" />
</copy>
</target>
<target name="compile" depends="prepare" description="Compile Java sources and copy to WEB-INF/classes dir">
<javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes">
<classpath refid="compile.classpath" />
</javac>
<copy todir="${work.home}/WEB-INF/classes">
<fileset dir="${src.home}" excludes="**/*.java" />
<fileset dir="${lib.dir}" includes="*.jar" />
</copy>
</target>
<target name="dist" depends="compile" description="Create WAR file for binary distribution">
<jar jarfile="${dist.home}/${app.name}-${app.version}.war" basedir="${work.home}" />
</target>
Now ANT can find the dependencies and compile it. However when I deploy it to a Tomcat server, it fails to file the dependencies. Can you please provide some ideas as to how I can package the dependencies so its visible to Tomcat as well?
You should use the war task instead:
<war destfile="${warname}" webxml="war/WEB-INF/web.xml">
<fileset dir="${work.home}"/>
<lib dir="${lib.dir}/" includes="log4j.jar"/>
<classes dir = "${CLASSES}" />
</war>
You can configure it to find the dependency jars to be included in your war file and to specify the path to the web.xml folder. You shouldn't be coping the .class files to the destination in the war folder, let the war task do it for you.
In my java web project,there are code like <T> , in ant script, javac use JDK to compile java code, and it can't compile success.
Later,I know it must use eclipse JDT to compile.
And, in eclipse, ant script can run success.when run like this:
Right key click build.xml ---> Run ---> Run as ---> External Tools Configurations,click JRE,select "Run in the same JRE as the workspace".
After that, ant can run successful, in eclipse.
But, I want to write a .bat and .sh file to call ant script, to compile,war,deploy and start Tomcat.
So, ant should run from command. I tried more, error happend always:
Class not found: org.eclipse.jdt.core.JDTCompilerAdapter
PS, I have copy jar files about JDT in eclipse plugin to ant_home/lib directory.
Wish your response. Thanks in advance!
build.xml
`
<tstamp>
<format property="build.time" pattern="yyyy-MM-dd" />
</tstamp>
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${catalina.home}/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${ant.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clear">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
<delete file="${catalina.home}/webapps/${webapp.name}.war" />
<delete dir="${catalina.home}/webapps/${webapp.name}" />
</target>
<target name="init" depends="clear">
<mkdir dir="${build.dir}/classes" />
<mkdir dir="${dist.dir}" />
</target>
<target name="compile" depends="init">
<echo message="begin compile..." />
<javac srcdir="${src.dir}" destdir="${build.dir}/classes"
includeantruntime="false" nowarn="on"
source="1.6" target="1.6" deprecation="true" debug="true"
encoding="UTF-8" classpathref="project.classpath">
<compilerarg line="-Xlint:unchecked" />
</javac>
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
<include name="**/*.sql" />
</fileset>
<fileset dir="${config.dir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
<include name="**/*.sql" />
</fileset>
</copy>
<echo message="end compile..." />
</target>
<target name="war" depends="compile">
<echo message="begin war..." />
<war destfile="${dist.dir}/${webapp.name}.war" basedir="${webRoot.dir}"
webxml="${webRoot.dir}/WEB-INF/web.xml">
<lib dir="${lib.dir}" />
<classes dir="${build.dir}/classes" />
<fileset dir="${webRoot.dir}">
<include name="***.*" />
</fileset>
</war>
<echo message="end war..." />
</target>
<target name="deploy" depends="war">
<echo message="begin deploy..." />
<copy file="${dist.dir}/${webapp.name}.war" todir="${catalina.home}/webapps" />
<echo message="end deploy..." />
</target>
</project>
`
Don't use the ant from eclipse IDE for usage from command line.
Download ant separately and extract it somewhere like - C:\apache\ant - for windows, and put its bin directory in your PATH. It'll come with some jars that will need to be added to your CLASSPATH too.
For Mac OSX 'sudo port install ant" takes care of everything.
Download ecj*.jar from Eclipse and put in under ANT_HOME/lib.
Make sure that ANT_HOME is set under the shell environment or you should set the ecj*.jar in the CLASSPATH on the shell. (Otherwise, a Class not found: org.eclipse.jdt.core.JDTCompilerAdapter might be still thrown.)
For the record, I am also getting this error randomly (works more often than not) when using the <javac> task with that compiler adapter in a <parallel> context, i.e. in multi-threaded situation.
It looks as if the compiler adapter jar is temporarily locked and can't be accessed by the thread classloader or something. I don't have a workaround for it yet, short of removing the <parallel> execution.