• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need to know what this error is all about?

 
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I am in desperate need of help to know how to use ant - even though I just read in the forum maven is the preferred tool but what to do.. i need money to pay bills so this contract job that i am working now is using an age old tool ant which I really have problem.

The tutorial I am using to learn is :

https://www.michael-thomas.com/tech/apache/ant/index.htm

so for the past few hours, I am trying to tackle the error to no avail  and I am not sure  why the build file is written this way....

https://i.imgur.com/YZL29t2.png

and then I tried to follow the SO - and added these lines in the xml file



it is the same error message.

And here's the file structure which I am not sure if it is correct because it is not mentioned in the tutorial.

https://i.imgur.com/dJ1oLuo.png

Hope I could get the answer here.

Tks.

 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have been around the Ranch long enough to know not to post screenshots of error messages. In the future, copy the text and post it directly. That's much easier to read, and can be quoted and copied.

The error message is really quite obvious: The build file is referring to a directory that does not exist. And indeed, the directory mentioned in the error message does not exist according to the screenshot of your file system. We can't say where your build file goes wrong, but apparently "${src.dir}" is set incorrectly.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:You have been around the Ranch long enough to know not to post screenshots of error messages. In the future, copy the text and post it directly. That's much easier to read, and can be quoted and copied.

The error message is really quite obvious: The build file is referring to a directory that does not exist. And indeed, the directory mentioned in the error message does not exist according to the screenshot of your file system. We can't say where your build file goes wrong, but apparently "${src.dir}" is set incorrectly.



Sorry I hope I will remember it guess I got so nervous about this job I am so scared that I can't perform I will have to go and the deadline given to me is so tight what with so much things I don't know in fact almost all the technologies stack involved I have no experienced at all.

I would like to ask if I should create a properties file like what is mentioned here ?


https://stackoverflow.com/questions/22615107/apache-ant-compile-javac-srcdir-does-not-exist



But, I do not know how to create a properties file.  Can you teach me how to create one and then this build file will know where to read the properties file ?

Thanks in advance.
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tangara, you've been on the Ranch for over 10 years. The mere fact that you're still asking questions tells us that you're not just filling a job slot, you're actively interested in the profession.

I don't know if Southeast Asia is participating in the "Great Resignation", but regardless, if your employers are that oppressive, then you might be well-advised to find more congenial ones.
 
Tim Holloway
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and properties files are very simple. They are just text file with name/value pairs in them. So things like this:

Note that Unix-style comments ("#") are supported and blank lines are ignored.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Oh, and properties files are very simple. They are just text file with name/value pairs in them. So things like this:

Note that Unix-style comments ("#") are supported and blank lines are ignored.



oh ok. But, how do i specify the build directory in fileset ?  There is like no tutorial on this at all in Apache Maven site and I have been surfing for an answer to no avail.  Really, if this goes on, what am i going to do.
 
<code>
<target name="clean" description="Clean output directories">
  <delete>
     <fileset dir="${build.dir}">    
     </fileset>
  </delete>
</target>
</code>

Is there anything wrong with the structure where the batch files, ant files and Java files reside ?

I hope you could tell me how to specify the build directory.
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:I hope you could tell me how to specify the build directory.


Where did you get the idea that there's anything wrong with the build directory? Read the error message very closely: it says that there is a problem with the "srcdir" parameter of the javac task. That parameter is set by "${src.dir}", and since the value of that parameter is a directory that doesn't exist, that's what you need to fix. Search the build file for "src.dir". It does have a value (although an incorrect one), so you should find it somewhere. If you're unsure about how Ant works, start reading at https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html. That example actually uses a "src.dir" parameter.
 
Tim Holloway
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're getting Ant and Maven confused here.

In Maven, you'd put your properties file under the project's /src/main/resources directory (or /src/main/webapp/WEB-INF/classes/ if you're building a WAR). You can also keep testing properties under /src/test/resources and so forth.

In Maven, the target is built into a directory named /target, which is created when you build if it doesn't exist and which is deleted when you do a Maven "clean".

In Ant, however, the only rules are the ones you make yourself. You can build anywhere you like in any way you like and where the sources are is also up to you to specify. Ant has no defaults or preferred locations or values.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:I think you're getting Ant and Maven confused here.

In Maven, you'd put your properties file under the project's /src/main/resources directory (or /src/main/webapp/WEB-INF/classes/ if you're building a WAR). You can also keep testing properties under /src/test/resources and so forth.

In Maven, the target is built into a directory named /target, which is created when you build if it doesn't exist and which is deleted when you do a Maven "clean".

In Ant, however, the only rules are the ones you make yourself. You can build anywhere you like in any way you like and where the sources are is also up to you to specify. Ant has no defaults or preferred locations or values.



Ant sounds powerful...i wish i can master it...but i have other things that i need to learn like XSD which is totally alien to me....and i am like so nervous as the clock tick away...

So, yesterday night based on your hints, I checked the error and created a src folder after the firststeps and the error stops.

BUT, I am not sure why it worked out this way.


C:\Users\xxx\ant\tutorial_firststeps_jar\src\firststeps



Another thing is based on the Ant manual - I ammended the ant build.xml to include the package name but still it failed to run the main class.

Hope you can give me some hints as to why it failed.


jar:
     [jar] Building jar: C:\Users\karen\ant\tutorial_firststeps_jar\src\firststeps\build\jar\HelloWorld.jar

run:
    [java] Error: Could not find or load main class firststeps.HelloWorld1
    [java] Caused by: java.lang.ClassNotFoundException: firststeps.HelloWorld1
    [java] Java Result: 1



Thanks.
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you set the classpath to include that class? Remember that we haven't seen your build file, so we can only speculate what's going on.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Have you set the classpath to include that class? Remember that we haven't seen your build file, so we can only speculate what's going on.



Hi Tim,

I am not getting the concept of Ant so I am trying to understand the Ant user manual rather than this tutorial that I found for beginner.

But, I don't quite get what is written in the user manual.

For example, on the Developing with Apache Ant



I can't make sense of the aboe.  Is mkdir dir = "build" a instructional step to Ant that makes Ant change the directory to build before building things which is linked to the next task - declare ?

I also dun get the part about javac srcdir="source" but there is no indication whereabout is the source so how on earth will Ant know?

Could you kindly let me know on the above.

Million thanks again.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:I am not getting the concept of Ant


The concept of Ant is simple - it's a build tool that does what you tell it to do, and nothing more. Those instructions come in the form of tasks, which are grouped in targets. That makes the following URL your #1 source of information: Overview of Apache Ant Tasks.

The documentation for those tasks can be overwhelming, especially if there are a lot of (optional) attributes. This is mostly a matter of reading what they all mean, and starting with only the required ones.

I can't make sense of the aboe.  Is mkdir dir = "build" a instructional step to Ant that makes Ant change the directory to build before building things which is linked to the next task - declare ?


mkdir, which shares its name with the same command-line interface command, creates a directory. That directory is called build, and it's relative to the current directory.

I also dun get the part about javac srcdir="source" but there is no indication whereabout is the source so how on earth will Ant know?


javac is the task to use to actual compile Java source code. The srcdir attribute tells the compiler where to find the source files. That should be the base of your package structure. In the example this is directory source in the current directory.
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That example isn't the simplest example though. The first target is - create the build directory if it doesn't exist yet, then compile all files in the source directory and place them in the build directory. The other tasks are for using your own tasks, but that's something I would stay away from for now. First get to know the basics before you start extending Ant.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:That example isn't the simplest example though. The first target is - create the build directory if it doesn't exist yet, then compile all files in the source directory and place them in the build directory. The other tasks are for using your own tasks, but that's something I would stay away from for now. First get to know the basics before you start extending Ant.



Hi Rob,

Thanks for the explaination.

So, I tried out the Ant tutorial - https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html,
specifically this one


but then I can't get it do the ant run.
I opened up the jar file and see that the main.class - oata.HelloWorld is inside the manifest but it is running on openJDK 11.  How on earth did Ant know since I did not indicate a openJDK 11 inside ?

Still, at the command prompt, I am still getting the error message :



C:\Users\abc\ant\test_ant2>ant run
Buildfile: C:\Users\abc\ant\test_ant2\build.xml

run:
    [java] Error: Could not find or load main class oata.HelloWorld
    [java] Caused by: java.lang.ClassNotFoundException: oata.HelloWorld
    [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 0 seconds



Where did I go wrong ? Tks so much for you guys who help me like that.
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you also create the Java source file that's listed at the top of the tutorial? And did you first run the compile and jar targets? Usually these targets are linked by depends attribute; the tutorial does that later in the "Enhance the build file" section.
 
Tim Holloway
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ant is basically just a programming language done in XML. Targets are goals that you can request and tasks are the instructions.

Ant comes pre-supplied with a set of standard tasks that you can use. You can also create custom task types of your own, but that should not be necessary here.

So the mkdir task makes a directory. The javac task runs the Java compiler. The jar task takes files and makes a JAR file out of them. And so forth.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Ant is basically just a programming language done in XML. Targets are goals that you can request and tasks are the instructions.

Ant comes pre-supplied with a set of standard tasks that you can use. You can also create custom task types of your own, but that should not be necessary here.

So the mkdir task makes a directory. The javac task runs the Java compiler. The jar task takes files and makes a JAR file out of them. And so forth.



Yesterday night I managed to make it run the HelloWorld and made it into jar with the enhanced build.xml by Ant tutorial.
The thing is I missed out the pre-project steps - putting the source code into the src folder.
Is there anyway to automate this part as well ? as in when I do a build, it will put all my source code into the src folder ?
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As was mentioned before, Ant is flexible about where stuff is. You can just adapt the build file to point to where your source code is, rather than having to put it where the build tool expects it (as Maven would require). That's what the srcdir parameter is for.

At this point I need to ask: if Ant is giving you such headaches, why are you using it? Why aren't you building this project in whichever way you build all your other projects? Surely the customer doesn't care how you do it.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:As was mentioned before, Ant is flexible about where stuff is. You can just adapt the build file to point to where your source code is, rather than having to put it where the build tool expects it (as Maven would require). That's what the srcdir parameter is for.

At this point I need to ask: if Ant is giving you such headaches, why are you using it? Why aren't you building this project in whichever way you build all your other projects? Surely the customer doesn't care how you do it.



Actually I am pretty worry I am dealing with old technologies cos now I understand concurrency is done controlling the JVM and can use parallism et except I have no chance to touch on all these.  But, I am in a contract job that requires me to handle old technologies...I guess my career sucks....

And it is running together with many batch file stuff which is all new thing to me.  Overall, I find the way the things set up are all closely tied up as in you can't remove something easily so all the parts are like tightly coupled together.... I am so sad I dun get to learn from the masters...if I get it then it will be gone from me somehow...as what happened to me on my first temp software developer job...but i have to be grateful even to step in...
 
Tim Holloway
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ant is only "old technology" in terms of age. The Tomcat JEE webapp server is built with Ant and they have no intention of changing that. It's also true that Maven does its best work when building generic-style Java artefacts such as JARs, WARs, EARs and so forth and when tossing projects back and forth between people (and possibly countries). You can customize Maven, but Ant is easier to customize on the whole, since it has fewer rules that it must obey.

Working with legacy projects is no shame. Someone has to do it and if you're canny, you can charge a premium for having to dig around in and decipher other people's ugly code. It's not a talent I'm much good at, since I do major rewrites of my own work at the drop of a hat, much less anyone else's.

 
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my opinion the common quality in Software Engineers that I hold in high regard is the ability to effectively wrangle with existing gnarly code. Development is easy when you don't have to start with a ball of mud.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Ant is only "old technology" in terms of age.



For me, I am too happy to even get to work on old technologies but I need help again which I hope I can get it here....cos I really don't want to lose a job.
Basically, I have problem in following the Ant tutorial.
Now, I am trying to learn the part on external libraries as listed in the site :


https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html


So, there is this part that I don't get it.  They have put a "..." in between the code change so I took it that the ... means following the previous section code as in the enhanced part.
But, when I ran it, it doesn't work.

 
Tim Holloway
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ant allows you to define "variables" in order to make the project more flexible. They are defined within project files using the "properties" elements, as well as in various other ways (including via -D definitions on the Ant command line). They're not actually variables, because once the value is set, it cannot be changed and there are rules that determine which definition has precedence if the same property is defined more than once.

You have a property whose name is "lib" and whose value is also "lib". Perhaps a better value would have been "./lib", as it shows more plainly that the lib directory is a relative pathname (relative to the current directory).

I can infer that there's also a property definition for "classes", since the same practice is being followed there.
 
tangara goh
Ranch Hand
Posts: 1048
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Ant allows you to define "variables" in order to make the project more flexible. They are defined within project files using the "properties" elements, as well as in various other ways (including via -D definitions on the Ant command line). They're not actually variables, because once the value is set, it cannot be changed and there are rules that determine which definition has precedence if the same property is defined more .



I managed to resolve those problems.  Sorry I got caught up by panic again.
Now, there is this -D thing that you mentioned here but I can't seem to find any tutorials on -D thing that I have seen it in Java configuration like OPT etc.

is -D, OPT etc part of Ant command ?

Where can I get tutorials on it ?
 
Why is the word "abbreviation" so long? And this ad is so short?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic