Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Can i build and compile a JAVA pgm in another JAVA program?

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I'm wondering if i can build a JAVA program 2 within JAVA a program 1, compile the program 2 in the program 1 and then run program 2 from the program 1?

I need to do this because the PipedInput/OutputStream processes need to know which, in this case Oracle table, is being used, to verify both ends of the pipe, right up front!

I've tried every combination of things, and the only one that works is when everything the program needs is known by the system right up front!

And because i have over 300 potential files to process, for me to create a unique program for every file, would result in having to create over 300x4 unique programs!

Right now i am extracting the file requested, passing the parms to a .ksh shell, the .ksh shell assembles the pieces of the program, including table name seleted, compiles the program and then runs the program!

So now i'd like to see if i can put this process into a java program as some of our users are not using UNIX!

Thanks very much for any ideas!

bc
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the Reflection API
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection won't really help you compile and run a Java program; it only can be used to inspect and access existing compiled Java classes. It will be necessary to use reflection (in the form of the Class.forName() and Class.newInstance() methods) to load the code after you've compiled it.

You can invoke Sun's Java compiler like this, or you can use the Runtime.exec() method to run it via the command-line interface.

Although they've always discouraged it in the past, I think there may even be an official Sun document somewhere about invoking the newest version of the compiler from code -- I just can't remember where I saw it.
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Ernest!!!

I think this 'java statement' approach will do the trick and save lots of headaches! thanks also Kashif!

Ernest, i have your book 'Jess in Action' right over my desk and follow your emails, can't wait to use Jess one of these days!

Have a great week!

bc
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by bob connolly:
I need to do this because the PipedInput/OutputStream processes need to know which, in this case Oracle table, is being used, to verify both ends of the pipe, right up front!



I don't fully understand what you are getting at here, but I strongly suspect that there will be a *much* simpler approach to solve this problem. Care to elaborate?
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure Ilja!

Basically, i was trying to get the following PipedInput/OutputStream program to work, by passing an oracle table name into the program, but for some reason, the pipes don't want to connnect when the table_name is passed into the program, but if the name is "hard coded" in the program it works fine!

So what i've done so far, is build the program via UNIX scripts, ie, when a user selects a file from an online screen, the script concatenates the program pieces together ie, header_code + oracle_table_name + trailer_code, compiles it and runs it!

But now i need to package up the process so that it runs via JAVA only components as 1 of our users isn't using UNIX, so i've been able to put most of processes into 2 JAVA programs, except for this one, which extracts XML from an oracle table and validates it using a SAX validator and instead of writing the XML to an external file, it buffers the XML directly into the validation routine, eliminating a huge external XML file!

This feature was "supposed" to be available in 10g!

Here is the program if you might have any ideas about why the Piped files don't want to connect unless the table_name is hard coded, see <<<<<<<<<<<
in the code

 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this whole effort to change the table name? Can you just get table names from parameters or a file?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by bob connolly:
Basically, i was trying to get the following PipedInput/OutputStream program to work, by passing an oracle table name into the program, but for some reason, the pipes don't want to connnect when the table_name is passed into the program, but if the name is "hard coded" in the program it works fine!



Can you show us how you tried to pass the table_name into the program? I'm convinced that we should be able to get it work.
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, actually, i am passing the table name into the program in:

this.TABLE_NAME =con.table.toUpperCase();
this.table_name =con.table.toLowerCase();

but if i didn't have that table name hard coded initially in this line of code:

public static final String IN_TABLE=new String("fn_ll_lossmit"); <<<<<<<

, the pipes don't seem to want to make the connections, must have tested this at least 10 times!

But i will re-test it again this morning just to be triply sure!

Thanks!
bc
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ilja!

Thanks for the prompt to go back and look at this from the top! as it seems to be working fine by passing the table_name in, great news! and i'm now trying to figure out what got me on this track to begin with!

So appreciate everyone's assistance on this and i quess the moral of this distraction is, the only way to be an optimist in this business is to be a pessimist, when the analyst, programmer and tester are one in the same?

But on the bright side, i now know how to build, compile and run a JAVA program from within another JAVA program, very nice! and i wrote a Groovy script to do a similar thing!

Have a great week all!
    Bookmark Topic Watch Topic
  • New Topic