I'm a java-greenhorn trying to compile my project via ant, but nothing's working.
So, in my class I'm using log4j.jar and import junit. Everything's in Eclipse, either Ant.
Here is the build.xml file:
<path id="master-classpath">
<pathelement path="D:\.a lot of folders..\junit.jar"/>
<!--<pathelement path="D:\...\log4j-1.2.17.jar"/> -->
<fileset dir="D:\apache-log4j-1.2.17">
<include name="log4j-1.2.17.jar"/>
</fileset>
<pathelement path="${buildSrc}"/>
</path>
And compile block:
<target name="compile" depends="init">
<javac includeantruntime="false" srcdir="${src1}" destdir="${buildSrc}"/>
<javac includeantruntime="false" srcdir="${src2}" destdir="${buildSrc}"/>
<javac includeantruntime="false" srcdir="${test}" destdir="${buildTest}">
<classpath refid="master-classpath"/>
</javac>
<javac includeantruntime="false" srcdir="src" destdir="build/classes" classpath="${buildSrc}"/>
</target>
I've also tried some different approaches, like making the same in the javac-task, using property, etc, to no success. Could you please, identify my mistake and help deal with it?
Thanks in advance.
<javac includeantruntime="false" srcdir="${test}" destdir="${buildTest}">
<classpath refid="master-classpath"/>
</javac>
should work. As should "classpathref" as an attribute on javac itself.
Possibilities:
Typo in folder name
Typo in file name
D drive isn't mapped
Related
My buildfile seems to be running correctly (and generating junit test reports) correctly when executing in Eclipse, however when I execute directly with: ant -buildfile C:\....\build.xml the files aren't produced - and the cmd output suggests it's not running the tests.
I have two eclipse projects. JUnitTest1 which is the code. JUnitTestUnitTests which contains the test code.
I've followed the instructions here to create my buildfile in eclipse (selecting only the test project) and can see the files drop into the junit directory.
When I run ant command directly, no files are generated and it doesn't look like it's running my tests.
Why aren't the changes made via the eclipse GUI reflected in the build.xml? I thought it was auto updated?
Here's the eclipse config
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. --><project basedir="." default="build" name="JUnitTest1UnitTests">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../../tools/eclipse-mars/"/>
<property name="junit.output.dir" value="junit"/>
<property name="JUnitTest1.location" value="../JUnitTest1"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="JUnitTest1.classpath">
<pathelement location="${JUnitTest1.location}/bin"/>
<pathelement location="${JUnitTest1.location}/../../../../../tools/libs/hamcrest-core-1.3.jar"/>
<pathelement location="${JUnitTest1.location}/../../../../../tools/libs/junit-4.12.jar"/>
</path>
<path id="JUnitTest1UnitTests.classpath">
<pathelement location="bin"/>
<pathelement location="../../../../../tools/libs/hamcrest-core-1.3.jar"/>
<pathelement location="../../../../../tools/libs/junit-4.12.jar"/>
<path refid="JUnitTest1.classpath"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall">
<ant antfile="build.xml" dir="${JUnitTest1.location}" inheritAll="false" target="clean"/>
</target>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects">
<ant antfile="build.xml" dir="${JUnitTest1.location}" inheritAll="false" target="build-project">
<propertyset>
<propertyref name="build.compiler"/>
</propertyset>
</ant>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="JUnitTest1UnitTests.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="JUnitTest1UnitTests">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="com.me.tests.MyTestClass" todir="${junit.output.dir}"/>
<classpath refid="JUnitTest1UnitTests.classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
I believe I've fixed this.
Eclipse creates your build file and seperately, you configure your run configurations. These run configurations (where you specify the run order of the ant tasks) are not persisted or represented in the actual build file.
The default target of the build file is the target="build" ... So you need to manually edit the build file and use the depends="..." clause to chain together the dependancies of your tasks.
This page (read example build file and see final line) has a great explanation of the depends clause.
I'm trying to run a "project.zip" I've downloaded from the official GWT site about RPC and Hibernate at http://www.gwtproject.org/articles/using_gwt_with_hibernate.html .
The guide suggests:
"you can use Ant to build the project, as well as start up hosted mode
to see the UI and our Hibernate instance setup in the embedded Jetty
server."
So I have imported it on Eclipse with New > Project menu-> Java Project from Existing Ant Buildfile wizard.
My final goal is to run it on Eclipse as web-application, but it gives me every types of errors and above all there's no run as-> web application but only as ->ant build ! And all the War directory is missing in Eclipse.
How can change this Ant build project.zip to a normal project GWT? I'm amazed how an official Google guide can give so many problems!
If you need it this is the build.xml :
<?xml version="1.0" encoding="utf-8" ?>
<project name="Guestbook" default="build" basedir=".">
<!-- Define gwt.home, gwt.dev.jar, appengine.sdk.home -->
<property file="build.properties"/>
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.home}/gwt-user.jar"/>
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.home}/gwt-servlet.jar" />
<!-- Add any additional server libs that need to be copied -->
<copy todir="war/WEB-INF/lib" flatten="true">
<fileset dir="lib/">
<include name="**/*.jar"/>
</fileset>
</copy>
</target>
<target name="javac" depends="libs" description="Compile java source">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.5" target="1.5" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
</target>
<!-- can add additional arguments like -logLevel INFO or -style PRETTY -->
<target name="gwtc" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg value="com.google.musicstore.MusicStore"/>
</java>
</target>
<target name="hosted" depends="javac" description="Run hosted mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.HostedMode">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-startupUrl"/>
<arg value="MusicStore.html"/>
<arg value="com.google.musicstore.MusicStore"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
</java>
</target>
<target name="build" depends="gwtc" description="Build this project" />
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/musicstore" failonerror="false" />
</target>
</project>
run
ant
to build the project.
run
ant hosted
to run the project.
I'm confused by the concept of a normal GWT project ... I'm not sure to understand what it means. But if it means an eclipse-ready-GWT-project, you will probably be disappointed because as you noted yourself:
you can use Ant to build the project
It is an ant based project, not en eclipse project. You can call ant from eclipse, but there is no specic eclipse files (.project and .classpath) so that it can run with gwt eclipse plugin without configuring it yourself.
I am starting out with GWT and hibernate. I'm going through the tutorial at https://developers.google.com/web-toolkit/articles/using_gwt_with_hibernate.
I downloaded the sample code provided with the tutorial (http://google-web-toolkit.googlecode.com/files/gwt_hibernate_base.zip). This is a simple music store where you can add an account and records. I am able to run this and successfully add accounts and records to the database by doing the following commands:
(in the data directory) java -cp ../lib/hsqldb.jar org.hsqldb.Server
ant build hosted
Here is the build.xml file used to build this:
<?xml version="1.0" encoding="utf-8" ?>
<project name="Guestbook" default="build" basedir=".">
<!-- Define gwt.home, gwt.dev.jar, appengine.sdk.home -->
<property file="build.properties"/>
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.home}/gwt-user.jar"/>
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.home}/gwt-servlet.jar" />
<!-- Add any additional server libs that need to be copied -->
<copy todir="war/WEB-INF/lib" flatten="true">
<fileset dir="lib/">
<include name="**/*.jar"/>
</fileset>
</copy>
</target>
<target name="javac" depends="libs" description="Compile java source">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.5" target="1.5" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
</target>
<!-- can add additional arguments like -logLevel INFO or -style PRETTY -->
<target name="gwtc" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg value="com.google.musicstore.MusicStore"/>
</java>
</target>
<target name="hosted" depends="javac" description="Run hosted mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.home}/${gwt.dev.jar}"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-startupUrl"/>
<arg value="MusicStore.html"/>
<arg value="com.google.musicstore.MusicStore"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
</java>
</target>
<target name="build" depends="gwtc" description="Build this project" />
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/musicstore" failonerror="false" />
</target>
Now I would like to get this simple example working in eclipse. I created a project called MusicStore using the gwt eclipse plugin. I then copied over the tutorial files without changing them. I can't post an image but here is a link to my eclipse project structure:
http://oi50.tinypic.com/t6rn2w.jpg
Again, I start by running
(in the data directory) java -cp ../lib/hsqldb.jar org.hsqldb.Server
Then I try to run my project in eclipse but hibernate doesn't work. When I try to add an account in the UI it alerts "Failed to save account" and I get the error java.lang.NoClassDefFoundError: org/hibernate/Session.
Please let me know how I should go about getting the sample code working with eclipse. I think that many users new to hibernate will also want to do this.
Thanks!
Basically eclipse cannot find your hibernate libraries. That is because your build.xml is for building a war file. Eclipse doesn't read it so it doesn't have any of your build information in there.
A quick solution to this is to just go to the "Build Path" properties in Eclipse and make sure your /lib directory is included in the "Libraries" tab. Then eclipse will know where you are keeping your libraries.
A better solution would be to use something like Maven. Then the Maven Plugin for Eclipse will automatically look at the Maven build file and configure the Eclipse project so that it can detect where the libraries are held etc...
I have jax-ws web service (jboss implementation) configured with annotation.
#WebService([...], wsdlLocation = "/WEB-INF/wsdl/service.wsdl")
The wsld file is included into war file. The war file is included into ear file, that is deployed on JBoss (version: 5.0.1.GA).
During deployment I receive error message like that:
"Could not find /WEB-INF/wsdl/service.wsdl in the additional metadatafiles!"
I tried to put the file in many places:
- META-INF folder of war file,
- META-INF folder of ear file,
- classpath of war file,
but I it didn't help.
Anyone knows how should I configure it?
i had the same problem and i solved like this:
#WebService(targetNamespace="http://my.app.it/", wsdlLocation = "WEB-INF/wsdl/additional.wsdl")
(WEB-INF not start with slash)
To address this issue, I placed the WSDLs into the jar file that I had created from the generated stubs. Then set the wsdllocation and all was good.
example of my ant target:
<target name="genclients" depends="clean, -createdirs">
<wsimport
fork="true"
xnocompile="true"
wsdl="${src.resource.dir}\${wsdl.name}"
wsdllocation="/resources/${wsdl.name}"
sourcedestdir="${src.generated.dir}"
verbose="true"
destdir="${target.classes.dir}"
keep="true"
extension="true"
debug="true"
package="com.fedex.ship.stub"
xadditionalHeaders="true"
binding="${basedir}/binding.xml"
>
<arg line="-mark-generated"/>
</wsimport>
<javac srcdir="${src.generated.dir}" destdir="${target.classes.dir}" includeantruntime="false" source="1.6" target="1.6" debug="true" deprecation="false" optimize="false" failonerror="true">
<include name="**/*.java"/>
</javac>
<copy todir="${target.classes.dir}" preservelastmodified="true" overwrite="true">
<fileset dir="${src.dir}" >
<include name="**/*.wsdl"/>
<include name="**/*.xsd"/>
</fileset>
</copy>
<pathconvert property="manifest.classpath" pathsep=" ">
<mapper>
<chainedmapper>
<flattenmapper />
</chainedmapper>
</mapper>
<path>
</path>
</pathconvert>
<mkdir dir="${target.classes.dir}/META-INF"/>
<manifest file="${target.classes.dir}/META-INF/manifest.mf">
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
<jar jarfile="${target.jar.dir}/${jar.name}" basedir="${target.classes.dir}" manifest="${target.classes.dir}/META-INF/manifest.mf" excludes=".settings,**/.svn"/>
<!--
<delete failonerror="false" includeEmptyDirs="true">
<fileset dir="${target.classes.dir}"/>
</delete>
-->
</target>
I'm trying to incorporate hibernate schema generator for Envers.
I've add this target:
<target name="schemaexport"
description="Exports a generated schema to DB and file">
<path id="hibernate.classpath">
<pathelement path="./lib/hibernate-persistence/*.jar" />
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.EnversHibernateToolTask"
classpathref="hibernate.classpath"/>
<hibernatetool destdir=".">
<classpath>
<fileset refid="lib.hibernate" />
<path location="${build.demo.dir}" />
<path location="${build.main.dir}" />
</classpath>
<jpaconfiguration persistenceunit="AuroraServicePU" />
<hbm2ddl
drop="false"
create="true"
export="false"
outputfilename="versioning-ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
</target>
The problem is that I get the error
taskdef class org.hibernate.tool.ant.EnversHibernateToolTask cannot be found
using the classloader AntClassLoader[myproject\lib\hibernate-persistence*.jar]
Help will be great.
Thank you,
Ido.
I suspect your path is incorrect. I don't believe you can use wildcards in a pathelement.
Try changing your path to be:
<path id="hibernate.classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</path>
If that fails, run ant with the -v tag and check the debug for more hints.