This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

makefile for java

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I need to know how to write a make file in linux to do the following task:
run a java program (using the command java add 10) a given number of times and write some of the output variables (say x,y,z) to a file.
I am a novice, so a sample makefile would really help.
Thanks
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why a makefile? They are not suited to the task that you propose. Make does not pass command line arguments to tasks, so you would not be able to specify how many times you wanted to run the task.
Make is designed to build files when another file it depends on changes.
The only way I see this working is if you had some number in one file, say in.txt and you always wanted the number in some othe file, say out.txt to be 10 greater. In that case you might set up a makefile like this: ([tab] means a tab character goes there)
out.txt: in.txt
[tab]cat in.txt | java add 10 > out.txt
Any time that in.txt changed, you could type make and out.txt would be updated.
To add in the number of times that you wanted this to execute, I would think that have to write a wrapper script. Make has no concepts of loops or branches.
[ November 05, 2002: Message edited by: Steve Deadsea ]
 
tony al
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You are right, what I actually need is the script file to do the above task.
thanks,
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically if you can do these things at the command line then you can do them in a batch file.
You would write a file that has the lines you need to execute, for example if the line you need to do to run your program is:
java add 10
then you just type that line into a file (let's call it "myfile").
If you wanted to route the output of that program to a file you use the standard unix re-direct commands of > or >>
java add 10 > output.txt
When you have written this list of commands you then set your file to be "executable" Look at the Unix command chmod to see how to do this. In any Unix or Linux system you can get that information via the man pages like this:
man chmod
But if you just want to make the file executable for the user who wrote it you would do this:
chmod myfile u+x
Once you've set the file to be executable you run it like this:
./myfile
The ./ means "run the file of this name in THIS directory rather than searching for it in my path"
That should be enough to get you started.
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I simplified it a bit to make it generic, but this does illustrate that for those times that the builds will look similar, but may need special environment settings, a Makefile is as good as anything.
If you really need to pass command line parms, then a script file is probably the answer. (My own preference is Perl, of course!)
If the project is way more complex, you may want to take a look into the Jakarta Ant project. For building my multi-class projects, I prefer to use the facilities of a good IDE, like Netbeans.
PCS
[ November 05, 2002: Message edited by: Philip Shanks ]
 
tony al
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic