Thursday

To make a Java executable JAR file.


2. Compress Files To An Executable Java Archive (JAR):

It is also possible to make an archive that can be executed (run) by Java and even by a double click through your OS, if you have it set up correctly.

Jar file contains MANIFEST file that contains information Java wants to know.

One piece of information a manifest file may contain is the name of a class that will be run if the JAR file is executed.

To create an executable jar file you must specify in which file the main method is there.

You do this by creating a text file called "mainClass.txt" with the following text:

Main-Class: Two
Where Two is the java file name which contains the main method.
 
 
IMPORTANT: the text file only needs the one line of text for this purpose. However, the file must end with a blank line other wise this will not work.

Now run the jar utility with this command line:

   jar cmf mainClass.txt example.jar *.class
 

observe m option and mainClass.txt you will get cleared.

i.e.

create a JAR file (option c) with modifications to the manifest file (option m) as specified within mainClass.txt, naming the JAR file (option f) as example.jar and including everything that matches the pattern *Class.

Running An Executable JAR From Command Line

java -jar example.jar

In windows you can just double click on a jar file instead of doing all these typing.

For this you should have the following to be set.(It is automatically done with java installation but if not you need to do it manually).

‘javaw.exe’ is an application comes with JDK for allow you for Double-click.

Go to Tools | Folder Options | File Types.

note: see the above image

"C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*

IMPORTANT NOTE: include the double quotes to take care of names with spaces.

That all about jar file creation. have a nice jarring J

Wednesday

jar file crete - how to

Every one while working with java comes to a need for jar file creation. Here we will look at how to do all these in straight forward way.

What is jar file?

jAVA arCHIEVE --JAR files are Java's version of ZIP files.

Used for 2 purposes.

1.compress (make a smaller size) a number of files into one file (archiving).

2.To make a Java executable JAR file.

Details:

Compress Files To A Java Archive (JAR):

Syntax -> jar CF example.jar *.java

jar

The command to run the jar utility.

CF

Create a new archive with the file name specified. These two options are from this list of common options:

- c create new archive
- t list table of contents for archive
- x extract named (or all) files from archive
- u update existing archive
- v generate verbose output on standard output
- f specify archive file name
- m include manifest information from specified manifest file
- 0 store only; use no ZIP compression
- M do not create a manifest file for the entries
- i generate index information for the specified jar files
- C change to the specified directory and include the following file

Multiple options can be used together. They all must appear after the "jar" command with no white space separating them.

example.jar

Name of the JAR file. This can only be included if you use the 'f' option.

*.java

i.e. All files that have extension as .java .similarly you can write like *.class to make all your successfully complied java code (byte code) to make as an archive.

Names of all the files you want to put in the jar file. This could be just one name or a list of multiple names separated by space. Names can use pattern matching characters to match multiple files.

If you have 2 java file and you want to make a jar for them.


jar CF example.jar One.java Two.java

example.jar the name you want for your archive .
two.java your second file name.









Yes that’s enough to create a jar file or make a jar file for your files.


Next To make a Java executable JAR file.

Monday

"Your system is low on virtual memory "error message in Windows

Problem: Applies to windows

"Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied."

Solution: For Windows XP(Because I am using xp now:))

1. Click Start, right-click My Computer, and then click Properties.

2. In the System Properties dialog box, click the Advanced tab.

3. In the Performance pane, click Settings.

4. In the Performance Options dialog box, click the Advanced tab.

5. In the Virtual memory pane, click Change.

6. Change the Initial size value and the Maximum size value to a higher value, click Set, and then click OK.

7. Click OK to close the Performance Options dialog box, and then click OK to close the System Properties dialog box.