This discussion is archived
8 Replies Latest reply: Feb 1, 2010 9:41 AM by 807580 RSS

java application to jar file

807580 Newbie
Currently Being Moderated
I use eclipse and i have a java program which run without any problem,
but when I export this program to jar file(export->java->jar file)
I get the jar file and when I run this jar file ,it run for few seconds then it stop to run,despite in eclipse it run .
I don't know what is the problem
  • 1. Re: java application to jar file
    807580 Newbie
    Currently Being Moderated
    whats your program contains ?
  • 2. Re: java application to jar file
    807580 Newbie
    Currently Being Moderated
    a server Socket which wait connexions from differents hosts and then every host is traited by a thread.
    in eclipse it's work without any problem
  • 3. Re: java application to jar file
    793415 Pro
    Currently Being Moderated
    netcom_ wrote:
    ...I get the jar file and when I run this jar file ,...
    How do you run it? If you are not running it from the command line, do that - any output should appear on the prompt.

    Is your code [swallowing exceptions|http://pscode.org/javafaq.html#stacktrace]? If so, change that to dump the stack trace.
  • 4. Re: java application to jar file
    807580 Newbie
    Currently Being Moderated
    I found the error;I have a file.txt under the bin of the project,but when I export the project this file
    don't appear so when I run the jar it doesn't find the file.this file is neccessery for the project.
    I will read the content of this file,So I think after exporting the project I make it with the jarfile and I use this code to read the file.
     
          InputStream is = getClass().getResourceAsStream("/test.txt");
            
              byte[] buffer = new byte[4096];
            String lin= is.read(buffer);
                
              is.close();
         
    but also it doesn't find the file.
  • 5. Re: java application to jar file
    793415 Pro
    Currently Being Moderated
    netcom_ wrote:
    I found the error;I have a file.txt under the bin of the project,but when I export the project this file
    don't appear so when I run the jar it doesn't find the file.this file is neccessery for the project.
    I will read the content of this file,So I think after exporting the project I make it with the jarfile and I use this code to read the file.
    ...
         String lin= is.read(buffer);
    ..
    Huh?!? Since InputStream.read(byte[]) returns an int, I do not understand how that compiles, let alone runs.

    But any way you cut it, that I/O code was utter rubbish.
    but also it doesn't find the file.
    When reporting problems, please [copy/paste any error messages|http://pscode.org/javafaq.html#exact] you are getting.
  • 6. Re: java application to jar file
    807580 Newbie
    Currently Being Moderated
    I want that when I extract the jarfile ,I found the file .txt under it(like plugins,src,.project,.classpath..)
  • 7. Re: java application to jar file
    793415 Pro
    Currently Being Moderated
    netcom_ wrote:
    I want that when I extract the jarfile ,I found the file .txt under it(like plugins,src,.project,.classpath..)
    You replied to my post. I cannot see why, since you seem to have veered off into some entirely separate topic.

    In your mind, does anything you said in your last post equate to an answer or reply to my last reply? If so, how is it related to what I said?
  • 8. Re: java application to jar file
    807580 Newbie
    Currently Being Moderated
    because ,I get some exception and I guess differents solutions ,for that mybe I write something separetly to the topic.
    So the exception that I get is
    java.lang.noclassdeffounderror: lotus notes exeption