Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

creating package

Thread view: 
Pradyut - 16 Feb 2006 05:47 GMT
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

Signature

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

Stefan Ram - 16 Feb 2006 05:53 GMT
>How do i create a package (.jar file) out of it using the "jar"
>utility and set the main class Alpha or DeltaOne

 If everything else fails, read the JAR tutorial at:

http://java.sun.com/docs/books/tutorial/deployment/jar/
Pradyut - 16 Feb 2006 06:50 GMT
> >How do i create a package (.jar file) out of it using the "jar"
> >utility and set the main class Alpha or DeltaOne
>
>   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
Pradyut - 16 Feb 2006 07:41 GMT
>> >How do i create a package (.jar file) out of it using the "jar"
>> >utility and set the main class Alpha or DeltaOne
[quoted text clipped - 11 lines]
> Main-Class: one.Alpha
> ------------------------------------------------------------------------------

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

Thanks
Signature

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

Roedy Green - 17 Feb 2006 06:25 GMT
>How do i create a package (.jar file) out of it using the "jar" utility and
>set the main class Alpha or DeltaOne

see http://mindprod.com/jgloss/jarexe.html
or the big boy's way
http://mindprod.com/jgloss/ant.html
http://mindprod.com/jgloss/genjar.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.