Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to wrap up .class file

 
Ranch Hand
Posts: 101
  • 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
 
Bartender
Posts: 4568
9
  • 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).
 
Rancher
Posts: 43016
76
  • 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
  • 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.
 
Ranch Hand
Posts: 650
  • 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
  • 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: 4568
9
  • 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
  • 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: 4568
9
  • 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
  • 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









 
Sheriff
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
  • 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
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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.
 
Greenhorn
Posts: 20
  • 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
  • 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
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
  • 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

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
  • 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.
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic