17

When I tried to compile build.xml file, below error is hitting:

BUILD FAILED

C:\Users\workspace\testrepo\src\build.xml:36: Compile failed; see the compiler error output for details.
    at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1150)
    at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)

Can someone help me ?

karthik
  • 17,453
  • 70
  • 78
  • 122
user1121120
  • 181
  • 1
  • 2
  • 8
  • 1
    Looks like the actual error message might be higher up than we can see, all this tells us is that build.xml failed somewhere around line 36, which I guess is where it tries to compile your Java source code. There must be something wrong with your Java code, do you use an IDE? – Ewald Dec 29 '11 at 12:24
  • In my logs, I have got [javac] C:\Users\workspace\testrepo\src\testrepo\testrepoclass.java:3: error: package org.junit does not exist [javac] import org.junit.After – user1121120 Dec 29 '11 at 12:53

5 Answers5

6

There is a compile error that occurred earlier during the build. Look for that error in the same output log file and try to fix it.

AbdullahC
  • 6,649
  • 3
  • 27
  • 43
  • Thank you for the answer. I got one warning warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds. Is it because of that warning?? – user1121120 Dec 29 '11 at 12:27
  • Nope, that shouldn't be the problem. – AbdullahC Dec 29 '11 at 12:30
  • In my logs, I have got [javac] C:\Users\workspace\testrepo\src\testrepo\testrepoclass.java:3: error: package org.junit does not exist [javac] import org.junit.After; – user1121120 Dec 29 '11 at 12:33
  • Yep...that's the problem. Including the JUnit jar in javac's classpath should fix the issue. – AbdullahC Dec 29 '11 at 12:35
  • I copied the Jnuit Jar files and pasted in C:\eclipse\jre\bin which is the JAVA_HOME path. Even then I am getting the same problem. – user1121120 Dec 29 '11 at 12:42
  • Try pasting it in the Java lib directory. – AbdullahC Dec 29 '11 at 12:43
  • I pasted in C:\eclipse\jre\lib. But even then same error is displaying. – user1121120 Dec 29 '11 at 12:49
  • Hmm...I guess javac is using a different lib directory on your machine. It might be C:\eclipse\lib, or it might be something else. Alternatively, you could add the path to the jar in the classpath attribute of the javac task. – AbdullahC Dec 29 '11 at 12:58
  • '-classpath' 'C:\Users\workspace\testrepo\build; C:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib\ant-antlr.jar; C:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib\ant-junit.jar; C:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib\ant-junit4.jar C:\eclipse\jre\lib\tools.jar; C:\eclipse\plugins\org.eclipse.swt.win32.win32.x86_64_3.7.1.v3738a.jar' '-sourcepath' 'C:\Users\workspace\testrepo\src\testrepo' '-g:none' The ' characters around the executable and arguments are not part of the command. [javac] File to be compiled: In the classpath, so junit are all there – user1121120 Dec 29 '11 at 13:16
  • @user1121120: I don't see the `junit-4.xx.jar` in the classpath - the `ant-junit` jars are definitely different. – AbdullahC Dec 29 '11 at 13:19
  • I pasted junit.jar in C:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib location,C:\eclipse\jre\lib location, C:\eclipse\jre\bin location and C:\eclipse\configuration\org.eclipse.osgi\bundles\39\1\.cp\lib locations. Still in the log file, i cannot see junit in the classpath and still the same error is displaying and also I restarted eclipse after doing each and every changes.:( – user1121120 Dec 29 '11 at 13:41
  • @user1121120: Where is javac present on your machine? You'll need to place it in the lib directory corresponding to that. – AbdullahC Dec 29 '11 at 13:45
  • Javac.exe is present in C:\eclipse\jre\bin location. In eclipse, I have configured the JAVA_HOME path as C:\eclipse\jre\bin. – user1121120 Dec 29 '11 at 13:48
  • @user1121120: Since it doesn't seem to work that way, try adding junit explicitly to the classpath. Use the classpath attribute of the javac task. To begin with, you can hardcode the whole path you pasted above and add the path to the junit jar to it. – AbdullahC Dec 29 '11 at 14:08
3

To see compiled error in log use below given command:

d:\yourdirectory of checkout>ant clean deploy>log.txt

It will create a complete log in your check out directory. So now you can check actual errors there.

Fjodr
  • 919
  • 13
  • 32
2

The following solution worked out good for me:

1) Define the following class:

package somepackage;

import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.types.Commandline;
import org.eclipse.jdt.core.JDTCompilerAdapter;

public class JDTCompiler15 extends JDTCompilerAdapter {
    @Override
    public void setJavac(Javac attributes) {
        if (attributes.getTarget() == null) {
                attributes.setTarget("1.6");
        }
        if (attributes.getSource() == null) {
                attributes.setSource("1.6");
        }

        super.setJavac(attributes);
    }
        // THIS METHOD IS RESPONSIBLE FOR PRINGTING THE ERRORS/WARNING.
    @Override
    protected void logAndAddFilesToCompile(Commandline cmd) {
        super.logAndAddFilesToCompile(cmd);
        System.err.println(cmd.toString());
    }

}

2) Add the following VM parameter: -Dbuild.compiler=somepackage.JDTCompiler15

Dudu Yanay
  • 21
  • 1
  • Thanks that saved me time :D Consider extending this code by: 'boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString() .indexOf("-agentlib:jdwp") > 0; if (isDebug) { logger.debug(cmd.toString()); } ' – Pwnstar Mar 02 '17 at 10:54
0

If you are using Weblogic to generate the client, you must add the "weblogic.jar" from the installation directory into the Additional Classpath, so Ant will know where the Ant.tools.... exist.

I got the same issue and I am trying to solve this problem not adding it as additional classpath since I copy all jars into my project, but still getting this error.

0

In my case, there was an unused import statement in a class whose package cannot be found elsewhere but was copied over because I copied the class from another project of mine. Be it was listed in the error log as "package not found" even if the error log itself wasn't clear-cut. I had to search through all the warnings the log generated in my case.

Catherine Austria
  • 161
  • 1
  • 3
  • 10