File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to wrap up .class file

 
Ankitt Gupta
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankitt Gupta
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what's the contents of MANIFEST.MF inside the JAR file?
 
Ankitt Gupta
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the source code of class Admin?
 
Ankitt Gupta
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic