Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
Below is the contents of a folder. I'm pretty confusded on how to use the

Code:
jar cvf
command.

Thanks for any help.
 

Attachments

  • pic.jpg
    pic.jpg
    148.6 KB · Views: 1,258

andrewheard

macrumors regular
May 16, 2005
166
0
Ontario, Canada
I see you are using BlueJ. If you click File, create jar then it allows you to specify your main class and make the jar file executable. If you specifically need to do it from the command line then you'll need to ask someone else.
 

hsvmoon

macrumors newbie
Jul 31, 2006
24
0
Huntsville Al
jar

jar [flags] files

you need a manifest text file with the following line:

Main-Class: YourMainClass

(There are other attributes you can set as well)

Create a Jar

jar cvmf yourmanifest.txt *

* adds all of the files in the current directory

expand a jar

jar xvf yourjar.jar

the v flag only causes the files found to be printed to stdout
 

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
I don't really understand your instructions... I'm sorry. Maybe something more specific?

I tried having BlueJ make the jar file but I keep getting that "MainCanvas" is not found errors.
 

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
Code:
jar cfm MyJar.jar Manifest.txt MyPackage/*.class

I would be able to do what that code is telling me to do, but I don't know what to substitute in for the MyPackage/*.class part. I don't have a package...

Help is apprecaited.
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
First, find out what your main class is, the one whose public static void main(String args[]) method is called. It doesn't neccesarily have to have a package name. It could be something like "com.blah.Game" or simply "Test"

Make a manifest file, which is a plain text file typically called "Manifest.mf". Add a single line to that file that looks like either of:

Main-Class: com.blah.Game

or

Main-Class: Test

(as was explained above for finding your main class' name.

Then just do like hsvmoon explained, and do the following:

1. Open a terminal and cd to wherever the .class files are, or the root of where they go. If you don't use package names, then cd to where all the .class files are. If you do use packages, then go to the directory where the packages begin, so if your package name is "com.blah", go to the parent directory of the "com" directory

2. Type "jar cvfm path-to-Manifest.mf *"
 

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
Still some trouble.
I've attached the manifest file and the whole java file.

I did what you said. Here's what is in my Terminal window right now.

Code:
[I]209-181-58-139:~/JavaProjects/Klamath.net bobber205$ jar cvfm Manifest.mf *[/I]
java.io.FileNotFoundException: Classes (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at sun.tools.jar.Main.run(Main.java:122)
        at sun.tools.jar.Main.main(Main.java:903)
[I]209-181-58-139:~/JavaProjects/Klamath.net bobber205$ jar cvfm Manifest.mf *.class[/I]
java.io.IOException: invalid header field
        at java.util.jar.Attributes.read(Attributes.java:389)
        at java.util.jar.Manifest.read(Manifest.java:167)
        at java.util.jar.Manifest.<init>(Manifest.java:52)
        at sun.tools.jar.Main.run(Main.java:123)
        at sun.tools.jar.Main.main(Main.java:903)
209-181-58-139:~/JavaProjects/Klamath.net bobber205$

Does that make any sense?
 

Attachments

  • Manifest.mf.txt
    27 bytes · Views: 373
  • KlamathWebCam.java.zip
    1.5 KB · Views: 247

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
This is getting almost silly. On my terminal I have this input:
Code:
209-181-58-139:~/JavaProjects/Klamath.net bobber205$ jar cmfv Manifest.mf example.jar *.class
added manifest
adding: KlamathWebCam$mainCanvas.class(in = 8325) (out= 7458)(deflated 10%)
adding: KlamathWebCam$refreshAction.class(in = 1240) (out= 666)(deflated 46%)
adding: KlamathWebCam$startUpdating.class(in = 1382) (out= 814)(deflated 41%)
adding: KlamathWebCam$startUpdatingThread.class(in = 1337) (out= 782)(deflated 41%)
adding: KlamathWebCam$stopAction.class(in = 1373) (out= 746)(deflated 45%)
adding: KlamathWebCam.class(in = 3867) (out= 2017)(deflated 47%)
adding: KlamathWebCamOLD.class(in = 1834) (out= 947)(deflated 48%)
adding: MainCanvas.class(in = 702) (out= 462)(deflated 34%)
adding: refreshAction.class(in = 628) (out= 389)(deflated 38%)
In there I am told that $mainCanvas was added. Whee. But when I try to run my class
this comes up.

Code:
Exception in thread "main" java.lang.NoClassDefFoundError: KlamathWebCam$MainCanvas

I'm no longer getting a "failure to load manifest attribute" error anymore. I think I've done that part at least right. The main canvas is the first to be loaded in my class. That must be why it's the one that keeps coming up.

Thanks for any help! I am desperate! :D
 

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
Aha!
I did do it right!
Look what is in that jar file I made in the terminal command above.
 

Attachments

  • Picture 3.png
    Picture 3.png
    25.9 KB · Views: 325

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
When you use inner classes, the filename might look like "Outer$Inner.class", but the classname is still "Outer.Inner", which is what should be in the Manifest.mf file.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.