Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / July 2006

Tip: Looking for answers? Try searching our database.

using an executable jar file in a new java program

Thread view: 
jsaucedo@gmail.com - 28 Jul 2006 02:54 GMT
so i can run this parser i downloaded at
http://htmlparser.sourceforge.net/
using the following

C:\ics\111\htmlParse>java -jar bin/htmlparser.jar "http://www.bbc.com"

however, what i want to do is expand the functionality in my java
program by calling the parser class in the jar executable.

i'm not sure what i should do to have my program below compile with
giving me an error about not being able to find the package.

where i'm confused about
-import statement?
-classpath needed for jar file when I compile?
-do i need to unjar the file? thanks.

public final class Craig{
  public static void main( String[] _args ){
     Control _c = new Control( );
     _c.start( _args );
  }
}

final class Control{
  Control(){
  }
  void start( String[] _args ){
     System.out.println("test2");
     Parser p =new Parser("http://www.NYT.com");
  }
}
Andrew Thompson - 28 Jul 2006 08:15 GMT
(Possible repost on my part, my apologies if this appears
twice.)

> so i can run this parser i downloaded at
> http://htmlparser.sourceforge.net/
[quoted text clipped - 10 lines]
> where i'm confused about
> -import statement?

Yes, it is required.  (pauses) Was you question different to that?
Maybe you should be more specific, rather than expect your
reader to guess your meaning.

> -classpath needed for jar file when I compile?

Again yes.

[ but taking a wild stab at the wider question - 'How?' ]

You can add other archives on the classpath at time of
compilation or execution.  The secret is to specify it
in the '-classpath' argument when compiling/running.

The 'classpath' option can be abbreviated to 'cp' on more
modern VM's.  Here is how it might look.

CLI>javac -cp .;bin/htmlparser.jar CallsClassInMainArchive.java

The "-cp.;bin/htmlparser.jar" is the part of interest.

   -cp
- the classpath - add these places to this invocation

   .
- the current directory (assuming your in the same
 directory as the Java code you are writing, or at the
 'root' package of your code - this will add your code
 into this new classpath)

   ;
- separator for multiple class path entries

   bin/htmlparser.jar
- the location of your external archive of interest.

> -do i need to unjar the file? thanks.

No.  Java tools as well as the classes are well set-up
for getting resources (classes, images, help files..)
directly out of Zip files (a Jar is just a specialised
form of Zip file).

BTW - Please use Upper Case letters at the start of
sentences.  It helps the reader to spot where breaks are,
and therefore makes messages easier to understand.

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.