954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

java to jar

please tell me step of converting java source code into jar in netbean or if any software available please send me download link of it.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

Use the javac command to create the .class files
Use the jar command to create the jar file.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

Hi Norm.
Watch out for this OP - already in trouble with Peter Budo for not showing any effort, and is starting to troll other people's posts. J

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

Please tell me syntax or some example of jar command.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

you were just given what you need to know. tried running these commands yet?

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

I already run jar command it showing me following

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>cd\

C:\>cd bank1

C:\bank1>jar bank
Illegal option: b
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] fil
es ...
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
-e specify application entry point for stand-alone application
bundled into an executable jar 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
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .


C:\bank1>

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 
NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

you know ... Google the Wise may help you on your path to wisdom. just ask him the specifics about the jar command, I'm pretty sure he'll have at least one answer for you.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

i make jar file but it when i execute it showing a java exception has occur.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

which one?

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

it doesn't showing any detail it just show a dialog of java virtual machine launcher with the message "a java exception has occurred".

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

open a command prompt window, change to the folder with the jar file and enter:
java -jar .jar

On Windows: To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>cd\

C:\>cd bank2

C:\bank2>jar cf myFile.jar *.class

C:\bank2>java -jar myFile.jar
Exception in thread "main" java.lang.NullPointerException
at sun.launcher.LauncherHelper.getMainClassFromJar(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

C:\bank2>

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

That looks like a problem in the java program. I have not seen that error message before.
What does the manifest file in the jar file look like?
The manifest file must contain a Main-Class: record that points to the starting class for your program.
The jar command you used does not show that you have a manifest file.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

here is the content of manifest file

Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build.


note:i have written program in netbean.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

That doesn't look like a valid manifest file. Is that what is inside of the jar file?
You need to create a valid manifest file with the Main-Class: line in it and add it to the jar file using the jar command's m option.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

please give me some idea about how to create manifest file.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

as your manifest file states, it will be automatically generated if you build it using NetBeans, otherwise, you'll have to add a reference to the actual main class:
if you had taken a closer look to the tutorials suggested to you, you would have landed on this and your problem would have been solved by now.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

The basic command has this format:
jar -cfm jarfilename manifestfile input-file(s)


you can look up what the different arguments mean and research the jar making process at: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

FALL3N
Junior Poster in Training
84 posts since May 2010
Reputation Points: 10
Solved Threads: 2
 

Thanks all, It's working now.

Thankx a lot.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You