• 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

Directory, File, Jar input problem

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've written a program that reads files from vaious locations on my drive to populate JComboboxes. It works file when I run the program through an IDE, but when I Jar the Classes it will not work.

Here is an example:

cboCrop = new JComboBox();
String line = null;
BufferedReader br =
new BufferedReader(
new BufferedReader(new FileReader("C:\\Test\\Data\\Jclimate.txt"));
while ((line = br.readLine()) != null)
{
cboCrop.addItem(line.substring(3, 3 +12));
}


Any suggestions will be appreciated. Thanks...Ronnie
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'will not work' isn't precise enough.

Is there a general 'catch (Exception e)' clause, which is silent as the grave of the dead programmer ({})?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that it will not find the file when I run the program in my JAR.

Thanks.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are getting a ClassNotFound exception?
In order to find a class file within a jar, either the classpath has to contain the jar file:

Or you create an executable jar and run it with the -jar flag:
 
Ronnie Coh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, ClassNotFond Exceptions. The program just hungup. I managed to get it to work by putting the Data and Text files outside the Jar in the same foldre as the jar.

Not the Jar will not finded the two Jars that war included in the jar. I uded a Manifest file file:

Main-Class: folder.program
Class-Path: folder.jarone.jar folder.jartwo.jar

But it will not find the two jars. Any ideas? Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic