# .java to .jar file



## GSquadron (May 9, 2011)

Hi guys!
I have a problem i think i dont know how to do this little thing
I have searched around the web, but i cant find anyone to explain it how to
and where to put this code down here in order for the compilator to convert it
from .java to a .jar file so the program or games i do in neatbeans can be executed in
my mobile phone!
Anyone can help??? The code is this one:
jar cf jar-file input-file(s)


----------



## digibucc (May 9, 2011)

well you'd put in in your command prompt, from wherever it can execute the java compiler.

if installed correctly, that should be anywhere.  but you may have to navigate to the java install directory to call the executable.

i have no idea about java specifically, so i can't help much more than that i'm afraid.

you might want to mention windows or linux, as that will matter.  i assume windows?


----------



## GSquadron (May 9, 2011)

I have already posted windows in my system specs


----------



## robn (May 9, 2011)

Netbeans is the same on all OSs: Right-click on your project and choose "clean & build". The Jar executable will be made and put in the "dist" sub folder of your project.


----------



## Easy Rhino (May 9, 2011)

Aleksander Dishnica said:


> I have searched around the web, but i cant find anyone to explain it how to
> and where to put this code down here in order for the compilator to convert it
> from .java to a .jar file s



http://download.oracle.com/javase/1.4.2/docs/tooldocs/solaris/jar.html

obviously didnt look to hard


----------



## GSquadron (May 9, 2011)

I know the manual, i got the code from there
I just dont know where to put the code in the program i made
and what to put in :S?


----------



## Easy Rhino (May 9, 2011)

if you know the manual then you know you dont put the code in the program, you convert all of your java class files into a jar file using their compiler.


----------



## temp02 (May 9, 2011)

As a side note to *Easy Rhino*s comment, you can only jar .class files, meaning that you need to compile all the .java files and them jar the .class files resulting from the compilation. Example:

```
javac Test.java
jar cf Teste.jar Test.class
```


----------



## GSquadron (May 9, 2011)

Ok, but where to put the code?
I mean in a new class? In the middle of a class?
And inside are so many classes, which means with your code man, i need to put all in???
Or should i create the code again and again?


----------



## robn (May 9, 2011)

Aleksander Dishnica said:


> I know the manual, i got the code from there
> I just dont know where to put the code in the program i made
> and what to put in :S?



Code goes on a command line prompt as already mentioned...

but anyway since you are using Netbeans, it will sort all this for you as I already said 

"Clean & build" project = jar file


----------



## Easy Rhino (May 9, 2011)

you can either use the command line or whatever program you may have used to write the program.


----------



## temp02 (May 9, 2011)

Aleksander Dishnica said:


> Ok, but where to put the code?
> I mean in a new class? In the middle of a class?
> And inside are so many classes, which means with your code man, i need to put all in???
> Or should i create the code again and again?



Yes, you need to compile every single file, and moreover, if one files has dependencies that cannot be solved automatically (the class is not in java.lang.path) you have to include the path to every unresolved class at the compilation process command line.
If I were you, for a big standalone application I would follow *robn* advice and use NetBeans to manage all the files in a projects, and let NetBeans/Ant figure out how to properly compile and build the jar (if you do use NetBeans the resulting jar file will be inside the _dist_ folder inside the project folder).


----------

