creating package

P

Pradyut

I have two files: -

------------------Alpha.java--------------------------------------------------
package One;
public class Alpha {
//member variables
private int iamprivate = 1;
int iampackage = 2; //package access
protected int iamprotected = 3;
public int iampublic = 4;

//methods
private void privateMethod() {
System.out.println("iamprivate Method");
}
void packageMethod() { //package access
System.out.println("iampackage Method");
}
protected void protectedMethod() {
System.out.println("iamprotected Method");
}
public void publicMethod() {
System.out.println("iampublic Method");
}

public static void main(String[] args) {
Alpha a = new Alpha();
a.privateMethod(); //legal
a.packageMethod(); //legal
a.protectedMethod(); //legal
a.publicMethod(); //legal

System.out.println("iamprivate: "
+ a.iamprivate); //legal
System.out.println("iampackage: "
+ a.iampackage); //legal
System.out.println("iamprotected: "
+ a.iamprotected"); //legal
System.out.println("iampublic: "
+ a.iampublic); //legal
}
}
------------------------------EOF------------------------------------------


-----------------------------DeltaOne.java---------------------------------
package One;
public class DeltaOne {
public static void main(String[] args)
{
Alpha a = new Alpha();
//a.privateMethod(); //illegal
a.packageMethod(); //legal
a.protectedMethod(); //legal
a.publicMethod(); //legal
//System.out.println("iamprivate: "
// + a.iamprivate); //illegal
System.out.println("iampackage: "
+ a.iampackage); //legal
System.out.println("iamprotected: "
+ a.iamprotected); //legal
System.out.println("iampublic: "
+ a.iampublic); //legal
}
}
----------------------------------EOF------------------------------------

How do i create a package (.jar file) out of it using the "jar" utility and
set the main class Alpha or DeltaOne
Thanks

--
Pradyut
http://pradyut.tk
http://groups.yahoo.com/group/d_dom/
http://groups-beta.google.com/group/oop_programming
India
 
P

Pradyut

Stefan said:
If everything else fails, read the JAR tutorial at:

http://java.sun.com/docs/books/tutorial/deployment/jar/

Thanks for the help

I created a manifest.txt file with the contents
------------------------------------------------------------------------------
Manifest-Version: 1.0
Created-By: 1.5.0_01-b08 (Sun Microsystems Inc.)
Main-Class: one.Alpha
------------------------------------------------------------------------------

The classes Alpha.class and DeltaOne.class were in the same directory
In the directory i gave the command: -

jar -cfm one.jar manifest.txt Alpha.class DeltaOne.class

But when i executed the jar file
java -jar One.jar
It gave the exception
Exception in thread "main" java.lang.NoClassDefFoundError: one/Alpha

Any help
Thanks

Pradyut
http://pradyut.tk
http://spaces.msn.com/members/oop-edge/
http://groups-beta.google.com/group/oop_programming
India
 
P

Pradyut

Pradyut said:
Thanks for the help

I created a manifest.txt file with the contents
------------------------------------------------------------------------------
Manifest-Version: 1.0
Created-By: 1.5.0_01-b08 (Sun Microsystems Inc.)
Main-Class: one.Alpha
------------------------------------------------------------------------------

Only Alpha has to be written i.e the manifest line should be
Main-Class: Alpha

Thanks
--
Pradyut
http://pradyut.tk
http://groups.yahoo.com/group/d_dom/
http://groups-beta.google.com/group/oop_programming
India
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,728
Latest member
FernMcmull

Latest Threads

Top