I am trying to run an Maven Ant Task with plugin version 2.1.3 and for some reason running into this error:
[javac] Compiling 101 source files to /home/raido/Workspace2/foobar/classes
[javac] error: error reading /home/raido/.m2/repository/foobar/1.0/foobar-1.0.pom; error in opening zip file
[javac] 1 error
Why is it trying to read a xml file as an zip file and how can I avoid this? The file itself is perfectly fine and readable.
That part from the build.xml file:
<target name="compile" depends="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<javac classpathref="compile.dependency.path" debug="on"
encoding="UTF-8"
deprecation="on" destdir="${classes.dir}"
includes="bar/**/*.java" optimize="off"
srcdir="${src.dir}" />
</target>
The error is targeted to the closing sign > on the srcdir row i.e. the whole tag.
It might be corrupt zip. you can remove the foobar/1.0/ dir from your maven repos and let maven download new fresh version
Show us your definition of compile.dependency.path. Seems like the pattern there is not quite correct and allows .pom files (if it's **/**, for example), which will clearly not work.
I finally figured it out. The problem was that the main ant file had a specific task that produced JAR-s of the modules but I hadn't done it. This shows how important documentation sometimes is which this project doesn't have at all!
Related
My ant has:
<target name="createJava">
<javac ... />
</target>
<target name="build" depends="createJava, compile" />
The createJava task adds a few java files under src root.
However, main build target always compile except them. How can I add java files created in the middle of build?
Looks like the files for "compile" has been set before "createJava" and no updated before "compile".
Our application is built my Hudson from Ant scripts. In my latest work I've recently included Maven. Now Hudson's build process fails when it reaches the compilation task without any explanation.
Hudson build:
[echo] Using Maven Repo at ../.maven/repo/
[javac] Compiling 134 source files to C:\Users\administrator1\.hudson\jobs\SAP_RC\workspace\current\classes
BUILD FAILED
C:\Users\administrator1\.hudson\jobs\SAP_RC\workspace\current\build.xml:68: Error running C:\Program Files (x86)\Java\jdk1.8.0_66\bin\javac.exe compiler
Ant script:
<javac classpathref="lib" destdir="${classesDir}" debug="true" debuglevel="lines,vars,source" verbose="true" fork="true" nowarn="true" memoryMaximumSize="320m" srcdir="${srcDir}" includeantruntime="false" />
I specifically included the Maven repo into the classpath, and that's when it fails inexplicably. When I remove the Maven repo the build throws a compilation error complaining that it can't find Maven dependencies. This makes me suspect that I'm hitting some classpath length limit.
I did it this way because I'm not sure what is the correct way to include Maven dependencies into the classpath. If there is a better way please tell me and I'll open a new question specifically for that.
It seems as though my wildcard in my fileset was the culprit.
<path id="lib">
<fileset dir="${env.maven_repo}">
<include name="*/**"/>
</fileset>
</path>
I changed the ** to *.jar and the build process is no longer (inexplicably) failing.
<path id="lib">
<fileset dir="${env.maven_repo}">
<include name="*/*.jar"/>
</fileset>
</path>
I need open this application-->
Decision tree
I have used netbeans and it has not worked, so I have installed eclipse and it seems that the file recognizes me.
What I do is import that application from Github, until there everything perfect, the problem is that when I give it to run, it does not work.
One problem I get is the following:
Buildfile: C:\Users\user1\workspace\Arbolito\java-decision-tree-master\build.xml
compile:
[javac] Compiling 9 source files to C:\Users\user1\workspace\Arbolito\java-decision-tree-master\build\classes
BUILD FAILED
C:\Users\user1\workspace\Arbolito\java-decision-tree-master\build.xml:19:
C:\Users\user1\workspace\Arbolito\java-decision-tree-master\lib
does not exist.
Total time: 550 milliseconds
I put the line of code in the XML file that gives me the problem
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false" debug="on" />
</target>
Does anyone know how to run the program?
Create a lib folder in your project and include SL4J and Junit jar in that folder.
I have an Android Library project, AndroidLib, that depends on a Java project in my workspace, JavaLib.
In Eclipse this is done by adding the JavaLib project to Java Build Path > Projects for AndroidLib and setting it to be exported in the Order and Export tab, and it builds fine.
However Ant doesn't seem to pick up the dependency on the JavaLib project when building AndroidLib (I have run android update lib-project). What is the best way to add this dependency to my build.xml?
I had the same problem. I ended solving it in a very hackish way.
In AndroidLib/build.xml (or better in AndroidLib/custom_rules.xml), I defined a -pre-build target that builds the JavaLib and copies the resulting jar in libs/. I also defined a -post-package target to remove the copied jar, otherwise Eclipse will get confused.
<property name="lib.javalib.project.dir" location="${basedir}/../JavaLib" />
<target name="-pre-build">
<subant buildpath="${lib.javalib.project.dir}" target="package" failonerror="true" />
<copy todir="${basedir}/libs" failonerror="true" verbose="true">
<fileset dir="${lib.javalib.project.dir}/target">
<filename name="javalib*.jar"/>
</fileset>
</copy>
</target>
<target name="-post-package">
<delete verbose="true">
<fileset dir="${basedir}/libs" includes="javalib*.jar" />
</delete>
</target>
This solution is far from satisfying, but it gets the job done.
You will find a similar question and answer there : Android Ant Include Java Library projects
I'll answer my own question: the only way to do this properly is to not use Ant.
You need a proper dependency management system. Maven is your only real choice here.
You need a build system that supports Maven. I currently use Maven again for this, because at the time it was the only mature build tool that also supported Maven dependency management -- now (albeit for Android Library Projects, since the format for these is not yet final) Gradle should be your build tool of choice.
I changed my build.xml to run the java project's ant file and then copy the jar to the libs folder:
<target name="-pre-compile">
<ant antfile="build.xml" dir="dependencies/JavaUtils" target="clean"/>
<ant antfile="build.xml" dir="dependencies/JavaUtils"/>
<copy todir="${jar.libs.dir}" failonerror="true" file="dependencies/JavaUtils/dist/Java-utils.jar"/>
<sleep seconds="3"/> <!-- Delay for the file to be recognized after the copy -->
</target>
How this helped someone.
BTW, I started reading about Gradle's dependency/build/whatever system and got the creeps from it. Ahhh, what a relief to get back to ant...
My java application uses log4j for logging. Using ant the project builds successfully, but I am unable to run it. The error I get is
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/Log
.........
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
My classpath contains the log4j jar.
[echo] ..../apache-log4j-1.2.15/log4j-1.2.15.jar: .....
My ant version is 1.7.1. What am I missing?
[Edit] My application is referencing another project which required the commons logging jar. So I tried creating an executable jar of the referenced project so that all the dependencies are carried over. The ant task to create the executable jar is as follows:
<target name="executablejar" depends="compile">
<delete file="${dist}/app.jar" />
<javac debug="true" srcdir="${src}" destdir="${classes}" classpath="${javac.classpath}"/>
<copy todir="classes" flatten="true">
<path>
<pathelement path="${javac.classpath}"/>
</path>
</copy>
<jar jarfile="${dist}/app.jar" basedir="${classes}" />
</target>
However the error still persists. Am I creating the executable jar correctly?
You may have inadvertently imported a class from org.apache.commons.logging and now, as you might expect, the JVM is expecting to find the class definition on your classpath at runtime.
I'd recommend looking for usages of the commons-logging package in your code.
You'll have add apache commons logging to your classpath. The package org.apache.commons.logging is not part of log4j.