File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to wrap up .class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to wrap up .class file" Watch "How to wrap up .class file" New topic
Author

How to wrap up .class file

Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
hello ranchers i am an engineering student.

I am developing a software in Java Swing which i want to sell it to a client.I have written all the source code.I have put the .class files in one folder
The problem is that i don't know to wrap it up and give the complete set up to the client so that he can install it without any intricacies.Please help me out
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4398
    
    8

Hi,

What you need to do is package them up in a JAR file (basically a zip file - it stands for Java ARchive). These are then very simple to distribute.

Sun have got a fairly comprehensive tutorial here: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

Also, if you're using a modern IDE (e.g. Netbeans), it's going to be able to build the JAR file for you - check out the documentation of whatever tool you're using.

(This isn't specific to Swing or any other library, so it really ought to be in a different forum).
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Note that if you want to ship everything in one file (including data files, images, sound, what have you) then you can't access those files via java.io.File et al.- you need to use the classloader resource mechanism.


Ping & DNS - my free Android networking tools app
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Matthew Brown wrote:Hi,

What you need to do is package them up in a JAR file (basically a zip file - it stands for Java ARchive). These are then very simple to distribute.

Sun have got a fairly comprehensive tutorial here: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

Also, if you're using a modern IDE (e.g. Netbeans), it's going to be able to build the JAR file for you - check out the documentation of whatever tool you're using.

(This isn't specific to Swing or any other library, so it really ought to be in a different forum).


I don't reckon zipping it would be a complete solution as the client will still need to invoke via command line.I want that with one mouse click the application starts running.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Java applications are run by a Java runtime. If the customer will not have Java installed on their system, then it will have to get installed somehow. Either you will have to tell them to do it, or build an installer to do it.
If Java is installed, then you can run the application from the Jar file using the "java -jar ..." command from any launching mechanism you wish to use.

Good luck.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Mark E Hansen wrote:Java applications are run by a Java runtime. If the customer will not have Java installed on their system, then it will have to get installed somehow. Either you will have to tell them to do it, or build an installer to do it.
If Java is installed, then you can run the application from the Jar file using the "java -jar ..." command from any launching mechanism you wish to use.

Good luck.


What are the launching mechanisms ?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4398
    
    8

Ankitt Gupta wrote:I don't reckon zipping it would be a complete solution as the client will still need to invoke via command line.I want that with one mouse click the application starts running.


Go through the tutorial I linked to, especially the part "Setting an Application's Entry Point".

If you've followed that approach, and they've got their computer configured so that .jar files are executed by the Java runtime, then it will run with a double-click.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Matthew Brown wrote:
Ankitt Gupta wrote:I don't reckon zipping it would be a complete solution as the client will still need to invoke via command line.I want that with one mouse click the application starts running.


Go through the tutorial I linked to, especially the part "Setting an Application's Entry Point".

If you've followed that approach, and they've got their computer configured so that .jar files are executed by the Java runtime, then it will run with a double-click.


I modified the Manifest.txt but still it is giving an exception when i invoke from command line

"Exception in thread "main" java.lang.NoClassDefFoundError :MyPackage/Admin (wrong name: Admin)
at .......
at....... "

And when i directly click by mouse it gives "Could not find the main class.Program will exit"
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4398
    
    8

That suggests to me that either the Manifest file isn't correct or (more likely) the internal structure of the JAR file isn't correct. I can't be more precise without knowing exactly what you've done.

If your main class is MyPackage.Admin, then the file Admin.class needs to be in a folder MyPackage within the JAR file.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Manifest.txt

Main-Class: MyPackage.Admin


Admin.jar

META-INF
META-INF/MANIFEST.MF
MyPackage/Admin.class
MyPackage/Bill.class
MyPackage/Insert.class
MyPackage/Update.class
MyPackage/View.class

The above are the contents of Manifest.txt and Admin.jar









Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

And what's the contents of MANIFEST.MF inside the JAR file?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Rob Prime wrote:And what's the contents of MANIFEST.MF inside the JAR file?


How to see the contents of Manifest.MF ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

The JAR file is nothing more than a glorified ZIP file, and the MANIFEST.MF file in it is nothing more than a glorified text file.
borj bersas
Greenhorn

Joined: Apr 19, 2010
Posts: 20
hi,
i just sold my simple application software written in java and i use third party software to wrap my class files,
you can use jar2exe to hide your source code and provide an executable file for your main class

edit: P.S. its only for windows ^^
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Rob Prime wrote:The JAR file is nothing more than a glorified ZIP file, and the MANIFEST.MF file in it is nothing more than a glorified text file.


Here is the glorified thingy

Manifest-Version: 1.0
Created-By: 1.6.0_04 (Sun Microsystems Inc.)
Main-Class: MyPackage.Admin

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Ankitt Gupta wrote:"Exception in thread "main" java.lang.NoClassDefFoundError :MyPackage/Admin (wrong name: Admin)
at .......
at....... "

Wait a sec. Is your Admin class put in a package called MyPackage? Not just in the file system, but does its file start with "package MyPackage"? Please remember that Java is case sensitive, also in package names.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Rob Prime wrote:
Ankitt Gupta wrote:"Exception in thread "main" java.lang.NoClassDefFoundError :MyPackage/Admin (wrong name: Admin)
at .......
at....... "

Wait a sec. Is your Admin class put in a package called MyPackage? Not just in the file system, but does its file start with "package MyPackage"? Please remember that Java is case sensitive, also in package names.


I checked it.There is no problem with name

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14196
    
  20

Can you show us the source code of class Admin?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Jesper Young wrote:Can you show us the source code of class Admin?


It is now running.I removed the package and included the .class files in same directory.I surmise package is the problem.



Thank you for being so patient.
 
GeeCON Prague 2014
 
subject: How to wrap up .class file