Ant - No public execute() error, even though it is there - java

I have an Ant script that I use to compile a project, and recently I've been trying to implement Maven to said project to deal with libraries references. I managed to do a'okay and create a pom.xml script that copies the libraries into the lib folder and then invokes the build.xml of Ant to build the whole project.
But then I tried to make ant invoke a function from the main class of the project (by making it extend the Task class and implementing the execute() method), but for some reason the build.xml script says that said function doesn't exist. It finds the class, alright, but not the function. What's weirder is the fact that I tried it in a previous version that doesn't have Maven implemented, and it works perfectly fine.
This is the bit in the ant build.xml that sets the path and defines the task:
<path id="classes">
<pathelement path="${basedir}/bin" />
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<taskdef name="getVersionTask"
classname="us.inswitch.jreport.JReport"
classpathref="classes"/>
<getVersionTask/>
And this is, in short, the class in question (with the unnecesary things removed):
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
public class JReport extends Task {
public void execute() throws BuildException {
getProject().setProperty("version", version);
Date date;
date=new Date();
DateFormat format=DateFormat.getDateInstance();
getProject().setProperty("date",format.format(date));
}
}
In both project cases, the files are the same through and through.
I think that, somehow, one being a Maven project and the other not being one is affecting something. Even after copying the ant files in the directory instead of referencing them with Maven, the error is still there. If I try to run the build script alone on the Maven project, it crashes and lays out this message pile:
[javac] import org.apache.tools.ant.BuildException;
[javac] ^
[javac] C:\Users\user\Documents\workspace\jreport-maven\src\us\inswitch\jreport\JReport.java:9: package org.apache.tools.ant does not exist
[javac] import org.apache.tools.ant.Task;
[javac] ^
[javac] C:\Users\user\Documents\workspace\jreport-maven\src\us\inswitch\jreport\JReport.java:19: cannot find symbol
[javac] symbol: class Task
[javac] public class JReport extends Task {
[javac] ^
[javac] C:\Users\user\Documents\workspace\jreport-maven\src\us\inswitch\jreport\JReport.java:115: cannot find symbol
[javac] symbol : class BuildException
[javac] location: class us.inswitch.jreport.JReport
[javac] public void execute() throws BuildException {
[javac] ^
[javac] C:\Users\user\Documents\workspace\jreport-maven\src\us\inswitch\jreport\JReport.java:116: cannot find symbol
[javac] symbol : method getProject()
[javac] location: class us.inswitch.jreport.JReport
[javac] getProject().setProperty("version", version);
[javac] ^
[javac] C:\Users\user\Documents\workspace\jreport-maven\src\us\inswitch\jreport\JReport.java:120: cannot find symbol
[javac] symbol : method getProject()
[javac] location: class us.inswitch.jreport.JReport
[javac] getProject().setProperty("date",format.format(date));
[javac] ^
[javac] 6 errors
Any ideas?

The error message is pretty clear:
[javac] ... package org.apache.tools.ant does not exist
[javac] import org.apache.tools.ant.Task;
[javac] ^
During your compile, you need the ant.jar file in your javac classpath.
If you want to use Maven repositories for dependency management, you may want to look into using Ivy. Ivy is a dependency manager that can be used by Ant and can (if so configured) use Maven repositories.
At my current location, our company produces a lot of jars that go into other projects. Originally, they tried downloading these jars into projects, and then using a overly complex system to fetch the jars that still didn't work. I was able to incorporate Ivy into the current build system.
Moving to Maven would have meant completely overhaul of all of the projects and not being 100% sure what we were producing was correct. Using Ivy allowed me to handle the dependency management issues with a minimal amount of changes. Plus, it allowed me to fix this issue as quickly as possible.

Related

How do I add a jar-file to Ant for a NetBeans Java Web App project so that it gets build?

I am trying to set up an automatic build system with command line ant.
Using glassFish 4.1 and Netbeans 8.0.2
My command line build I have the following command:
C:\java\NetBeans 8.0.2\extide\ant\bin>ant -f \Java\Temp\myproject\build.xml -Dnb.internal.action.name=build -DforceRedeploy=false -Dbrowser.context=\Java\Temp\myproject\ -Duser.properties.file=C:\Users...\AppData\Roaming\NetBeans\8.0.2\build.properties -Dj2ee.server.home=C:\java\glassfish4\GLASSFISH\ dist
And this is the last part of my output:
[javac] C:\Java\Temp\crmparts\src\java\freedom\bytecode\service\CrmPartsServiceA.java:10: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.Consumes;
[javac] ^
[javac] C:\Java\Temp\crmparts\src\java\freedom\bytecode\service\CrmPartsServiceA.java:11: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.HeaderParam;
[javac] ^
[javac] C:\Java\Temp\crmparts\src\java\freedom\bytecode\service\CrmPartsServiceA.java:12: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.OPTIONS;
[javac] ^
[javac] C:\Java\Temp\crmparts\src\java\freedom\bytecode\service\CrmPartsServiceA.java:13: error: package javax.ws.rs.core does not exist
[javac] import javax.ws.rs.core.Response;
[javac] ^
[javac] C:\Java\Temp\crmparts\src\java\freedom\bytecode\service\CrmPartsServiceA.java:14: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.GET;
I have no experience with the "Ant", so I have searched and found a lot about it, but I cannot seem to figure out how to get this library added so that the project gets properly build on ant.
I do not use maven or jenkins. My problem is only in those libraries, and the library is already added to projects/libraries.
My question is: how do I my that the Java "ant" compiler does not complain about missing packages (i.e. missing jar files)?
The problem was in my Dj2ee.server.home parameter. I made the correction and it worked.

Ant Build giving error when using the itext jars

[javac] symbol : method setDocumentFromString(java.lang.String)
[javac] location: class org.xhtmlrenderer.pdf.ITextRenderer
[javac] renderer.setDocumentFromString(html);
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
Im getting this error .im using itext jars with ant build
de.huxhorn.lilith.3rdparty.flyingsaucer.core-renderer-8RC1.jar /
itext-2.0.8.jar
This works fine with PSVM ...And no complie errors shown in the ide..
but when i runnig the ANt build this error is appearing..
Why is this happening ??
The dependent jar may not be added correctly to your build classpath and your IDE has it in the build path.
It looks like the org.xhtmlrenderer.pdf.ITextRenderer class in the jar that is resolved by Ant build doesn't include the method 'setDocumentFromString'
Can you please take a look on your jar and ensure that the method is really there?

robotium test project builds in eclipse but not in ant

How do I configure ant to include class files from a separate project / separate directory structure?
I am trying to build an robotium android test project with ant. The test project references not the robotium jars but the robotium source code, which I have modified slightly (added a method and some logging). However when I try and run an ant debug right now, the compiler isn't seeing the robotium code.
How do I tell ant to include those robotium classes from the other directory? In eclipse it's working fine, as I have the robotium project in the build path. Looking for the equivalent in ant.
Thanks!!
-compile:
[javac] Compiling 3 source files to /Users/swolfe/Documents/git/android/automation-suite/sandbox/bin/classes
[javac] /Users/swolfe/Documents/git/android/automation-suite/sandbox/src/com/foobar/bookings/test/SearchTestHoneycomb.java:9: package com.jayway.android.robotium.solo does not exist
[javac] import com.jayway.android.robotium.solo.Solo;
[javac] ^
[javac] /Users/swolfe/Documents/git/android/automation-suite/sandbox/src/com/foobar/bookings/test/SearchTestHoneycomb.java:15: cannot find symbol
[javac] symbol : class Solo
[javac] location: class com.foobar.bookings.test.SearchTestHoneycomb
[javac] private Solo solo;
[javac] ^
[javac] /Users/swolfe/Documents/git/android/automation-suite/sandbox/src/com/foobar/bookings/test/SearchTestHoneycomb.java:23: cannot find symbol
[javac] symbol : class Solo
[javac] location: class com.foobar.bookings.test.SearchTestHoneycomb
[javac] solo = new Solo(getInstrumentation(), getActivity());
[javac] ^
[javac] 3 errors
You can jar modified Robotium classes, and put this file to sandbox/libs

Lucene: Cannot find symbol

I am using Lucene 3.4.0, hibernate (hibernate-all.jar), ANT and TestNG to run some test...
Most of all works right now, but since I have implemented my lucene part nothing seems to work when I use ant command... I'm kind of lost here.
Because everything works perfectly locally. I can run my test, compile, etc. As soons as, I try to build with ant, I get this error "cannot find symbol" for contructor StandartAnalyzer(version.), etc...
But like I said, everything works on eclipse... At first, I had an method not found error, but fixed it because hibernate is not compatible with the latest version of lucene. So I upgraded hibernate... but now, I get this.
Thank you. If you need more information plz ask.
$ ant explode
Buildfile: c:\DuplicateBugFinder\dbf\build.xml
init:
groovy.compile:
groovy.copy:
compile:
[javac] c:\DuplicateBugFinder\dbf\build.xml:156: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=l
st; set to false for repeatable builds
[javac] Compiling 27 source files to c:\DuplicateBugFinder\dbf\exploded-archives\dbf.ear\dbf_jar
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
6: cannot find symbol
[javac] symbol : constructor StandardAnalyzer(org.apache.lucene.util.Version)
[javac] location: class org.apache.lucene.analysis.standard.StandardAnalyzer
[javac] Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
[javac] ^
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
2: cannot find symbol
[javac] symbol : constructor QueryParser(org.apache.lucene.util.Version,java.lang.String,org.apache.lucene.analysis.Analyzer
[javac] location: class org.apache.lucene.queryParser.QueryParser
[javac] new QueryParser(Version.LUCENE_34, "title", analyzer)
[javac] ^
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
9: cannot find symbol
[javac] symbol : constructor IndexSearcher(org.apache.lucene.store.Directory,boolean)
[javac] location: class org.apache.lucene.search.IndexSearcher
[javac] searcher = new IndexSearcher(index, true);
[javac] ^
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
00: cannot find symbol
[javac] symbol : method search(org.apache.lucene.search.Query,org.apache.lucene.search.TopScoreDocCollector)
[javac] location: class org.apache.lucene.search.IndexSearcher
[javac] searcher.search(q, collector);
[javac] ^
[javac] 4 errors
BUILD FAILED
c:\DuplicateBugFinder\dbf\build.xml:156: Compile failed; see the compiler error output for details.
It's probablly a difference in the classpathes used by Eclipse and by Ant respectively. Check what jars are you exactly using inside Eclipse (what libraries are added to the project) and then what jars you use in your declared Ant classpath when you build with that. Also check that you're using the same JDK in Eclipse and Ant. If either of the two differ, change Ant ones to be like Eclipse (since that's the environment that does work)
Check the ant classpath for multiple versions of Lucene library. Do ant -diagnostics to check the ant environment.
Ok fixed it. I needed to add the jar file in my lib/test (I'm using seam framework). In eclipse, everything was working because I was pointing to the jar in my run configurations for TestNG. When I was running the command "ant test" no jar was found...
So thanks to everyone.
Plus, for those of you who wants to make use of lucene and seam make sure too have no version incompatibilty. I had this problem for a long time. Finally, I found out that I had to use an older version of lucene (2.4.1) to work with seam 2.2. I didn't check yet for lucene 3.4 and seam 3...

Why javac task does not creates classes

I have an ant task that contains javac task inside. It reports about error in one of the classes, but the build doesn't fail, because it has failonerror="false". I suppose to see class files in the end of build, but I don't see it. Can anybody tell me why?
Properties used:
checkout.path=work/workingcopy
classpath.path=work/build/classes
log.file=work/log.txt
Ant code:
<record name="${log.file}" action="start"/>
<javac destdir="${classpath.path}" srcdir="${checkout.path}/src"
debug="true" failonerror="false">
<classpath>
<path refid="webinf.lib"/>
<path refid="tomcat.lib"/>
</classpath>
</javac>
<record name="${log.file}" action="stop"/>
Log file:
[javac] Compiling 169 source files to C:\work\build\classes
[javac] C:\work\workingcopy\src\com\mycompany\exception\handlerException\CustomExceptionHandler.java:25: cannot find symbol
[javac] symbol : class RequestContextImpl
[javac] location: package org.primefaces.context
[javac] import org.primefaces.context.RequestContextImpl;
[javac] ^
[javac] C:\work\workingcopy\src\com\mycompany\exception\handlerException\CustomExceptionHandler.java:103: cannot find symbol
[javac] symbol : class RequestContextImpl
[javac] location: class com.mycompany.exception.handlerException.CustomExceptionHandler
[javac] new RequestContextImpl(ec);
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors
[javac] Compile failed; see the compiler error output for details.
The failonerror option is for Ant not for javac. So if failonerror=false then Ant will continue your task even javac returns an error.
From the docs:
failonerror Indicates whether compilation errors will fail the build; defaults to true.
The build is Ant's build process not javac's !
Use Eclipse Java Compiler (EJC) instead of standard Oracle javac. One of ECJ advantages over javac is that it is permissible of errors, it tries to compile as much as possible and keeps already generated class files. With javac it is everything or nothing.
EJC was developed for use in IDE, for highly interactive work where partial compilation is a must, but it can also be used as CLI or Maven plugin. Plexus guys provide EJC as a handy Maven dependency.
For example configuration of ECJ in Maven, a partial compilation, check my answer to this question:
Maven: partial compilation before code generation
I've had same problem. And that is soluion I've found on the Web
This depends on the compiler that you are actually using. If you're using
javac 1.3, this is what Sun does by design. (see
http://java.sun.com/j2se/1.3/docs/tooldocs/tools-changes.html for more
information, specifically the last paragraph of the first bullet.)
Try using an older compiler or using the jikes compiler from IBM. Both
javac 1.2.2 and jikes 1.13 will produce output for classes that do compile,
even if another file in the fileset doesn't.
Jay
Best regards,
Michael

Categories