Has anyone used Ant4Eclipse with Project Lombok? - java

Has anyone successfully used Ant4Eclipse (http://www.ant4eclipse.org/) in combination with Project Lombok (http://projectlombok.org/)?
Lombok provides annotations for removing boilerplate code; however, it doesn't appear to play nicely with Ant4Eclipse (headless compilation of Eclipse projects). For instance, the following Lombok sample compiles fine in Eclipse and javac:
import lombok.Getter;
public class LombokTest {
private #Getter String foo;
public LombokTest() {
String s = this.getFoo();
}
}
But compiling with Ant4Eclipse's <buildJdtProject> yields the following:
[javac] Compiling 1 source file
[javac] ----------
[javac] 1. WARNING in C:\dev\Java\workspace\LombokTest\src\LombokTest.java (at line 4)
[javac] private #Getter String foo;
[javac] ^^^
[javac] The field LombokTest.foo is never read locally
[javac] ----------
[javac] 2. ERROR in C:\dev\Java\workspace\LombokTest\src\LombokTest.java (at line 8)
[javac] String s = this.getFoo();
[javac] ^^^^^^
[javac] The method getFoo() is undefined for the type LombokTest
[javac] ----------
Has anyone successfully used these libraries together?
Thanks!
Edit: sample project demonstrating the issue

I eventually managed to compile a lombok project with ant4eclipse by delomboking the project first with
<delombok verbose="true"; encoding="UTF-8"
to="${workspaceDirectory}/myproject/src"
from="${workspaceDirectory}/myproject/src-original" />

IIRC in order to use Lombok in Eclipse, there's a parameter required at start-up to introduce Lombok's Java Agent into the JDT compile process. This is normally specified in the eclipse.ini file. If Ant4Eclipse does not also make use of those parameters (I don't see why it would) you may have to specify the -javaagent:lombok.jar parameter for that too.
DISCLAIMER: this is only a guess.

Supplied project does not compile out of the box with Eclipse Java EE 3.5.2 using Java 6. The errors in Eclipse are the same as those given by ant4eclipse.

Related

assertNotEquals static import causing compile error

I have a file Foo.java which compiles with no errors. But when I add the single line
import static org.junit.Assert.assertNotEquals;
This causes the following error from my ant build:
compileTests:
[javac] Compiling 27 source files to C:\example\bin
[javac] C:\example\src\Foo.java:7: error: cannot find symbol
[javac] import static org.junit.Assert.assertNotEquals;
[javac] ^
[javac] symbol: static assertNotEquals
[javac] location: class
[javac] 1 error
I am using JUnit 4.4. junit-4.4.jar is included in the classpath for the javac task.
I have tried running different compiler versions with the flags -Dbuild.compiler=javac1.7 and -Dbuild.compiler=javac1.8 but it makes no difference. I still get the exact same error.
assertNotEquals is the only static import from Assert that causes this error.
I have already seen this post Java static import causing compile error. Probable compiler bug?
and I tried importing Assert on its own and prepending each assert statement with Assert. like this post suggested. I got the same error, this time at the method call for Assert.assertNotEquals()instead of the import statement.
The import successfully compiles and runs on Eclipse, however.
Does anyone have any ideas about the cause of this? I'd like to get to the bottom of this instead of having to implement a workaround solution.
You are using Junit 4.4. AssertNotEquals wasn't added until 4.11
JUnit 4.11 release Notes
If you update to the latest JUnit jar. the compiler error should go away. Eclipse is probably using its own built in version that has the latest methods.

Project compiles with Ant. But if I open eclipse, the project no longer compiles

I'm on Windows.
I downloaded the source to a java project (Plovr) and I can build it with ant using cygwin.
But just opening it in Eclipse means it will never build again. If I open it in Eclipse and then close it again, it will no longer build. I also can't add files that were written in Eclipse.
Output:
javacc:
compile:
[javac] Compiling 7 source files to C:\Users\Bryana\plovr\pulled\plovr-master\build\classes
[javac] C:\Users\Bryana\plovr\pulled\plovr-master\closure\closure-stylesheets\build\genfiles\java\com\google\common\css\compiler\ast\GssParserCC.java:345: error: cannot access Type
[javac] public CssBooleanExpressionNode buildBoolExpressionNode(CssBooleanExpressionNode.Type type,
[javac] ^
[javac] bad class file: C:\Users\Bryana\plovr\pulled\plovr-master\build\classes\com\google\common\css\compiler\ast\CssBooleanExpressionNode$Type.class
[javac] bad signature: ▒3i
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
BUILD FAILED
Using: jdk1.7.0_40 , Apache Ant(TM) version 1.9.2 , Eclipse Juno Service Release 2
Found this: http://suneelgv.wordpress.com/2011/02/17/java-lang-classformaterror-invalid-constant-pool-index-63-bad-class-file/ referring to that http://mail-archives.apache.org/mod_mbox/cayenne-user/200804.mbox/%3C0JZC008038T159#mail.uni-rostock.de%3E.
In your case the filterset or similar on-the-fly modification during copying - accidentally including class files - might not do any harm with Unix but convert line endings on Windows.

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?

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