kolursri has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Importing a jar file in a perl script
by GrandFather (Saint) on Jan 12, 2011 at 06:58 UTC

    A jar file is a Java Archive file. How do you expect to use it from Perl? Java is not Perl. What are you actually trying to achieve?

    True laziness is hard work
Re: Importing a jar file in a perl script
by tilly (Archbishop) on Jan 12, 2011 at 08:12 UTC
    At a guess, the simplest solution is to write a stand alone Java executable, and then call that from Perl as you would any other executable.
Re: Importing a jar file in a perl script
by Your Mother (Archbishop) on Jan 12, 2011 at 15:19 UTC
Re: Importing a jar file in a perl script
by chrestomanci (Priest) on Jan 12, 2011 at 10:56 UTC

    What exactly are you trying to do?

    At the most basic level a jar file is a zip archive, that happens to contain some java class files, metadata files, and other files needed by a java program, so if you just want to extract the contents of the jar file, or parse the metadata, then you should look on CPAN for modules that can parse zip archives. Archive::Zip::MemberRead looks a likey candidate.

    If your jar file contains a complete java program that you need to run, then you can start it with a system, exec open or backticks call the same as any other external program. eg:

    my $cmd = 'java -jar '.$jar_file_path.' '.join(' ',@args); system $cmd;

    If your jar file is a library of some sort, that your want to access from perl, then you probably want something like Inline::Java as suggested by an Anonymous Monk further up this thread, before you do that, I think you should step back, and consider what you are actualy trying to do. Could you access what the Java library is accessing via a lower level API? If you have the source of the Java library, could you port the stuff you need to perl?