LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 06-16-2005, 03:27 AM   #1
John_Emad
Member
 
Registered: Dec 2004
Posts: 196

Rep: Reputation: 30
Java executable Files


Hello All,

I am using NetBeans4.1 to build a simple application to use at my home.

The problem with Java programs ( i used eclipse before too) is that the IDE doesnt provide an exuctable file in the end which really annoys me

I am sure there is a way to make an executable file, but how can this be done ??

Thanx in advance
 
Old 06-16-2005, 03:54 AM   #2
sadun
Member
 
Registered: Mar 2005
Posts: 48

Rep: Reputation: 15
Jar files are executable if you have java virtual machine is installed. At least you can do a batch file or script which acts like executable, that contains like

java -xvj <name>.jar

Dont remember (xvj) switches exactly it may be different
 
Old 06-16-2005, 04:54 AM   #3
John_Emad
Member
 
Registered: Dec 2004
Posts: 196

Original Poster
Rep: Reputation: 30
I didnt fully understand the last part

hwo to combine all the resulting .java files to that JAR file ?
 
Old 06-16-2005, 05:48 AM   #4
sadun
Member
 
Registered: Mar 2005
Posts: 48

Rep: Reputation: 15
http://java.sun.com/docs/books/tutorial/jar/basics/

simply

To create a JAR file
jar cf jar-file input-file(s)

To view the contents of a JAR file
jar tf jar-file

To extract the contents of a JAR file
jar xf jar-file

To extract specific files from a JAR file
jar xf jar-file archived-file(s)

To run an application packaged as a JAR file (requires the Main-class manifest header)
java -jar app.jar

To invoke an applet packaged as a JAR file
<applet code=AppletClassName.class
archive="JarFileName.jar"
width=width height=height>
</applet>
 
Old 06-20-2005, 07:49 PM   #5
John_Emad
Member
 
Registered: Dec 2004
Posts: 196

Original Poster
Rep: Reputation: 30
OK, I managed to make the JAR file but my problem now is with executing it, I read that i must edit the mainfest file to mention the Main class

now my main class is called firstWindow (in a .Java file), and there is another file called firstWindow.frame

so which of them should be considered as the Main class ? and how to edit the manifest file to mention that this is the main class ??

thanx in advance
 
Old 06-21-2005, 03:26 AM   #6
sadun
Member
 
Registered: Mar 2005
Posts: 48

Rep: Reputation: 15
It should be automatic when creating. After creating jar file you should simply run it by

java -jar app.jar (assuming you have jvm installed)

If you couldnt then what was the error you get?
 
Old 06-21-2005, 01:07 PM   #7
prj
Member
 
Registered: Aug 2003
Location: South Wales
Distribution: Kubuntu, Ubuntu server, SuSE 11, Knoppix, Puppy, Myth. Oh alright then, all of them
Posts: 177

Rep: Reputation: 30
Or just use NetBeans to create the jar file and manifest.
You can then test it in NetBeans plus edit files and update the jar file plus it's manifest easily.

Just follow sadun's instructions run outside of NetBeans.
 
Old 06-21-2005, 02:52 PM   #8
John_Emad
Member
 
Registered: Dec 2004
Posts: 196

Original Poster
Rep: Reputation: 30
here is the error I get

Failed to load Main-Class manifest attribute from
john.jar

prj,

how to do that from NetBeans ?
 
Old 06-21-2005, 03:15 PM   #9
prj
Member
 
Registered: Aug 2003
Location: South Wales
Distribution: Kubuntu, Ubuntu server, SuSE 11, Knoppix, Puppy, Myth. Oh alright then, all of them
Posts: 177

Rep: Reputation: 30
"Just" create new jar. Use wizard to specify various properties.
Drag all the files into it. Highlight jar in file tree. Compile (F9)
Voila!

You can edit the jar by right clicking on it and changing all sorts of properties.
 
Old 06-21-2005, 03:43 PM   #10
John_Emad
Member
 
Registered: Dec 2004
Posts: 196

Original Poster
Rep: Reputation: 30
Ok, I managed to do it from the NetBeans

but i still dont get how to create a new JAR file ??

all i had to do is to right click on the project name on the left and choose build

then the jar file appeared in /dist directory, but it didnt appear in the project tree in the IDE

but another problem arrised, my application is a DB application, when I run it from the jar file it doesnt work with the DB at all, ie when I submit any data or try to retrieve from the DB nothing at all happens !!!!!!!!!!!!!

the DB is with mysql

here is what i get when i try to communicate with the DB

john@linux:~/JavaProjects/SoccerSafe/dist> java -jar Soccer.jar
java.lang.NoClassDefFoundError: com/mysql/jdbc/NonRegisteringDriver
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.john.db.query.retrieve(query.java:47)
at matchResultFrame.submitData(matchResultFrame.java:136)
at matchResultFrame.submitResultActionPerformed(matchResultFrame.java:120)
at matchResultFrame.access$000(matchResultFrame.java:15)
at matchResultFrame$1.actionPerformed(matchResultFrame.java:71)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

so any suggestions ?

Last edited by John_Emad; 06-21-2005 at 04:18 PM.
 
Old 06-21-2005, 05:22 PM   #11
prj
Member
 
Registered: Aug 2003
Location: South Wales
Distribution: Kubuntu, Ubuntu server, SuSE 11, Knoppix, Puppy, Myth. Oh alright then, all of them
Posts: 177

Rep: Reputation: 30
Quote:
then the jar file appeared in /dist directory, but it didnt appear in the project tree in the IDE
Oops, sorry thats me going back to NB 3.*.
To make changes in 4.1 right click on the project and choose properties.
Then check the nodes shown for various properties.
3.* used to be lovely for this!

For your db its possible but I'm not 100% that you may need to add some library (JDBC?) to your jar, again from the project properties dialogue.
Although I thought you could choose a connection, assuming you've created one, from the runtime listing?
 
Old 06-22-2005, 10:01 AM   #12
John_Emad
Member
 
Registered: Dec 2004
Posts: 196

Original Poster
Rep: Reputation: 30
thanx alot

It was an issue of adding the mysql jdbc connector in the JAR file
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java executable files vong'xion Linux - Newbie 3 10-06-2005 08:27 AM
Running a Java executable class from another executable class LUB997 Programming 22 07-24-2005 04:57 AM
java executable titanium_geek Programming 9 10-10-2003 05:56 AM
compiling a java file to be executable spyghost Programming 5 08-28-2003 07:20 AM
Converting perl files to executable mac files mrozkan Programming 0 04-16-2002 09:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 09:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration