Results 1 to 8 of 8

Thread: How to import/use .jar files?

  1. #1
    Join Date
    Mar 2005

    How to import/use .jar files?

    I'm familiar with how to do imports in C/C++, but this thing with jar files has me mystified -- and the question seems too basic to find the answer anywhere.

    A coworker gave me a bunch of .jar files, each with a number of classes I need to incorporate into my code. However I don't know where the heck to put the files, or how to write the import statement to import the file correctly.

    I've been told I have to define the CLASSPATH environment variable, so I set it to C:/java/tools/, but just placing my jar files in there doesn't seem to work. I feel like I'm missing something really basic here.

    Help please?

  2. #2
    Join Date
    Nov 2003
    Jerryville, Tejas
    You put the JARs on the classpath and the CLASSES in your imports. For Windows that looks like:

    set CLASSPATH=C:/java/tools/lib1.jar;C:/java/tools/lib2.jar;%CLASSPATH%

    Then your imports in your code are for fully qualified classes (best practice) or wild-carded packages.

    import java.io.*;
    import java.math.BigDecimal;
    "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Brian W. Kernighan

  3. #3
    Join Date
    Mar 2005
    Hey, thanks! That worked -- but one question. Given the .class files are encoded, how do I know the exact path to the object in question for the import statement, or even what objects are available, or what their public properties and methods are?

    In C++ there would be a header file that would be a public declaration of all the object handles, but here I see nothing? Is there a tool I would use to do this?

    For example, one of the .jar files contains an "activityID.class" file that contains an object "activityID". But the import I was told to use was something like:

    import com.pm.public.someotherthing.somethingmore.activityID

    even though the actual file is in C:\java\tools\activity_lib.jar

    Seems like this is something that would be covered in the basic documentation, but again, I see naught.

  4. #4
    Join Date
    Dec 2002
    Calgary, Canada
    if java doc was not created for the classes that you are using then its a tough one.
    Essentially in Java any reasonable developer will produce a Java doc with their distributable jars.
    Now if you were to use any Java IDE then your work is mostly done(e.g eclipse, or IntelliJ).
    If you use one of the above and add the jar files to the libraries that are required for the project then context sensitive menu will appear to display any packages available, classes in those packages and public methods and properties etc.
    Java IDE work just like C/C++ IDE's
    To access public methods of a class
    SomeClass sc = new SomeClass();
    or property will display after the dot operator.
    Last edited by Khalid Ali; 04-06-2005 at 11:28 AM.


    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  5. #5
    Join Date
    Mar 2005
    JAR Files [17/18]

    Each applet file means separate request
    .class files, images, audio files, etc.
    Java ARchive file can hold all applet files
    Use jar tool to archive necessary files
    Use jarsigner tool to digitally sign JAR file
    Use ARCHIVE attribute in APPLET tag
    <APPLET... ARCHIVE="foo.jar" ...>
    Archive searched before requesting server file
    Operation Command
    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
    (version 1.1) jre -cp app.jar MainClass

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

    To invoke an applet packaged as a JAR file <applet code=AppletClassName.class
    width=width height=height>

  6. #6
    Join Date
    Mar 2005
    Thanks for the responses -- so basically, unless the develop sends me documentation with the jar file, I'm pretty well up a creek? Like I said, comingfrom a C++ environment, that seems a little weird, but I can live with it. Does the Jar file at least have residual directory information so I can see what the package names ought to be? I know I can extract the individual classes... but that does me little good if I can't reference the full package name.

    Thanks again!

  7. #7
    Join Date
    Dec 2002
    Calgary, Canada
    a jar file is nothing but a zipped file just with different extension.
    You can open a jar file in your favourite zip/unzip utility (I use WinRAR) and view the package structure as well as classes in them.


    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  8. #8
    Join Date
    Aug 2013
    I also have problem relating with the jar file..
    what should i do??
    I got Packages does not exist error..
    Help me please..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10743 seconds
  • Memory Usage 2,912KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates