I want to build a web project (war) with Apache Ant. The project has dependencies to classes in javax.ejb and similar packages which are included in my server runtime. So building with eclipse works fine. However, when trying to build the war with Apache Ant, the following error occurs:
[javac] ...\Test.java:3: error: package javax.ejb does not exist
[javac] import javax.ejb.Timeout;
[javac] ^
[javac] ...\Test.java:7: error: cannot find symbol
[javac] #Timeout
[javac] ^
[javac] symbol: class Timeout
[javac] location: class Test
[javac] 2 errors
You can reproduce the problem with the following minimal example.
Test.java
import javax.ejb.Timeout;
public class Test {
#Timeout
public void test() {}
}
build.xml
<project name="Test" default="compile">
<target name="compile">
<mkdir dir="build"/>
<javac srcdir="src" destdir="build" />
</target>
</project>
I know this can be solved by adding the server runtime to the classpath, but since I want to build the project on a Jenkins server where no server runtime exists, I was wondering if there is any possibility to build this project without the runtime.
Related
I reinstalled between jdk-8 and jdk-12, the building process shows different errors but both failed. And both are showing in the log that the bcel package is missing as the first error.
I've set JAVA_HOME in both jdk with the corresponding value;
sh build.sh -Ddist.dir=~/tmp/ant dist
this is the code I get from the org document for building.
Loading source files for package org.apache.tools.tar...
Loading source files for package org.apache.tools.zip...
Constructing Javadoc information...
/home/uppdev/tmp/ant/src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java:23: error: package org.apache.bcel.classfile does not exist
import org.apache.bcel.classfile.ClassParser;
^
/home/uppdev/tmp/ant/src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java:24: error: package org.apache.bcel.classfile does not exist
import org.apache.bcel.classfile.ConstantValue;
:
:
:
Building index for all the packages and classes...
Building index for all classes...
Generating /home/uppdev/tmp/ant/build/javadocs/help-doc.html...
Note: Custom tags that could override future standard tags: #todo. To avoid potential overrides, use at least one period character (.) in custom tag names.
26 errors
100 warnings
BUILD FAILED
/home/uppdev/tmp/ant/build.xml:1012: The following error occurred while executing this line:
/home/uppdev/tmp/ant/build.xml:1520: Javadoc returned 1
Total time: 20 seconds
If this is for ant 1.10.2 then I can provide info:
JDK8 returns an error for missing references in javadocs (see https://bugs.openjdk.java.net/browse/JDK-8224266) which can be maded non-fatal by passing -Xdoclint:none to javadoc.
ant 1.10.2 removed this flag together with the configure param withDoclint which made builds fail if the optional dependencies were not found.
A workaround is to add additionalparam="-Xdoclint:none" to the <javadoc ...> tag in the <target name="javadocs" in build.xml before building.
Fixed part of 1.10.2:
<target name="javadocs" depends="check-javadoc"
description="--> creates the API documentation" unless="javadoc.notrequired">
<mkdir dir="${build.javadocs}"/>
<javadoc additionalparam="-Xdoclint:none"
useexternalfile="yes"
destdir="${build.javadocs}"
failonerror="true"
author="true"
version="true"
locale="en"
windowtitle="${Name} API"
doctitle="${Name}"
maxmemory="1000M"
verbose="${javadoc.verbose}">
I am using javac in ant to compile a project and I am getting an compilation error message without the file or line number. Why is this and how can i find where in the (large) project the problem is?
build.xml
make_folders:
compile:
[javac] Compiling 33 source files to *project root*/bin/classes
[javac] error: incompatible types: String cannot be converted to Integer
[javac] Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
[javac] 1 error
BUILD FAILED
*project root*/build.xml:33: Compile failed; see the compiler error output for details.
And heres the relevant lines with verbose set to true:
[javac] [loading ZipFileIndexFileObject[/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/lib/ct.sym(META-INF/sym/rt.jar/java/util/Date.class)]]
[javac] error: incompatible types: String cannot be converted to Integer
UPDATE:
So I managed to figure out that the error it was originating from calling a function in a class from within an inner class in said outer class. I'm not sure why this produced an error or why it was presented with such little information so any help would still be appreciated.
I'm compiling many legacy Java code probably written with Java1.3 and I got tons of errors like this:
Copydir.java:128: warning: as of release 5, 'enum' is a keyword, and may not be used as an identifier
[javac] (use -source 5 or higher to use 'enum' as a keyword)
[javac] Enumeration enum = filecopyList.keys();
It's too time consuming to replace each instance of enum with _enum so I added source="1.3" in ant javac task as below (based on examples from http://ant.apache.org/manual/Tasks/javac.html). But I still got the same compile error. I've tried to change source = 1.4,1.5, and still same error.
<javac srcdir="${src.dir}"
destdir="${build.classes}"
debug="true" debuglevel="lines,vars,source"
source="1.3"
deprecation="off"
optimize="on">
What is the right way to tell comiler that the source is written in 1.3, but I want to compile it to run in 1.6? I'm using jdk1.6.0.26 and ant 1.8.2
That's a warning, not an error. Unless there are other errors in the build that should work just fine.
I am trying to compile the canonical metamodel classes for some JPA entities using an ant script. I am using OpenJPA. I would like the generated files to be located in a subdirectory which, according to the OpenJPA documentation, I can do by specifying the -s option for javac. The way I am trying to do this right now is like this:
<compilerarg value="-s c:\buildfiles"/>
However, I keep getting an error that says:
javac: invalid flag: -s
Usage: javac <options> <source files>
If I do:
<compilerarg value="-version"/>
it tells me that I am using 1.6. And if I do:
<compilerarg value="-help"/>
it lists -s as a valid option. Does anybody have any advice on what I can do to accomplish what I'm trying to do? Thank you!
You have two args in there, with a space between them. You just need to separate them:
<compilerarg value="-s"/>
<compilerarg value="c:\buildfiles"/>
At the moment you're parsing the single arg "-s c:\buildfiles". If you run
ant -verbose
you can verify this - you'll see something like:
[javac] Compilation arguments:
[javac] '-classpath'
[javac] ''
[javac] '-sourcepath'
[javac] '/a/b/c'
[javac] '-target'
[javac] '1.5'
[javac] '-g:none'
[javac] '-s c:\buildfiles' <-- here is the problem
[javac] '-source'
[javac] '1.5'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
I am trying to run a build file using Ant. I am using Maven for dependencies. I am having a testNG dependency in my project.
This is the pom.xml file
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.anova.abis</groupId>
<artifactId>maven-pom</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>My first Maven POM</name>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</project>
The maven downloads the testNG from mavenrepository, but I am getting an error, it is complaining that it can not find org.testng.Assert and org.testng.annotations.Test. (as below)
Compiling 10 source files to /home/shahin/Files/Development/Ant/ServiceEJBSample3/bin
[javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/ejbModule/net/company/test/Service1Test.java:5: package org.testng does not exist
[javac] import org.testng.Assert;
[javac] ^
[javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/ejbModule/net/company/test/Service1Test.java:6: package org.testng.annotations does not exist
[javac] import org.testng.annotations.Test;
[javac] ^
[javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/ejbModule/net/company/test/Service1Test2.java:5: package org.testng does not exist
[javac] import org.testng.Assert;
[javac] ^
If I don't use maven and simply use ant and specify the location where the testNG.jar file is, there is no problem at all. I have used the same .jar file that maven downloaded for Ant to make sure I am using the same source. I also have tried different versions of testNG from maevnrepo. Any insights ?
Do I need to include all dependencies (all different packages? like org.testng.Assert and org.testng.annotationsTest and as such) in the POM file? or just the one is enough? If I need to have all of them listed in POM file, what is the best and fastet way of doing it?
Works for me. Did you do a mvn clean first? Maybe the dependency isn't getting downloaded.
Your pom.xml looks correct, maybe your repository got corrupt somehow, I suggest rm -rf ~/.m2 or if you don't want to download the entire Internet, start by just removing the TestNG dependencies only.
I have cleaned the maven and revised the build.xml file once again, it works now. Probably it was something wrong in the repository. Thanks all for your input.