6


how can I make jar for my java files in linux? I have this situation: I have in directory src this stuff:

   Client.java  //source code
    GUI.java    // source code
    miglayout-lib.jar //external lib 
    icons // folder in which are 20 jpeg pictures

when I want to compile it I use

javac -cp "miglayout-lib.jar:." *.java

when I want to run it I use

java -cp "miglayout.jar:." Klient

//cause Klient is class with main.
How can I make some build file or script (something like make) which will make me one jar file with my application and I'will be able to run it?

Thx.

user1097772
  • 3,499
  • 15
  • 59
  • 95

2 Answers2

16

You can use command line utility named jar e.g.

jar cvf classes.jar .*.class

Use online help of jar for more info.

Since jar is a part of JDK it is cross platform, so it works on all operating systems. But it is very low level. You can use it as an exercise but in real life I'd recommend you to use one of popular build tools like ant, maven, buildr, gradle etc.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • 2
    Also commons IDE like Netbeans or Eclipse provide building jar facilities – ab_dev86 Mar 07 '12 at 07:44
  • Thx, but on that machine i'll test and run it there is no ant installed :/ So I have to use some not tool dependable script :/ – user1097772 Mar 07 '12 at 07:56
  • AlexR: Thanks it helped me to find right way. I made shell script and used this command `jar` with some other options there. – user1097772 Mar 07 '12 at 10:30
5

There are 2 popular options for Java:

Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211