It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Jar files" Watch "Jar files" New topic
Author

Jar files

James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

My directory structure is ..
c://.../jdk/bin/programs

When i create a jar file of (say) a.class and b.class which is in programs directory. The jar file is created in the bin directory.
because the jar.exe is in bin ,it is created there.

I want that *.jar to be created in programs dir.
Is it possible??. If so how..
I tried -C option but ended up with error.
So help me out .
Thanks


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Casttro Francis
Greenhorn

Joined: Oct 08, 2008
Posts: 25
Hi James

I guess you were executing the command from /jdk/bin directory.. First set the class path and then execute the above command to make jar from programs directory. It will create the myfile.jar in the programs directory..


Any fool can write code that a computer can understand. Good programmers write code that humans can understand....
Casttro Francis
Greenhorn

Joined: Oct 08, 2008
Posts: 25
Set the path using


Hope this will help you
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

PATH is a dos command .. so if i change that would that effect all other commands path? ?
or would that effect only the next command??
Dont mind if it sound stupid :roll:
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

If you set it in a command window, it will affect only the PATH for that command window and that session. It will not affect other command windows or shells (such as Windows Explorer which is the primary Windows GUI). If you add it to your environment variables settings, than it will be present for all command windows opened after its been set.

There is nothing wrong with setting it permanently. It won't break other commands (if done correctly). And if you are going to be doing regular Java development, it will make your life a lot easier if you put it in your path permanently. In Windows, you can do this by going into the System control Panel applet, go to the Advanced tab, click Environment Variables, and edit the PATH system variable and append it. Once you click OK on all the windows, it will be in your PATH for any new command windows you open (but not for any that are already open).
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Thanks for the explanation...
I tried the following

path C:\Program Files\Java\jdk1.6.0_03\bin\programs
jar -cf jms.jar programs/pack1

with the jdk/bin as as current directory

Still it created the jar file in bin..
What is that i am doing wrong
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18881
    
    8

You're creating a file in your current working directory. Changing the PATH environment variable doesn't have any effect on what your current working directory is. To change that, you use the CD command.
[ December 07, 2008: Message edited by: Paul Clapham ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Bad idea to put your own files in the bin directory. Better to move that folder elsewhere.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

I totally understand that its a bad idea to keep file in bin...
But i was trying to create a jar file(destiny) in some other folder other than in jdk/bin.
Which i was not able to. And that is what i was looking for .
Casttro Francis
Greenhorn

Joined: Oct 08, 2008
Posts: 25
Hi James,

Create a new directory called programs under c: and store the .java or .class files. Now open a command prompt then set the path as


Now change the prompt to your working directory, Ex: c:/programs. Now execute


This will create the jar file in the working directory itself..
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

@ Casttro Francis

Thank you so much for helping me... it worked perfectly.
Can you tell me ,what exactly does the PATH command do( or tell).
Casttro Francis
Greenhorn

Joined: Oct 08, 2008
Posts: 25
The PATH variable contains directories where binary files (e.g. EXE files in Windows) will be looked for.
If you open a command prompt and type "javac", you're supposed to have the "bin" directory of your sdk into the PATH, otherwise you'll get an infamous "Command not found" error message.

The CLASSPATH contains directories (or JAR files), from where your java compiler/runtime will look for .class files (and some others).
For example, "java Hello.class" will not work unless you set the directory (or JAR file) Hello.class is in, into your CLASSPATH.


PATH : The OS will look into this while executing.
CLASSPATH : The Application will look into this while executing.

Hope this will help you out...
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Okay... now i understood that.....
To check my understanding...
if i have a fun.exe file which can exectue the command "funny", in the dir
d:\test\fun.exe

and if i am in E:\document\

and if i set the path varible to d:\test\
i can exectue that funny command from E:\document\
Casttro Francis
Greenhorn

Joined: Oct 08, 2008
Posts: 25
Exactly !! Not only in E:/documents. You can call it from any directory
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Yeah yeah , i just took a example of E:

And thank you so much again .Now Every thing is crystal clear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar files