Advertisement
hakonhagland

java-wrapper

Aug 12th, 2021 (edited)
1,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.68 KB | None | 0 0
  1. use feature qw(say);
  2. use strict;
  3. use warnings;
  4.  
  5. my $wrap_name = 'Wrapper';
  6. my $source = <<"END_JAVA";
  7. import com.utilties.SampleClass;
  8. class $wrap_name {
  9.     public static void main(String[] args) throws Exception {
  10.         String result = com.utilties.SampleClass.SampleMethod("string1", "string2");
  11.         System.out.print("Result: " + result);
  12.     }
  13. }
  14. END_JAVA
  15.  
  16. my $fn = $wrap_name . '.java';
  17. open ( my $fh, '>', $fn ) or die "Could not open file '$fn': $!";
  18. print $fh $source;
  19. close $fh;
  20. system 'javac', '-cp', '.:/opt/apps/batch/utilities/Utilities.jar', $fn;
  21. my $output = `java -cp .:/opt/apps/batch/utilities/Utilities.jar ${wrap_name}`;
  22. say "Got output: '$output'";
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement