This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java program and ant.jar  RSS feed

 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

A java prg was tried to go for creating a build file with minimum task and target
using the ant.jar file as shown below
Though the compilation   is ok but on executing
the error was indicated as below
*****************************
Hi
Subsequent to reediting the following java code, i obtained comilation errors.(notshown)

Actually tha ant.jar was tried as follows

jar -tf ant.jar

jar -xvf ant.jar from which i could get the META-INF
as well as org folder containing all the .class of
ant By using these two things

i tried to compile the java prg shown below
But the result is not so favouring probably the description that were given in between the java codes may not be proper .
Please try to help/revise the description that enable  the java program to render a ready made build.xml



Thanks
As
CRMK






 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before anyone can help you, we need at least the exact code you tried to compile and the error messages it produced.
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Before anyone can help you, we need at least the exact code you tried to compile and the error messages it produced.

Hi
Subsequent to reediting  java code, i obtained comiplation errors


Actually tha ant.jar was tried as follows

jar -tf ant.jar

jar -xvf ant.jar from which i could get the META-INF
as well as org folder containing all the .class of
ant By using these two things

i tried to compile the java prg shown below
But the result is not so favouring probably the description that were given in between the java codes may not be proper .
Please try to help/revise the description that enable  the java program to render a ready made build.xml
As

CRMK

*******************************


 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have copied and pasted much of your reply.  This isn't helpful. 

It is difficult to tell exactly what you're trying to do.  Please TellTheDetails but also IsolateTheProblem (those are links).
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You have copied and pasted much of your reply.  This isn't helpful. 

It is difficult to tell exactly what you're trying to do.  Please TellTheDetails but also IsolateTheProblem (those are links).

Hi

Is there any ready  made java program for creating a build.Xml with one target and one task(minimum).The
Java prg shown(previous)  is just a sample one that i wanted to create .Contexualy
i made use of the ant.jar that is normally being supplie along with ant  But.I am surprised why the same java program
when iit s run from a java evironment is not producnig the build.xml file though compilation is without error
Please go through only code and tell if ok or not
Please note i mentioned anout ant jar just to make  you comprehend as to the way i started
Thanks
As
CRMK

 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code above, the biggest problem is this:

Simply add e.printStackTrace(); and you can see that there is an error when you run the program.  Address those errors and post back here if you get stuck.
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:In the code above, the biggest problem is this:

Simply add e.printStackTrace(); and you can see that there is an error when you run the program.  Address those errors and post back here if you get stuck.



Hi
Now after try/catch correctly entered
the codes are as follows



Now the runtime errors are the main hurdles inspite of the  many try by way of inclusion from ant tool;
Shall be thankful f this is made alright
Thanks
As
CRMK
 
 
 
 
 

 
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have an answer to your question about the NullPointerException, but I'd like to find out what you are trying to do.  It seems like you are trying to create a build.xml file for ant in Java.  Usually the build.xml file is created by hand.  Can you tell me why your trying to create it with Java?
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I don't have an answer to your question about the NullPointerException, but I'd like to find out what you are trying to do.  It seems like you are trying to create a build.xml file for ant in Java.  Usually the build.xml file is created by hand.  Can you tell me why your trying to create it with Java?


Hi
Build file is normally created by hand only But when you are able to know about the important classes being avaiilable from an executable
jar (ant.jar) i do feel that a try out can be made using java prg and the minimum elements like target ,task,project  to create .This would
,on success be able to do a bigger build.xml
but neverthles,why the classes are rather difficult to be made use of for, build up inli-eu of only .class files being  avilable   from a jar.
(present scenerio is maximum java lang being sandwitched  wth ant classes and that too only .clases
The null pointer exceptions  always exist when an object is not readily  made during run time.which is tough  So this hurdle is first thing to get rid off,This is
for your perusal with thanks.
As
CRMK
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't find any way to generate an Ant build file from Java.  You can generate them from an IDE like Eclipse or IntelliJ.  In Eclipse, try File > Export > General > Ant buildfiles.

Generating an Ant buildfile from a Java program sounds like a monumental task.  I would try using an IDE first.

As for you NPE in your Java program, I only know that you should use...

https://ant.apache.org/manual/api/org/apache/tools/ant/Project.html#createTask-java.lang.String-

I don't know if this will clear it up or not.  I'm not familiar with the org.apache.tools.ant package and I can't find any documentation on how to use it.
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I can't find any way to generate an Ant build file from Java.  You can generate them from an IDE like Eclipse or IntelliJ.  In Eclipse, try File > Export > General > Ant buildfiles.

Generating an Ant buildfile from a Java program sounds like a monumental task.  I would try using an IDE first.

As for you NPE in your Java program, I only know that you should use...

https://ant.apache.org/manual/api/org/apache/tools/ant/Project.html#createTask-java.lang.String-

I don't know if this will clear it up or not.  I'm not familiar with the org.apache.tools.ant package and I can't find any documentation on how to use it.


Hi

on the usual tryout methods &
removning the use of jar classes totally
since thre are no documentations available except the available .class files which seems to be of no help for the build-up work,
The following codes were tried
as a smpler one using the self made+radomcollectd ant.api(very approximately)the code was run in the java environment
as follws

javac ChapterAntProject.java

java ChapterAntProject.class

The NEW RESULTS were fetched which is not only  quite  relief  motivating at this jucture and requires further try

May I leave it to your good offices to do the needfull .I do not know how to include annotation process

This new venture of codes  is for your Perusal with thanks

As
CRMK

 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I can't find any way to generate an Ant build file from Java.  You can generate them from an IDE like Eclipse or IntelliJ.  In Eclipse, try File > Export > General > Ant buildfiles.

Generating an Ant buildfile from a Java program sounds like a monumental task.  I would try using an IDE first.

As for you NPE in your Java program, I only know that you should use...

https://ant.apache.org/manual/api/org/apache/tools/ant/Project.html#createTask-java.lang.String-

I don't know if this will clear it up or not.  I'm not familiar with the org.apache.tools.ant package and I can't find any documentation on how to use it.


Hi
On another instant when
i  used the code with system.out.println(proj1);

the resiult indicates a db id-
**************
ChapterAntProject@1db9742
*************
please tell me what this meansThanks
As
CRMK
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Comal Rajagopalaratnam Muthukumar wrote:
javac ChapterAntProject.java

java ChapterAntProject.class

Java takes a class name, not a class file name.  That means you should execute your program like this:

java ChapterAntProject
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Comal Rajagopalaratnam Muthukumar wrote:
Hi
On another instant when
i  used the code with system.out.println(proj1);

the resiult indicates a db id-
**************
ChapterAntProject@1db9742
*************
please tell me what this meansThanks
As
CRMK

When you print an object System.out.println() looks for a toString() method in the object's class.  If none is found, it looks in the superclass, until it gets to the Object class.  All objects are subclasses of Object, so you are seeing Object's toString() method.  It prints the class name, an @, and a reference to the object's place in memory (not very useful, but it works).  If you want to see something different, override the toString() class in ChapterAntProject.
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A class that doesn't extend any other class explicitly will extend class Object implicitly, so there's no need for "extend java.lang.Object".

Also, everything in java.lang is implicitly imported in every class, so you don't have to write java.lang.Object, just Object.
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The formatting of your code isn't helping you.  I consider poor formatting a bug.  Here's how you code looks just by using Eclipse and pressing Ctrl-Shift-F:
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a misspelling of the method execte?
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still have the question: what are you trying to do with this code?
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I still have the question: what are you trying to do with this code?


Hi

Indeed I totally agree with you the buildfile making via java prg is so complex that it requires a ready made documents.
As i earlier itsef  indicated just out of curiosity I did try many methods.Also the reason for the complexity is too many
clubbings of methods(betweenjava and ant classes)
The follwing last resort
i tried in a reverse way ie) build.xml being made by hand.and the same java program(which compiles ok)  being placed in the src
folder under ant base dir This resulted in yet another new error as shown below

Hence i now say cheerio to this.

The details for your perusal with thanks
Thanks
Cheers
As
CRMK

*********************************

****************************************


build.xml
*****************************


****************************

C:\Program Files\apache-ant-1.10.1\bin>ant
Buildfile: C:\Program Files\apache-ant-1.10.1\bin\build.xml

jonsTarget:

BUILD FAILED
C:\Program Files\apache-ant-1.10.1\bin\build.xml:4: taskdef class GreetJon ca
t be found
using the classloader AntClassLoader[]

******************************
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I finally know what you're trying to do.  Are you trying to write a Java program that can be called from an ant task?  If so, it's much simpler than you've made it.  The directions are here.  My Java class:

And I called it with a build.xml file like this:
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I think I finally know what you're trying to do.  Are you trying to write a Java program that can be called from an ant task?  If so, it's much simpler than you've made it.  The directions are here.  My Java class:

And I called it with a build.xml file like this:



Hi

From your specimen sample i could get the resolutuion for the same java prg of mine

shown  as under


Thanks and cheers
As
CRMK
**************************
Lesson learnt If you hava  a lemon make lemanade(proverb of Dale Carnegie)

***********






 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I think I finally know what you're trying to do.  Are you trying to write a Java program that can be called from an ant task?  If so, it's much simpler than you've made it.  The directions are here.  My Java class:

And I called it with a build.xml file like this:


Hi
Though the buldfile making was not possible by the java prg ealier  it does compile and creates a jar file  now


that can be now executed  as shown below


This is for  your perusal with thanks

Thanks
As
CRMK






*******************************
My originalJava Prg
ChapterAntProject.java
*********************************************

*********************************************************************************


build.xml

*****************************************************************
The long awaited output for the jar file created by above build.xml


Please note that this jar file is ot double clickable since no swing used

***************************************************************
C:\Program Files\apache-ant-1.10.1\bin>java -jar dist/antsimple-20170629.jar
GreetJonHello
*****************************************************************





 
Tim Moores
Saloon Keeper
Posts: 3758
78
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it's too late now, but https://coderanch.com/wiki/660363/Ant-Task contains a simple Ant task written in Java.

The lesson might be to search the FAQ before asking questions
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:I guess it's too late now 

Hi
Thanks for your simple result oriented solution no matter if it is late or not.I was able to get the java prg (Shown there )and on running the same afte
errorless compilation  the logging work does not take place .I am used  to run a java prg if there is constructor wthout args/parameters
As for example
javaprg jp = new javapg();
where as the example given  involes constructors are with args /parameters
.
you pleas show the command to invoke javapr  to render the buildfile style as output
Thanks
As
CRMK
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about the code in this post?  What do you mean by "logging"?  The output seems to be exactly what I would expect.  What were you expecting and why?
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Are you talking about the code in this post?  What do you mean by "logging"?  The output seems to be exactly what I would expect.  What were you expecting and why?



Hi
Invoking the java prg is the criteria  for obtaining the build.xml style
and that is what the  clarification requested by me
The example shown here is the one that i was referring that does
contain the log detail but invain of any result in producing the output as a build.xml style
No matter who deals/helps this post.Thisjava prg is able to only build a jar file out of the build file shown(also from the same example)not the one i sought
Please show me the exact command for the same
Thanks
As
CRMK


  ************************************

  
C:\Program Files\apache-ant-1.10.1\bin>ant clean
Buildfile: C:\Program Files\apache-ant-1.10.1\bin\build.xml

clean:

BUILD SUCCESSFUL
Total time: 1 second

C:\Program Files\apache-ant-1.10.1\bin>ant
Buildfile: C:\Program Files\apache-ant-1.10.1\bin\build.xml

compile:
    [mkdir] Created dir: C:\Program Files\apache-ant-1.10.1\bin\classes
    [javac] C:\Program Files\apache-ant-1.10.1\bin\build.xml:49: warning: 'inclu
deantruntime' was not set, defaulting to build.sysclasspath=last; set to false f
or repeatable builds
    [javac] Compiling 1 source file to C:\Program Files\apache-ant-1.10.1\bin\cl
asses

jar:
      [jar] Building jar: C:\Program Files\apache-ant-1.10.1\bin\MyTask.jar

BUILD SUCCESSFUL
Total time: 2 seconds






 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a little tweaking, I got ant to "log" (print) to the screen:

What I changed in the build.xml file:

Note that the classname attribute is "mtp.MyTask" because you have a package statement in your Java program.
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:With a little tweaking, I got ant to "log" (print) to the screen:

What I changed in the build.xml file:

Note that the classname attribute is "mtp.MyTask" because you have a package statement in your Java program.




Hi
   In order to make use of all the constructors that are with parameters & clubbing them with the main constructor
   so as to get the best of Objects  for the java prg  & same was compiled subsequent to changes
   made as under
   the error output is also shown for your perusal with thanks
   This is tried to get the direct build file pattern/style  correresponding to the java prg.
   Please you may do the error correction and add whatever more required
   Thanks
   As
   CRMK
  
  
 





 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are multiple problems with this code, the first of which is it is improperly formatted.  If you indent and format your code correctly, you will see many of the problems.

This is a plain old syntax error.  That means you didn't follow the basic rules of coding.  It looks like you are trying to make a do/while loop, but there's not "do" part.  Also, the condition of the "while" is surrounded with parentheses.

I think you need to abandon this project and do something simpler.  Review the basics of Java programming here:

https://docs.oracle.com/javase/tutorial/
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:There are multiple problems with this code, the first of which is it is improperly formatted.  If you indent and format your code correctly, you will see many of the problems.

This is a plain old syntax error.  That means you didn't follow the basic rules of coding.  It looks like you are trying to make a do/while loop, but there's not "do" part.  Also, the condition of the "while" is surrounded with parentheses.

I think you need to abandon this project and do something simpler.  Review the basics of Java programming here:

https://docs.oracle.com/javase/tutorial/



Hi

Thanks for tutorial. I just had gone through the same +some more references

This is is the most simple example i hava mede using the most essential setter and getter methods that we had missgiving
earlier
So kindly do a favorable go throgh and add if any

This is for your reconsideration as this project in fact has had many valuable points .
Thanks
As
CRMK



       
       
       
       
       
       
       
       
       
       
 
 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Your indentation/formatting really need improvement.  Here is the style guide for the CodeRanch Java programs.  The only thing I do differently is how I use braces:

Pick a style and stick with it.

2) Remove unnecessary and unused code from you program.  All of these lines are unused:
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:1) Your indentation/formatting really need improvement.  Here is the style guide for the CodeRanch Java programs.  The only thing I do differently is how I use braces:

Pick a style and stick with it.

2) Remove unnecessary and unused code from you program.  All of these lines are unused:



Hi

Indeed your initial   write-up that said

"This would be able to work" especially

when i gave a haphazard/tantalizing out put

from an ant.api used java prg that
that was not fully satisfactory as below
***********************
the resiult indicates a db id-
**************
ChapterAntProject@1db9742
*************
*********************

since the set and get methods of ant.api were not 100% tolerable
I now take this opportunty to thank you for the whole lot of  suggestions/usages etc rendered


Pleas you would be able to have a glimpse of the net result as under though this is total mechanical  way
to build from you java prg but once done don't you think you are  at full control over what you intend building

Lastly if any thing is to be corrected i shall do so in order to make the build file that
i created  so as to make a jar file  in the ant-home dir   to start with
Thanks
As
CRMK



   
       
       
       
       
       
       
       
      
       
       
       
       
       
       
       
       
 




 
Knute Snortum
Sheriff
Posts: 3837
91
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The formatting is still terrible, but your program seems to do what you want it to.
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:The formatting is still terrible, but your program seems to do what you want it to.

Hi

Your feedback is quite fitting Thanks. please suggest how do i replace the ' with " enabling the formating
of the My Task code atleast  becomes ok  ie  in (System.out.println();)

As
CRMK

 
Tim Moores
Saloon Keeper
Posts: 3758
78
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can embed double quotes in Java string litelals by escaping the double quote with a backslash: name=\"MyTask\" instead of name='MyTask'.
 
Comal Rajagopalaratnam Muthukumar
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:You can embed double quotes in Java string litelals by escaping the double quote with a backslash: name=\"MyTask\" instead of name='MyTask'.


Hi

Trying is the stepping stone for success(Dale carnegi's old saying)
I created java prg as under just to get  a style-pattern /specimen sample
that can be developed further
this is for perusal with thanks
As
CRMK



 
 
 
 
 
 

 
Campbell Ritchie
Marshal
Posts: 54897
155
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Comal Rajagopalaratnam Muthukumar wrote:. . . I created java prg as under just to get  a style-pattern /specimen sample
that can be developed further . . .
Not in its present state it can't. The formatting is really bad. Please format the whole thing correctly and post it again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!