Create java library with Ant -


I am trying to put some classes in a jar for use as a library.

In this exam, I am trying to have a class, apiInterface , and this package is in project.api .

I was thinking here that I was misusing the library, as I was getting the "Package Project.Api is not present" on the import line, but it means that the jar Tf project.jar should be produced

  project / api / apiInterface.class   

while getting me

  apiInterface.class apiInterface.java   

> It is intended to include the Java file, but not necessary.

The relevant part of my build.xm

  & lt; Target name = "buildAPI" dependent = "" & gt; & Lt; Mkdir dir = "$ {Jar}" /> & Lt; Jar Destfile = "$ {Jar} / $ {ent. Project.name} -api.jar" & gt; & Lt; Fileset dir = "$ {bin} / $ {ant.project.name} / API" /> & Lt; Fileset dir = "$ {src} / $ {ent. Project.name} / API" /> & Lt; / Jar & gt; & Lt; / Target & gt;   

The compile successfully compile Java and in bin / project / API. Sets the square file.

In the jar file, the list of files under the directory specified in the fileset elements . Since you specify the directory as $ {bin} / $ {ant.project.name} / api , the job will only search under this directory and include the class file in the jar, That is, $ {Bin} / $ {ant.project.name} /api/apiInterface.class .

To include the directory corresponding to the package, simply $ {bin} in this case to point to the dir attribute root folder. Same for source files.

  & lt; Jar destfile = "$ {jar} / $ {ant.project.name} -api.jar" & gt; & Lt; Fileset dir = "$ {bin}" / & gt; & Lt; Fileset dir = "$ {src}" / & gt; & Lt; / Jar & gt;   

If only this package should be included (i.e. the other package should not be in jar), use the included attribute: < Pre> & lt; Jar destfile = "$ {Jar} / $ {ant.project.name} -api.jar" & gt; & Lt; Fileset dir = "$ {bin}" includes = "$ {ant.project.name} / api / *. Class" /> & Lt; Fileset dir = "$ {src}" includes = "$ {ant.project.name} / api / * .java" /> & Lt; / Jar & gt;

You can check the link from the Ant manual to use this function properly.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -