Calling javac in java code- possible?

I'm writing a reasonably large app which can be run with X11 (using swing etc) or as a CLI app. This is basically because it will be useful in many different circumstances, for instance where there is no swing or X support, it'd be pointless building it with those capabilities. Now the easy way to do this, of course, (and I'm pretty lazy so I'll do it this way) is to write the base app, and then on one copy of it create a CLI, the other a GUI, and then give users the option of which to use. Also because of the size of it, I believe it'd be better for users to compile it themselves, so it is tailored perfectly (esp. where different J/SDKs are used.
Now what I decided to do was just fire out some javacode to take command line options to compile- makes sense I thought, then I hit a problem... Is it possible to call javac in a java app? Can I have a line of code to call javac in the same way I could in a bash script? For reference, here is my code thus far- the lines that need replacing are the print lines saying which option is being used...
class MakeII {
     private int choice;
                public static void main(String[] args) {
                         if (args.length != 1) {
              System.out.println("Bad choice/ no choice- please try again");
          } else { MakeII myComp = new MakeII(args[0]); }
     public MakeII (String choose) {
          System.out.println(choose);
          if (choose.equals("--make-x11") ) {choice = 1;}
                         else if (choose.equals("--make-sh") ) {choice = 2;}
                         else if (choose.equals("--make-full") ) {choice = 3;}
                         else {choice = 3;} //any error, assume full version
                         switch (choice) {
              case 1: System.out.println("x only"); break;
              case 2: System.out.println("cli only"); break;
              case 3: System.out.println("full ver"); break;
}And yes I know its ugly code, I just prefer to seperate everything out at this stage- I also know I've done everything the long way too, its for maintainability.

jamesCondron wrote:
Employer? Nah- this is a none-paid bit of project, more voluntry than anything, but I regret saying I would. Can't turn around now and say no... And I can't use anything but java because of how the project started, and the guys I'm working with; because Its server side stuff that needs to be distributed and portable I'd rather use python (or perl, but not quite that good) but ah well- what can you do?First off: challenge the requirement that it must be portable. More often than not, that's bogus. Beyond that, dude, you hold all the aces. They don't wanna pay but they still expect you to do it? That means they don't have a clue where to start. Baffle 'em with science, shouldn't be too hard. If it's lines of code they want, write them a bit of custom JSTL and show 'em how 2 lines of JSP can equate to 200 lines of Java, thus proving that lines-of-code is an utterly worthless metric. Then ask them if they want it done or not, and mumble a lot about going to the beach

Similar Messages

  • How to calling JVM in java code

    Hello!
    I continued my homework -- a java IDE written in java. I've asked how to compile the java code in my IDE here. Thanks to Franck_Lefevre, he showed me this:
    import com.sun.tools.javac.Main;
    public static boolean compileSource(String filename) {
    String[] javac_args = { filename };
    int result = Main.compile(javac_args);
    return (result == 0);
    now the problem is how to RUN the .class file on the JVM. Is there a method corresponding to this, ie also using java tools? or some better ways? I've tried a few ones but they don't work well.
    I really appreciate you who helped me so much.

    Planetar, remember to read the API docs for the
    complete method signature for Class.getMethod.Good point, take my code example as just a rough guide of what to look at in the API docs. Namly,Class, ClassLoader and Method.

  • Do you know how to call RDF with java code?

    Say me a tip!
    Environment:
    Linux, Reports 6i,java beans, jsp
    My mission is to run a report with java code.
    But I don't know how to.
    Basic flow is :
    On web browser, call jsp a program and
    that jsp call a java module,
    and the java module call a reports RDF with parameters
    I don't need reponse message from rwcgi60 or rwrun60.

    hello,
    the easiest way is to use the regular HTTP request to either the servlet or the CGI to run a report request from within a java-class.
    regards,
    the oracle reports team --pw                                                                                                                                                                                                                                                                                                                                                                                       

  • Is there any way to call VBscript from java code

    hi all
    i have a question about calling a VBscript from my java code. can we do that in java? if so, any sample i can look at it. thanks in advance.

    it is not the scripting used in the browser. it is
    the scripting that builds VB program used in MS SQL
    server like the bulk loader. i need to call this
    loader to load xml data into the database.So you have a .vbs file that you want to execute?
    Runtime.getRuntime().exec("cmd.exe /C start " + fileName);
    Where fileName = the path to your .vbs file.

  • How to call codec in java code

    i want to call a jmf codec for video compression form direct capture device, i dont know how to call codecs of Jmf i am using jffmpeg how to implement it can any one please let meknow

    Lot of examples are given in the below link
    http://www.oracle.com/technology/sample_code/tech/java/jsp/oracle9ijsp.html

  • Call JCo from java code?

    My problem is that i need to access SAP R/3 backend via connector frame work
    using JCo please let me know the directory structure for an application that addressess the same.

    Hi Sumit
    Check the below link it might be helpfull for you
    http://help.sap.com/search/highlightContent.jsp
    http://help.sap.com/saphelp_nw2004s/helpdata/en/18/6052429f2dbd30e10000000a155106/frameset.htm
    If you face any issues or need any speacific information about creating a JCO connection do let me know.
    Message was edited by:
            rajat anand

  • Calling simple Java Code from 11g BPM

    Hi,
    I know this has been round the houses but I cant find a satisfactory solution for my scenario. I would like to call some simple java code from BPM (11.1.1.6). I guess I need to expose it as a service but it seems overkill to be via soap so any advice you can give would be much appreciated. Creating a jar that I can call somehow would be perfect.
    This is my scenario:
    - I am creating a Security POC for BPM
    - The BPM Process is exposed as a web service and authenticated using SAML
    - I am testing by calling the WS from OSB
    - I want to be able to get the WLS Principal and display the username and the roles for the launching user, from within the BPM process
    - This is possible using some simple weblogic client api code shown below
    - So all I want to do is call this code from BPM somehow
    - Anyone point me in the right direction ?
    cheers
    Tony
    subject = Security.getCurrentSubject();
    for(Principal p: subject.getPrincipals()) {
    if(p instanceof WLSGroupImpl) {
    groupList.add(p.getName());
    } else if (p instanceof WLSUser) {
    principal = p.getName();
    }

    The problem to communiate java classes and forms solved !
    i have add my .jar file to $OA_JAVA/oracle/apps/fnd/jar and now i can communicate between forms and java.
    I can create an object, i can get simple message from class, but when i try to create
    ServiceFactory factory = ServiceFactory.newInstance();
    ive got ORA-105100...
    can anybody help ?

  • System call fom Java code

    Hi all
    I hope someone over here might answer my problem.
    I need to run a Shell script form my Java code, which does perform some operations like writing/copying files to a specific directory and my Java code then starts reading the files and do necessary stuff like parsing it for some info inside the file.
    If I make a system call from my Java code, how do I know when the shell script is done executing completely? Just to make sure that my Java code execution starts only after the shell script has executed.
    If anyone has come across such a scenario, please reply to this topic. A sample code wud be a bonus for me :)
    Thanks
    -Uday

    If you've never used Runtime.exec, read this carefully first:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    MOD

  • Use of Java Code within the generated XML Forms Stylesheets

    Hello,
    is the use of Java-Code possible with the XSL-Files generated by XML-Forms, as possible in standard XSLs? I know that this would mean a modification.
    kind regards,
    Marco

    Hi Marco,
    I "executed" some java code within XSLs file. I have quoted the word executed because I didn't really run java code, but I used a simply trick that I describe you below.
    Into your XSLs put an iframe which is hided (it has an height of 0 pixel). As src of the iframe put the address of a portal component which execute your code (in my case calculate some PCD URL of some pages into a defined role). As result of component execution, I use the response.write method in order to execute some jscript code, which is able to interact with the HTML generated by XSLs files, for example in my case response.write put the PCD URL into a drop down list placed into the "edit" form.
    This works fine. I don't know if is suitable also for your case, anyway could be a hint, but pay attention to Roland's recommendations.
    Ciao
    Roberto

  • Where to Place Custom Java Code

    We are planning on adding customized Java code to Identity Manager 8; XPRESS will be used to call the customized Java code.
    Questions:
    1) Where does this customised code reside in the Java Application Server (Glassfish)?
    2) Does the customized Java code have to be packaged in a JAR file?
    Many thanks for your help.

    You would deploy custom Java code along with the IDM war/ear file. Classes go in the WEB-INF/classes/ folder, JARs in WEB-INF/lib/ and that is application server independant.
    Class files or JARs? Do you have any build process for your IDM, like the custom build environment CBE, then the source files might end up as class files; if you are using a seperate build environment for those custom classes, then packaging them in a JAR would be the way to go.
    Generally speaking, using a JAR for your custom code is neater; whether a class in classes/com/foo/bar/Foo.class or in lib/myfoobars.jar takes precedence over the other is up to the class loader and depending on your application server and its settings, the behavior might vary - so be careful about mixing use of those locations.

  • Simple Question Calling methods from Java files through JSP without JVM

    Hi.
    I've got a simple question (forigve my newbieness)...
    If I'm running Tomcat can I exectue a method in a compiled Java file from a JSP page without having the JVM installed on the server?
    Any thoughts or additional comments would be appreciated.
    Many thanks.

    No... but that's because you can't run Tomcat without
    a JVM installed on the server.
    If you are running Tomcat, you are running a JVM for
    the JSP pages to run in, in which case, yes, the JSP
    pages can call the other Java code... as long as it's
    in the classpath.Thanks a lot for the replies.
    So just to check, if I sign up with a hosting company that offers Tomcat then the JVM will be installed on the server and I can call other Java code as long as it's in the classpath?
    I just want to make sure before I sign up with a hosting company =D
    Thanks again!

  • How to call xml from java

    Hi
    I want to use xml for updating files in an existing jar . so i want to call xml from java code and then come back to java code and do the remaining work in java code, pl guide me how to do this . what APIs are helpful for this regard
    Thanks

    You can't update files in a jar. Even if you could, you wouldn't use XML for that. You don't call XML. XML is not a programming language. So, basically your entire question is misguided.

  • Calling Remote-Enabled JAVA Module from Web Dynpro Java

    Anyone have a clue how I can call a Remote-Enabled JAVA Module in ECC from a Web Dynpro Java app?  I'm on Portal 7.0.  When I try and create an Adaptive RFC model in NWDS and put in the Function Module name (CFG_API_FIND_KNOWLEDGEBASES) or its Function group, that RFC is not returned for me to import.  Can I not use this method to get at this function?
    (I CAN call this function module and run it from the old SAP Business Connector software.  That, however, does not help me get it into my Web Dynpro app.)

    If anyone stumbles upon this thread, the long and short answer is you can't call a Remote-Enabled JAVA module in SAP from Web Dynpro Java.....using Adaptive RFC.
    You can, however, if you create your own session and function call directly in Java code and give up on being able to use Adaptive RFC.

  • JNI Calling Java code when attaching to existing JVM

    I've got an Active/X that runs within IE, and also makes JNI calls (via the Invocation API) to Java code. Running within IE means there's already a JVM around, so I attach to it using JNI_GetCreatedJavaVMs
    This is fine. The problem is that I can't use the JNI findClass() to locate my Java classes, because I have no control over the classpath that the JVM is using to locate classes. The only solution I can think of so far is to either add my classes as part of the JVM, OR find out the classpath of the existing JVM (using System.getProperty("java.class.path") and copy my classes into that directory.
    Both solutions look ugly - anyone know of a cleaner way ?
    Mark.

    Toby, thanks for the reply.
    You're welcome.
    I notice from elsewhere on this forum, you're clearly a JNI expert.
    I've been known to work with it a little from time to time. =)
    My code has to work with JDK 1.1 so URLClassLoader is out. Writing my own classloader is fine, but how do I load it in the first place ? Is there something in JNI I've missed ?
    Possibly. Using DefineClass() you can load a class into the virtual machine, given it's byte-code. Now here's the tricky part. First, write your ClassLoader. It will be easiest if it doesn't rely on any other classes other than what is core to the JRE. Once you compile that classloader, you then need to include the bytecode as a resource in your executable/dll. Then, at runtime, you can load that resource, and use DefineClass to class-load it. Once you've class-loaded it, you can use NewObject, GetMethodID, CallXXXMethod, etc... to do the other class loading you need to do.
    Trust me, this really isn't as hard as it might sound.
    God bless,
    -Toby Reyelts
    As always, I recommend you check out the free, open-source JNI toolkit, Jace, at http://jace.reyelts.com/jace.

  • Call to JAVA code from VB

    i plan to write the interface(Presentation of the software, plz don't mistake it for java interface) in VB and all logic in JAVA...........Can you help me out. Is this possible? I mean can i make calls to JAVA code from VB ......?? Some references plz
    Thanks & Regards,
    Gurmeet S. Budhraja

    You can link the 2 projects VB and J# not Java, 'cause I don't think it's possible to like Microsoft to Sun

Maybe you are looking for

  • Can I sync many iPods with one account on many computers?

    My company has purchased iTouch's for each of our departments and we're loading iPharmacist onto them. 1. Can I create one generic iTunes account (e.g. [email protected]) for all the iTouch's to use? 2. If these iTouch's are set up by connecting them

  • Showing only Approved Metapedia Terms

    This question is two fold: 1) Is there a way to only show approved metapedia terms? 2) How have others managed their metapedia terms in a "multi-tier" environment (dev / qa / prod)? Do you promote your terms / changes through different environments o

  • Error 2005

    I have a new PC,windows 7.I wanted to syns my iPod shuffle 4,but it failed.I tried to restore but it failed,too. Every time when I connect iPod to PC, itunes automatically starts restoring iPod,but detects error at once:"An iPod has been detected, bu

  • Component reference point in ultiboard

    The default setting for component reference point is the center of PIN 1 of the part. however, for many SMT machines, it reference to the center of the component (not a pin).  How doImodify it without going through every component in the database? So

  • Can this inspection lot type 06 be changed

    Hi! all could you please suggest me on this this is related to QM When using the standard SAP customer returns process an inspection lot is automatically created. Can this inspection lot type 06 be changed to allow stock to transferred to u201CUnrest