• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jar...

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have already searched for "how to create an executable jar file" in few forum, and lucky get some very detailed steps for creating a jar file, I successfully create a Test.jar file by following those steps, BUT i can't successfully create a jar file for my "ShowChart.java", There will always be a message box jumping out "Can not find main class, program will exit" after i double click "ShowChart.jar"....
after compiling ShowChart.java, the following class file are created:
ShowChart.class ShowChart$1.class ShowChart$2.class ShowChart$3.class ShowChart$4.class ShowChart$5.class drawtables.class matrix .class
My compiling command it:
jar -cfm ShowChart.jar mainclass.mf ShowChart.class ShowChart$1.class ShowChart$2.class ShowChart$3.class ShowChart$4.class ShowChart$5.class drawtables.class matrix .class
the generated Manifest.mf is :
Manifest-Version: 1.0
Main-Class: ShowChart
Created-By: 1.4.0-beta (Sun Microsystems Inc.)

...I have been working for the probelm two days....pls do help
thanks in advance
dejie
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dejie,
The first, obvious question is, does the "ShowChart" class have a "main()" method?
Secondly, manifest files can be tricky. Have you seen these:
http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html
http://java.sun.com/j2se/1.4/docs/guide/jar/jar.html
Hope this helps.
Good Luck,
Avi.
 
dejie lin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.....i am quite sure the main class is inside the "ShowChart.java"....
anybody got anyother ideas???
thanks a lot
dejie
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dejie,
I asked about "main()" method -- not "main class".
You also didn't mention whether you verified the format of your manifest file. Does it conform to the specification (the link to which I gave in my previous post)?
Are you using some IDE wizard to create your JAR file (and/or manifest)?
Good Luck,
Avi.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Avi,
i have a question regarding the 'extensions' via Jar file.
i can understand the standard extensions like JavaMail or something are useful but i am not able to understand the its' applicability in user defined applications?
say, if we had an applet and we needed two jar files a.jar and b.jar then we can just write into the archive attribute for the applet tag the list of a.jar and b.jar right? what is a gain in using the download extension via the jar files?
i hope i am able to explain my doubt.
regards
maulin.
 
dejie lin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Avi,
The main() method is in ShowChart.java and the format of mianclass.mf file is:
Main-Class: ShowChart

(curser now is in third line)
I am not sure what is IDE wizard...
I have already read the two links which you provided, and believe that i have taken care some tricky problem the links mentioned...
...I am blur about why the "helloword.jar" can work well but the "show.jar" can't work well...there are more classes inside ShowChart.java rather than helloword.java, what else should i take care becuase of the more classes?
thanks for your kind suggestions
dejie
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maulin,
You seem to be mixing several different topics together, including applets and the java extension mechanism. Therefore your question is unclear to me, and hence, I cannot answer it.
Dejie,
If you have read the links I gave and have set up your JAR file correctly (as you claim), then I don't know why it doesn't work -- sorry.
Good Luck (to both of you),
Avi.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi avi,
i'm referring to fact that extensions can also be used in applets...
1. say my applet is in a.jar and there are some other classes which i had in b.jar then i might put b.jar as extension to the a.jar,...right?
2. the same effect we can essentially get via archive attribute in applet tag. we can write a.jar and b.jar *both* in there...
then in which way the extension of b.jar will help us??
i am getting something...
in 1st case,
-----------------
say if we are sure that almost all people have the classes in b.jar already on their machines but some users don't have it (say for the first time they see the applet)...so we can put b.jar in there as extension to a.jar... and that will reduce the downloading time for those who already had b.jar ,....you see what i mean?

in 2nd case,
------------------
downloading of b.jar if forced. even if the client machine has b.jar it will download b.jar along with a.jar as it was specified in the archive attribute and the classes in b.jar will be used when needed , right??

i was just trying to figure out applicability and significance of "user defined packages/jars as extensions" you know...whether they are in applet or standalone applications...
regards
maulin.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any packages in the jar file? Is the ShowChart.class in the top level directory? If not then you need to include the qualified name of the package that it is in when you declare your manifest.
What is important is that you do not mess up the classpath. Jar files must be in the classpath. If you include a jar file inside another jar file, you could mess up the level of subdirectory that it is in, and therefore mess up the classpath.
If you want to use multiple jar files, just get them both in the classpath and it should work fine.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your error message "Can not find main class, program will exit" is a common error message that occurs when a system is not properly configured to run a JAR file (like when the system is configured to use simply "javaw.exe" to run the JAR file instead of "javaw.exe -jar"). But you did mention that you made the example JAR file successfully...
Could you post a very simple example that replicates the problem you are having?. Simple use of multiple class files should not be causing this problem.
I'm adding a simple example of multiple class files use to the "Creating An Executable JAR File" thread.
 
dejie lin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, dirk
I have created a successfully helloworld.jar previously which i followed the exactly same sample you posted on June 5, 02 thanks for that
My problem:
For the following code, I can create a tt.jar successfully, and it works well, but if i enbale those codes followed by **********, although tt.jar can be created successfully, it doesn't work, an Message box " can't find main class, program will exit" will jump out after double clicking tt.jar.
It is just a part code of my project, because there are some printing method in the remining codes, so that i have to enabel these codes whcih followed by ******
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import java.util.*;
//import java.awt.print.*;**********************
//import javax.print.*; ************************
//import javax.print.attribute.*;***************
public class tt extends javax.swing.JFrame {
public static void main (String args[]) {
new tt().show ();
}
public tt() {
initComponents ();
pack ();
}
private void initComponents() {

Container f = getContentPane();
f.setLayout(new BorderLayout());
//attributes = new HashPrintRequestAttributeSet(); *****************
jMenuBar1 = new javax.swing.JMenuBar();
File = new javax.swing.JMenu("File");
JMenuItem pagesetup = new JMenuItem("Page Set Up");
JMenuItem print = new JMenuItem("Print");
File.add(pagesetup);
File.add(print);
jMenuBar1.add(File);
setJMenuBar(jMenuBar1);

JPanel setting = new JPanel();
setting.setLayout(new GridLayout(15,1));
setting.add(new JLabel("table edit"));
setting.add(new JLabel(""));
setting.add(new JLabel("width"));
width = new JTextField("90",4);
setting.add(width);
setting.add(new JLabel("height"));
height = new JTextField("60",4);
setting.add(height);
JButton change = new JButton("change");
setting.add(change);
f.add(setting,java.awt.BorderLayout.WEST);

f.setSize(400,300);
}

private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenu File;
// private PrintRequestAttributeSet attributes; ****************
private JTextField width;
private JTextField height;

}
I am using JDK 1.4 now, there's no compiling error whatever these code were enabled or not.
I was troubled by the problem around one week, hope you can help me.
thanks a lot
dejie
 
reply
    Bookmark Topic Watch Topic
  • New Topic