Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:26:44+00:00 2026-05-24T16:26:44+00:00

My situation is somehow interesting. I am trying to use Ant to make a

  • 0

My situation is somehow interesting. I am trying to use Ant to make a jar file. However, I don’t want every single java file to be compiled. My source code has strcuture something like this:

src
-Contact.Java
-Contact.hbm.xml
-AnotherClass.Java

So, what I want to have in my jar file is as follow:

myjar.jar
-com
--me
---Contact.Class
---Contact.hbm.xml

I don’t want AnotherClass.Class to be there.

Is it possible doint that with Ant ?

The best I come up with is like this:

<target name="condition-hibernate" description="check if there is a java and hbm file then call for compile-hibernate">
    <condition property="condition">
    <available file="**/*.hbm.xml" />
    </condition> 

<antcall target="condition-hibernate-part2"/>

</target>   

<target name="condition-hibernate-part2" description="check if there is a java and hbm file then call for compile-hibernate">
    <javac srcdir="${source.dir}" destdir="${hibernate.dir}">
</target>

I don’t think that I can use Ant to solve my problem as I can’t tell Ant what to compile and what not (I can using exclude and include) but I want to tell Ant compile only files that have an *.hbm.xml file next to them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:26:45+00:00Added an answer on May 24, 2026 at 4:26 pm

    I don’t know how to achieve this with Ant’s built-in selectors.

    However, if you cannot work around this in any other way you could implement a custom selector that checks if the .java file has a corresponding .hbm.xml file, e.g.

    public class CorrespondingHbmSelector implements FileSelector {
      public boolean isSelected(File basedir, final String filename, File f) {
        Pattern p = Pattern.compile("^(.+).java$");
        Matcher m = p.matcher(filename);
        boolean matches = m.matches();
        if (!matches) {
          return false;
        }
        final String basename = m.group(1);
        String[] foundFiles = basedir.list(new FilenameFilter() {
          @Override
          boolean accept(File dir, String name) {
            return name.startsWith(basename) && name.endsWith(".hbm.xml");
          }
        });
        return foundFiles.length > 0;
      }
    }
    

    Use it in your build.xml like an include

    <typedef
      name="correspondinghbmselector"
      classname="CorrespondingHbmSelector"
      classpath="${mydomain.classes}"/>
    
    <javac srcdir="${source.dir}" ...>
      <correspondinghbmselector/>
    </javac>
    

    This is just the basic idea. (I didn’t test the code.)

    The better way would be to avoid such complex dependencies in your build.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the situation: I use the Java API of Selenium 2 to open
I have situation when I need to communicate with Java process somehow. Java handling
Here's my situation: I have a file, homepage.php, that I want to allow my
Situation is you have to develop an application against an Active Directory Tree. Want
Situation: I want to provide a website service where users can enter some data
I'm not entirely sure how I got to this situation but somehow I'm getting
Situation is: Admin logs in to system and he changes product somehow. For example:
somehow I've ended up in a situation such that when I navigate through source
I have this situation: I am trying to remove an old avatar image for
I have the following situation, I am trying to add a toolbar ( Ext.toolbar.Toolbar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.