Results 1 to 8 of 8
  1. #1
    Fruz is offline Member
    Join Date
    Dec 2011
    Posts
    10
    Rep Power
    0

    Default creating a Makefile

    Hi

    I'm quite familiar with java yet but my question is still a newbie's one to me.
    I'm trying to create a Makefile for a java programm.
    Indeed, at the beginning, I was just using couple of .sh file to set the LD_LIBRARY_PATH, then to compile all the files with the right options, and then to execute with the right -cp.
    But now, I'm working with someone that is has been using Eclipse, which means that all his files are splited among couple of directories with packages names ( I don't know if having packages will change something and require some more attention yet ... ), and I'm not familiar with that at all.

    So I think that the best option would be a Makefile, but I don't really know how it works, and even though I have been reading couple of tutos on internet, noone of them is speaking about packages whatsoever, and I don't have anything that really works now.

    Basically, the structure of the files is :
    ( -[x] is the directory "x" and -y is the file "y"

    -setLDLP.sh
    -compiler.sh
    -launch.sh
    -Makefile
    -[lib]
    ......-lib1.so
    ......-lib2.so
    ......-jar1.jar
    ......-jar2.jar
    -[trunk]
    ......-[src]
    ............-file1.java
    ............-file2.java
    ............-file3.java
    ............-file4.java
    ............-[abstraction]
    ..................-file5.java
    ..................-file6.java
    ............-[controleur]
    ..................-file7.java
    ..................-file8.java
    ............-[communicationUtilities]
    ..................-file9.java
    ..................-file10.java
    ......-[bin]
    ............-file1.class
    ............-file2.class
    ............-file3.class
    ............-file4.class
    ............-[abstraction]
    ..................-file5.class
    ..................-file6.class
    ............-[controleur]
    ..................-file7.class
    ..................-file8.class
    ............-[communicationUtilities]
    ..................-file9.class
    ..................-file10.class

    In my old .sh, I had :

    Quote Originally Posted by setLDLP.sh
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./lib/
    Quote Originally Posted by compiler.sh
    javac -cp "lib/jar1.jar:lib/jar2.jar" -d trunk/bin trunk/src/*.java
    Quote Originally Posted by launch.sh
    java -cp ${cp}:lib/jar1.jar:lib/jar2.jar:trunk/bin file1
    and I was just doing :
    source ./setLDLP.sh
    ./compiler.sh
    ./launch.sh
    to compile and launch the programm

    Those are the .sh when I had not those new directories : "controleur", "communicationUtilities", "abstraction", and I had not to handle it.

    I tried to create a makefile, but it doesn't work and I really don't know exactly how it should be.
    Should I do for each file a :
    "trunk/bin/fileX.class: trunk/src/fileX.java
    $(JCC) $(JFLAGS) trunk/src/fileX.java"
    and like

    "trunk/bin/controleur/fileY.class: trunk/src/controleur/fileY.java
    $(JCC) $(JFLAGS) trunk/src/controleur/fileY.java"

    ( where I would put "javac" in JCC and "-cp "lib/jar1.jar:lib/jar2.jar"" in JFLAGS )
    ??
    I would like the class file to be creating in different folders like the sources files are.

    I'm really getting lost there, if someone could help me, it would be really helpful.

    Thanks in advance
    Last edited by Fruz; 01-17-2012 at 05:49 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: creating a Makefile

    Blimey, it's been over a decade since I've done a MAKE.
    Have you thought of using Ant?
    It's similar, but is the tool usually used for Java builds and you'll find a lot more examples for that one...

  3. #3
    Fruz is offline Member
    Join Date
    Dec 2011
    Posts
    10
    Rep Power
    0

    Default Re: creating a Makefile

    I've never been using ant
    Is it a software ?
    I don't really like the fact that if I were doing like most of the students, I would be a "slave-like" of Eclipse, like not being able to do anything without it and that's why I'd like to handle the compiling part of it myself, or at least some of it ( there are couple of other reasons why I don't like Eclipse too ).
    I'll give ant a look a bit later today, thanks for the advice.
    Last edited by Fruz; 01-17-2012 at 06:04 PM.

  4. #4
    Fruz is offline Member
    Join Date
    Dec 2011
    Posts
    10
    Rep Power
    0

    Default Re: creating a Makefile

    double post sry



    ( Using that double post at the end )

    I tried to modify my "compiler.sh" file before trying to do the makefile.

    it became that :

    Quote Originally Posted by compiler.sh"
    javac -cp "lib/j3dcore.jar:./lib/j3dutils.jar:lib/vecmath.jar" -d trunk/bin/abstraction trunk/src/abstraction/*.java
    javac -cp "lib/j3dcore.jar:./lib/j3dutils.jar:lib/vecmath.jar" -d trunk/bin/controleur trunk/src/controleur/*.java
    javac -cp "lib/j3dcore.jar:./lib/j3dutils.jar:lib/vecmath.jar" -d trunk/bin/communicationUtilities trunk/src/communicationUtilities/*.java
    javac -cp "lib/j3dcore.jar:./lib/j3dutils.jar:lib/vecmath.jar" -d trunk/bin trunk/src/*.java
    But with it, I have errors because it does not find the packages, like "package controleur does not exist" ( I'm nor really familiar with packages, maybe I should get use to it ... ).
    Maybe someone has a solution to that problem ?
    Because if I can just compile it like that, I'm cool with it
    Last edited by Fruz; 01-17-2012 at 06:15 PM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: creating a Makefile

    Apache Ant.
    "
    Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications.
    "
    So not too different in aim to 'make', but geared to Java.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default Re: creating a Makefile

    I use ant, but you might also consider maven: Welcome to Apache Maven

    "Maven can manage a project's build, reporting and documentation from a central piece of information."
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default Re: creating a Makefile

    Quote Originally Posted by Fruz View Post
    I and that's why I'd like to handle the compiling part of it myself
    You can't do that with Java; a.a.m.o.f. javac (the compiler) and the make utility don't like each other much because javac itself is a small make utility, i.e. if a class A references a class B in some way, then, if A is to be compiled, B is also compiled if needed; that behaviour confuses the make utility because some of its dependencies (and targets) are made up to date behind its back. The Ant tool can handle such situations.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Fruz is offline Member
    Join Date
    Dec 2011
    Posts
    10
    Rep Power
    0

    Default Re: creating a Makefile

    Actually, I just forgot to use the proper -sourcepath with /trunk/src in the "compiler.sh" so that it would work .

    So the project works atm, but thanks still for your help, if I have to be in a big java project in the future, I'll think about using ant.

    At least I learned 1 thing : Makefile is not something you use with java project lol =P.

Similar Threads

  1. Replies: 9
    Last Post: 07-29-2011, 02:18 PM
  2. Help with Linux Makefile
    By ruerric in forum New To Java
    Replies: 36
    Last Post: 07-23-2010, 03:46 AM
  3. Creating files stopped creating...
    By Dieter in forum Advanced Java
    Replies: 3
    Last Post: 09-25-2009, 11:45 PM
  4. MakeFile
    By divyanshu023 in forum New To Java
    Replies: 1
    Last Post: 09-18-2009, 08:16 AM
  5. Help regarding makefile problem
    By rams in forum Networking
    Replies: 0
    Last Post: 11-17-2008, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •