Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

How to call .jar files from perl program

by Anonymous Monk
on Dec 17, 2008 at 07:04 UTC ( #730847=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am using Saxon.jar file to parse some xml files. Is there a way to call the jar file from the perl script.

i have some 100 xml file in a folder, in the same folder i placed the jar file.

Thaks,
sid

Comment on How to call .jar files from perl program
Re: How to call .jar files from perl program
by Anonymous Monk on Dec 17, 2008 at 07:29 UTC
    Use system or exec, just like you would for any executable.
Re: How to call .jar files from perl program
by dHarry (Abbot) on Dec 17, 2008 at 14:31 UTC

    To elaborate a little further: exec executes a system command and never returns, system does return. I'd prefer system, something like:

    # @args = ("command", "arg1", "arg2"); my @args = ("java", "-jar", "Saxton.jar"); system(@args);

    You can inspect the $? variable to check what/if anything went wrong. If you want to capture the output of the command you can use backticks or qx//

      While we call a Jar file from a perl application using System() the Jar file is invoked and run normally. At that time we are not able to access the calling Perl Application. When we close the called java application then we are able to access the Perl application. On the other hand if we use the EXEC() to invoke the jar file then the jar invoke and the perl application will close. Can you please suggest how we can call a jar file from the perl application and access both the application(perl and jar)simultaniously?

        You didn't mention this in your original post. Maybe you should elaborate a little bit more what exactly it is you are trying to achieve. There are several modules around to use Java from Perl (or the other way around). For example Java a module that allows you to talk to a JVM (local machine or remote), and with Java::Import you can use Java classes in Perl. See below in other responses for more suggestions. Obviously you want to parse XML document and apply XSLT transformations, there are ways of doing this in a more Perlish way. Are you stuck with Saxon? And also where does Perl exactly come in? You could also consider a pure Java/Saxon solution. Please elaborate the problem a little bit more to clarify.

      While we call a jar file from the perl using the following syntax my @args = ("java", "-jar", "Saxton.jar"); system(@args); then it invoke the jar window and also invoke a command prompt window as well. Can any one tell how I can disable the command prompt that is invoked while I call my jar file? I just want to run the jar file, not the command prompt.
      While we call a jar file from the perl using the following syntax my @args = ("java", "-jar", "Saxton.jar"); system(@args); It is opening the jar application along with a command prompt window. Is there any way to disable the command prompt window?
Re: How to call .jar files from perl program
by tmaly (Monk) on Dec 17, 2008 at 14:43 UTC
    You could also use Inline::Java to call jar files. You essentially put all your java code in a string plus the import line for the jar. I usually declare a simple java class that calls the jar code. The Inline::Java will generate the translation from the Java class to the perl domain then you simply instantiate the object in perl and make the call to the method that in turn calls the jar code.
      Can you please give me an example how do you call a jar from perl so that both the application run simultaniously?
Re: How to call .jar files from perl program
by anupamde (Initiate) on Jun 19, 2009 at 11:06 UTC
    While we call a Jar file from a perl application the Jar file is invoked and run normally. At that time we are not able to access the calling Perl Application. When we close the called java application then we are able to access the Perl application. Can anyone one tell me how we can access both the application simultaniously?

        PLZ GIVE THE WHOLE COMMAND<\p>

Re: How to call .jar files from perl program
by Anonymous Monk on Aug 30, 2013 at 09:00 UTC
    getting error:-Failed to load Main-Class manifest attribute from <jar file>
      and then what happened?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://730847]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-12-19 03:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (70 votes), past polls