• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a .JAR  RSS feed

 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Code Ranch Forum,

Well I have been poking around with the whole .jar in the command prompt. It is said to be easy but more times then not I get file not in that directory or some compile error. These problems got me frustration because I can create the .jar in Eclipse but not in CMD. Like I said I compile all my classes in then I run the command to create the .jar with all the names of the classes. So any ideas why my IDE is better or easier then command prompt at compiling? I need to learn either how to compile via CMD or NetBeans and have yet to master this skill. Do you know of any online .jar utility that I can upload my packages and create the .jar? If not can anyone help me master the skill of creating .jar CMD and or NetBeans.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IDE's actually hide a lot of the details from you. If you are getting compiler errors when you try to make a jar, then your code isn't really right. You may be surprised to learn we actually have a FAQ on this: FixAllCompilerErrorsBeforeRunningTheApplication
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dude! calm down. it isn't that hard.
i jar from command prompt all the time.
jarring
for applets and other non-executables just leave out that part.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response yes I understand we have documents to help thanks for the link fred rosenberger. You are right fix the errors for Cmd compiling and creating the jar. Thanks for your knowledge and help.

Thanks for helping me calm down haha. I was told to compile all classes in the app then use .jar main class .jar then list all the other classes that are part of the project. When you say non applets and other non-executables what exactly does this mean? I have many classes and they work together to create the app. Like I said before CMD seems to be really picky when it comes to .jar when it is a complex project compiling in .jar is difficult because it will not help fix any errors. Thanks for your help Randall Twede I tried and will try to work with it some more but have not gotten the outcome I want.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello every one

I followed your links and got all my classes compiled in .class make the manifest.

Can you look over this error and tell me what I am doing so wrong I am so sorry to have to ask I know it is easy but as you might know I want to learn this new method.

The system cannot find message text for message number 0x2350 in the message file for Application.



C:\Users\Bykenhaal\Desktop>cd board

C:\Users\Bykenhaal\Desktop\board>jar cvfm TicTacToeGUIGame.jar manifest.txt*.class
java.io.FileNotFoundException: manifest.txt*.class (The filename, directory name, or volume label sy
ntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at sun.tools.jar.Main.run(Main.java:171)
at sun.tools.jar.Main.main(Main.java:1177)

C:\Users\Bykenhaal\Desktop\board>C
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you get .txt* in the extension? It is possible the Microsoft Notepad has added something like that. Don't use it; look here for suggestions.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I renamed the Manifest .mf and I am working with that now. Thanks
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it out
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried for a while now and I got something close to a .jar file the problem is that the .jar file will not open and it is not giving me any error message when I click on it. I posted the CMD commands below in hopes someone knows where I went wrong.



Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\Bykenhaal\Desktop>cd board

C:\Users\Bykenhaal\Desktop\board>dir
Volume in drive C is Windows
Volume Serial Number is 9A73-751D

Directory of C:\Users\Bykenhaal\Desktop\board

02/06/2014 01:14 PM <DIR> .
02/06/2014 01:14 PM <DIR> ..
02/06/2014 01:07 PM 2,431 Board.class
02/05/2014 06:06 PM 1,702 Cell.class
02/04/2014 03:47 PM 1,195 Mark.class
02/04/2014 03:47 PM 960 Outcome.class
02/04/2014 03:47 PM 832 Player.class
02/05/2014 06:06 PM 3,313 TictacToeGUIGame.class
02/06/2014 01:13 PM 6,385 TicTacToeGUIGame.jar
7 File(s) 16,818 bytes
2 Dir(s) 1,909,133,635,584 bytes free

C:\Users\Bykenhaal\Desktop\board> jar -cf TicTacToeGUIGame.jar Manifest.mf Board.class Cell.class Mark
.class Outcome.class Player.class
Manifest.mf : no such file or directory

C:\Users\Bykenhaal\Desktop\board>jar -cf TicTacToeGUIGame.jar Manifest.mf Board.class Cell.class Mark.
class Outcome.class Player.class

C:\Users\Bykenhaal\Desktop\board>jar -cf TicTacToeGUIGame.jar Manifest.mf Board.class Cell.class Mark.
class Outcome.class Player.class

C:\Users\Bykenhaal\Desktop\board>
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Bykenhaal wrote:C:\Users\Bykenhaal\Desktop\board>jar cvfm TicTacToeGUIGame.jar manifest.txt*.class
java.io.FileNotFoundException: manifest.txt*.class (The filename, directory name, or volume label syntax is incorrect)

Type a space between manifest.txt and *.class.

About your second problem: I don't see the Manifest.mf file in your directory listing. Make sure you have it in the right place.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your right I tried to compile my manifest seems to be the issue. This is what I have for my manifest "Manifest-Version: 1.0 Main-Class: TicTacToeGUIGame.Class".


Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\Bykenhaal\Desktop>cd board

C:\Users\Bykenhaal\Desktop\board>dir
Volume in drive C is Windows
Volume Serial Number is 9A73-751D

Directory of C:\Users\Bykenhaal\Desktop\board

02/06/2014 07:15 PM <DIR> .
02/06/2014 07:15 PM <DIR> ..
02/06/2014 01:07 PM 2,431 Board.class
02/05/2014 06:06 PM 1,702 Cell.class
02/06/2014 11:19 AM 57 Manifest.mf
02/04/2014 03:47 PM 1,195 Mark.class
02/04/2014 03:47 PM 960 Outcome.class
02/04/2014 03:47 PM 832 Player.class
02/05/2014 06:06 PM 3,313 TictacToeGUIGame.class
7 File(s) 10,490 bytes
2 Dir(s) 1,909,142,188,032 bytes free

C:\Users\Bykenhaal\Desktop\board>jar cvfm TicTacToeGUIGame.jar Manifest.mf *.class
added manifest
adding: Board.class(in = 2431) (out= 1371)(deflated 43%)
adding: Cell.class(in = 1702) (out= 959)(deflated 43%)
adding: Mark.class(in = 1195) (out= 673)(deflated 43%)
adding: Outcome.class(in = 960) (out= 538)(deflated 43%)
adding: Player.class(in = 832) (out= 472)(deflated 43%)
adding: TictacToeGUIGame.class(in = 3313) (out= 1738)(deflated 47%)

C:\Users\Bykenhaal\Desktop\board>java -jar TicTacToeGUIGame.jar
no main manifest attribute, in TicTacToeGUIGame.jar

C:\Users\Bykenhaal\Desktop\board>
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Bykenhaal wrote:C:\Users\Bykenhaal\Desktop\board>java -jar TicTacToeGUIGame.jar
no main manifest attribute, in TicTacToeGUIGame.jar

Did you follow step 2 in the Creating an executable JAR file section of the link Randall gave you ?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Bykenhaal wrote:This is what I have for my manifest "Manifest-Version: 1.0 Main-Class: TicTacToeGUIGame.Class".

First of all, those two attributes should be on separate lines in your manifest file. Secondly, the value for the Main-Class attribute must be a class name. Not a filename. you should not add ".Class" to it. Your manifest file should look like this:

Manifest-Version: 1.0
Main-Class: TicTacToeGUIGame

I'm assuming here that your class TicTacToeGUIGame is in the default package.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will look into if my .jar is correct or not. Thanks you for your help.


You are right my main is TicTacToeGUIGame.jar Thanks I fixed that mistake but every time I make the .jar it will not open up.


I have TicTacToeGUIGame as a .class and .jar in my folder I think I only need one. Maybe I just use the correct .jar and then remake the .jar and see if I can get it to run. Sound right?

C:\Users\Bykenhaal\Desktop\board>jar cvfm TicTacToeGUIGame.jar Manifest.mf *.class
added manifest
adding: Board.class(in = 2431) (out= 1371)(deflated 43%)
adding: Cell.class(in = 1702) (out= 959)(deflated 43%)
adding: Mark.class(in = 1195) (out= 673)(deflated 43%)
adding: Outcome.class(in = 960) (out= 538)(deflated 43%)
adding: Player.class(in = 832) (out= 472)(deflated 43%)
adding: TictacToeGUIGame.class(in = 3313) (out= 1738)(deflated 47%)

 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried a many times to create the .jar I do not know what I am doing wrong. May be my .jar is not write or I am not understanding the directions.

So I got all my class files in a folder on my desktop. I have my main compiled as well in that folder. Now I use that name a my .jar and add them all with the commands to create the jar but I can never open the file and run it like in my IDE. I downloaded the Jar Maker as I thought I would be able to maybe get some results but I am not able to make a working Jar.


Sometime I am getting Invalid or Corrupt jacfile.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could not load or Find Main Class error message that I have. I have the main class in class form in the folder and I use it when I create the Jar.



C:\Users\Bykenhaal\Desktop>cd board

C:\Users\Bykenhaal\Desktop\board>javac TicTacToeGUIGame.java
javac: file not found: TicTacToeGUIGame.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\Users\Bykenhaal\Desktop\board>javac TicTacToeGUIGame.java
javac: file not found: TicTacToeGUIGame.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\Users\Bykenhaal\Desktop\board>jar cfvm TicTacToeGUIGame.jar Manifest.mf Board.class Cell.class Mark
.class Outcome.class Player.class
added manifest
adding: Board.class(in = 2431) (out= 1371)(deflated 43%)
adding: Cell.class(in = 1702) (out= 959)(deflated 43%)
adding: Mark.class(in = 1195) (out= 673)(deflated 43%)
adding: Outcome.class(in = 960) (out= 538)(deflated 43%)
adding: Player.class(in = 832) (out= 472)(deflated 43%)

C:\Users\Bykenhaal\Desktop\board>jar tf TicTacToeGUIGame.jar
META-INF/
META-INF/MANIFEST.MF
Board.class
Cell.class
Mark.class
Outcome.class
Player.class

C:\Users\Bykenhaal\Desktop\board>java -jar TicTacToeGUIGame.jar
Error: Could not find or load main class TicTacToeGUIGame

C:\Users\Bykenhaal\Desktop\board>

C:\Users\Bykenhaal\Desktop\board>java -jar TicTacToeGUIGame.jar
Exception in thread "main" java.lang.NoClassDefFoundError: TicTacToeGUIGame (wrong name: TictacToeGU
IGame)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)







 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Bykenhaal wrote:This is what I have for my manifest "Manifest-Version: 1.0 Main-Class: TicTacToeGUIGame.Class".

Brian Bykenhaal wrote:
C:\Users\Bykenhaal\Desktop\board>jar cfvm TicTacToeGUIGame.jar Manifest.mf Board.class Cell.class Mark
.class Outcome.class Player.class
added manifest
adding: Board.class(in = 2431) (out= 1371)(deflated 43%)
adding: Cell.class(in = 1702) (out= 959)(deflated 43%)
adding: Mark.class(in = 1195) (out= 673)(deflated 43%)
adding: Outcome.class(in = 960) (out= 538)(deflated 43%)
adding: Player.class(in = 832) (out= 472)(deflated 43%)

Assuming you now have the format of your manifest file correct as shown by Jesper above, your problem now is that you don't have the TicTacToeGUIGame.class file in your jar file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!