How to compile in Java Source???

Hello,
I'm studying a way to compile java files to class files in the java source. I have use the sun.tools.javac.Main to do this, but I have noticed that it aint recomended to use. I also wan't to get the possible errors from the compiler (if java file was wrongly made). The problem using the sun.tools.javac.Main is that it won't guarantee that it works in every platform or in future releases of JDK. Does the JDK 1.4 even support it? (My IDE environment prevents to use JDK 1.4). So the question is: is there a way to compile on the fly (to memory or to class files)? Do I really have to run some external process that compiles the file and then try to get somehow possible errors? That seems to me litle too indecent to use. Any suggestions?
Thanks,
Petri Tuomaala

Hi guys,
I have also needed to compile Java source from within a Java application. Here is the best solution I came up with:
Process proc = Runtime.getRuntime().exec( "
C:\\Temp\\Jikes -bootclasspath C:\\jdk\\jre\\lib\\rt.jar C:\\Java\\com\\sts\\utility\\Utility.java" );
BufferedReader br = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) );
String line = null;
while( (line = br.readLine()) != null ) {
System.out.println( line );
proc.waitFor();
I used Jikes http://oss.software.ibm.com/developerworks/opensource/jikes/ because it compiled my source quicker than Javac did - 250 millseconds for Jikes compared to 2750 milliseconds for Javac.

Similar Messages

  • How to compile a java source from a java program

    Hi .
    I would like to know how to compile my java source from inside an execution of a java program.
    Is there another way than rather use :
    Runtime.getRuntime().exec("javac myFile"); ?

    you can and cann't use the source code of javac... or maybe use jikes...

  • How to compile a java file in J9 for windows mobile 5.0

    I have downloaded J9 for windows mobile 5.0 and need help on how to compile a java file.

    You can compile your source code using J2SE ;)
    may be this is important for you:
    http://awareness.ics.uci.edu/~rsilvafi/pocketPC/index.
    html
    Regards!!!Actually i am using some eSWT related classes also.. so is there any way to compile from the J9 environment using J9 console..

  • How To Compile Within Java

    Hi Everybody,
    I have a serious problem. I want to compile a Java file withing another Java program, without using the "javac" command or this compiler. Is there any function or class which helps compile a Java source file created withing another Java Class file, So that the new Java source file will not be available to the outside world?
    Thanks,
    TechnoSam.

    I'm pretty sure that you can create a class in memory by passing it a stream of bytecode. From this you could create a new instance and then proceed as normal. However, you're going to need to know how to create that bytecode and I guess that you don't want to have to implement a 'virtual' compiler from scratch. I don't know of anything that can do this for you but I wouldn't be surprised to find that somebody's had a go in the past.
    Perhaps your requirements would be satisfied by compiling your dynamically created source using javac to a temp file and then deleting that once you had instantiated the object? This would do something like what I think that you're after but even then you would need to accept that others would be able to access your class definition by reverse-engineering your source-writing routine, (whether or not it was obsufacated).
    Can you say anymore about what you're trying to achieve?

  • How to compile a java file which is in memory?

    how to compile a java file which is in memory?
    such as:
    String s="class MyClass {....}";
    how to compile the string?
    thx

    come on ...That was a perfectly valid solution.
    Do you know how to call the sun.* compiler? If not then search the forums for it. If that interface still exists (which it might not in newer versions) you then will create a string stream from your class and pass it to that.

  • How to compile Oracle java strored procedure in Putty

    I have created a java strored procedure , which would be invoked by oracle function.
    This java stored procedure is get compiled via SQL plus. While compiling by the use of putty , it shows lots of compilation error .
    How to compile Oracle java strored procedure in Putty??

    You'll need to add the j2ee.jar to your classpath. Usually you'll have to add some jars from your app server to your classpath as well.
    For example (using weblogic):
    javac -classpath c:\java\j2ee\j2ee1.3.1\lib\j2ee.jar;c:\tools\appserver\weblogic\wl7.1\lib\weblogic.jar
    HelloServlet.java

  • How to compile a java file(Servlet) in J2EE v1.3.1

    This is my first time using J2EE instead of J2SE!!HOw to compile a java file in J2ee\bin because there is no javac in j2ee and when i compile in J2se i got
    G:\j2sdk1.4.1_01\bin>javac HelloServlet.java
    HelloServlet.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    This mean it doen;t support servlet in J2se!!so how can /what command to compile a servlet java file in j2ee.Thanks

    You'll need to add the j2ee.jar to your classpath. Usually you'll have to add some jars from your app server to your classpath as well.
    For example (using weblogic):
    javac -classpath c:\java\j2ee\j2ee1.3.1\lib\j2ee.jar;c:\tools\appserver\weblogic\wl7.1\lib\weblogic.jar
    HelloServlet.java

  • How to compile a Java file

    Hi All,
    I am extending a seeded CO and when I try to compile it in JDev , it asks for many class files the seeded CO imports.
    I have copied all those imported files to my local system and when I try to compile , it still throws an error that some class files used by the classes imported in seeded CO are missing. Now this goes on and on. ( Seems entire server needs to be on my local system).
    Now I decided to port the custom CO to server and compile it there. Even this seems to be a hard task for me as the javac command is not working on the server. It throws following exception
    Exception in thread "main" java.lang.ClassFormatError: com.sun.tools.javac.main. Main (erroneous method access flags)......................................
    Pls suggest how to compile a java file , as downloading entire server classes is a herculean task for me.
    Thanks,
    Srikanth

    Hi Avajain & D.Ram ,
    Thanks for the reply.
    I have downloaded around 70 dependent class files to local system. Now the CO is getting compiled correctly.
    I am extending a region level controller in Payroll page where in I have to default the salary to a predefined value.
    This field is having a VO attribute to it. Now can I go ahead and set a value to the MessageTextInput or should I extend the VO to replace the desired value in the place of already queried value.
    Thanks,
    Srikanth

  • How to read the Java source code (in Netbeans)

    I use OS X10.5.5, NetBeans 6.1 and JSE 6 on a 64 bit mac.
    When I downloaded NB6.1 it had JSE 5 as it's default (and only) java platform. I ran Software Update to get Java 6 from Apple, used the Java Prefrences utitlity to set JSE6 as default. In NB I added the JDK6 platform, registered the JDK6 javadocs and noticed that I also have the option of registering the Java source code.
    I have three questions:
    1) How do I make JDK6 the default in NetBeans. The JDK5 keeps being default after I did the steps above and I don't see anywhere to change that.
    2) How do I read the Java 6 source code? I can see sun provides [source code| http://download.java.net/jdk6/] for their supported platforms. I dont see Apple doing the same for its JDK port. What would I need to do to get to read the java SE6 sources? or is it actually hiding somewhere in the /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home hierarchy?
    3) Where does the JVM look for the binary code to run when I make a call to, say java.util.ArrayList or any other library. In my naivety I would have assumed it would be a .class file somewhere in the java Home folder, but I don't see anything like it.
    thanks in advance,
    chris

    This is taken from the help included with netbeans. In response to question 1.
    By default, the IDE uses the version of the Java SE platform (JDK) with which the IDE runs as the default Java platform
    for compilation, execution, and debugging. You can view your IDE's JDK version by choosing Help > About and clicking the
    Detail tab. The JDK version is listed in the Java field.
    You can run the IDE with a different JDK version by starting the IDE with the --jdkhome jdk-home-dir switch on the command line
    or in your IDE-HOME/etc/netbeans.conf file. For more information, see IDE Startup Parameters.
    In the IDE, you can register multiple Java platforms and attach Javadoc and source code to each platform. For example, if you
    want to work with the new features introduced in JDK 5.0, you would either run the IDE on JDK 5.0 or register JDK 5.0 as a
    platform and attach the source code and Javadoc to the platform.
    In  , you can switch the target JDK in the Project Properties dialog box. In  , you have to set the target JDK in the Ant script itself,
    then specify the source/binary format in the Project Properties dialog box.
    To register a new Java platform:
    Choose Tools > Java Platforms from the main window.
    Click New Platform and select the directory that contains the Java platform. Java platform directories are marked with a  
    in the file chooser.
    Use the Sources and Javadoc tabs to attach Javadoc documentation and source code for debugging to the platform.
    Click Close.
    To set the default Java platform for a standard project:
    Right-click the project's root node in the Projects window and choose Properties.
    In the Project Properties dialog box, select the Libraries node in the left pane.
    Choose the desired Java platform in the Java Platform combo box.
    Switching the target JDK for a standard project does the following:
    Offers the new target JDK's classes for code completion.
    If available, displays the target JDK's source code and Javadoc documentation.
    Uses the target JDK's executables (javac and java) to compile and execute your application.
    Compiles your source code against the target JDK's libraries.
    If you want to register additional Java platforms with the IDE, you can do so by clicking the Manage Platforms button.
    Then click the Add Platform button and navigate to the desired platform.
    To set the target Java platform for a free-form project:
    In your Ant script, set the target JDK as desired in the javac, java, and javadoc tasks.
    Right-click the project's root node in the Projects window and choose Properties.
    In the Sources panel, set the level of JDK you want your application to be run on in the Source/Binary Format combo box.
    When you access Javadoc or source code for JDK classes, the IDE searches the Java platforms registered in the
    Java Platform Manager for a platform with a matching version number. If no matching platform is found, the IDE's default platform is used instead.
    See Also
    Managing the Classpath
    Declaring the Classpath in a Free-Form Project
    Stepping Through Your Program
    Legal Notices

  • How to Compile Servlet Java Files

    hello ...
    i am a beginner at JSPs and java servlets ... i have been searchin' hopelessly for the past couple of days. Could someone please guide me on how to compile source files for servlets ... namely how can i include the packages javax.servlet.* since the compiler gives me an error that there is no class name ... I am using jdk1.3
    Do I need to get the java server development kit ... but i cant seem to find it any where on the sun's site ... and do i need to download the j2ee sdk too ...
    As you can gather that i am completely comfused and lost ... After doing programmin with asps and previous java experience, i had thought that the migration to a java platform on would be a breeze but the lack of any solid documentation which addresses the above questions is dampenin my spirits ... and the cryptic documentation with tomcat doesnt help either. :)
    pleaze reply soon ... i have to implement a project for my company ... otherwise i would have to put servlets and jsp back in the closet and return back to asp.

    Try http://java.sun.com/j2ee/docs.html specifically, the links on that page called Download Instructions, Installation Instructions, Java Servlets Tutorial and JavaServer Pages QuickStart Guide
    By the way, J2EE SDK's reference implementation is based on Tomcat itself but is more than a web container.

  • Compiling a java source in pl/sql developer - problems

    Hi,
    i'm using pl/sql developer and i created a javasource like this:
    import net.sf.jasperreports.engine.JRException;
    import net.sf.jasperreports.engine.JasperFillManager;
    create or replace and compile java source named Test as
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.view.JasperViewer;
    import persistencia.JdbcDaoFactory;
    * @author igor.simoes
    public class ProcessoRelController {
    the problem is: when i compile the source, an error is displayed(canno't find symbol) in the first line (import net.sf.jasperreports.engine.JRException;)
    i wanna know how can i make the oracle JVM see the package(.jar) that contains net.sf.jasperreports.engine.JRException class, and the others classes in the import statement..
    thank's
    Igor Simões

    Hi,
    Refer the 'Implementing the report service' section in the following article: http://java.dzone.com/articles/java-reporting-part-2
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.HashMap;
    import net.sf.jasperreports.engine.JRException;
    import net.sf.jasperreports.engine.JRExporterParameter;
    import net.sf.jasperreports.engine.JasperCompileManager;
    import net.sf.jasperreports.engine.JasperExportManager;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.JasperReport;
    import net.sf.jasperreports.engine.export.JRXlsExporter;
    public static Connection establishConnection()
    Connection connection = null;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String oracleURL = "jdbc:oracle:thin:@localhost:1521:mySID";
    connection = DriverManager.getConnection(oracleURL,"username","password");
    connection.setAutoCommit(false);
    catch(SQLException exception)
    exception.printStackTrace();
    return connection;
    -Priyanka

  • How to compile a java servlet in netbeans

    heyall, just placed the following java code in my src folder in my web app folder in netbeans, anyone tell me how to compile this now? it asks me for a main but not sure exactly what to put
    package org.mypackage.chapter1;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ServletOne extends HttpServlet {
      /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
       * @param request servlet request
       * @param response servlet response
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        /* TODO output your page here */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ServletOne</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ServletOne at " + request.getContextPath () + "</h1>");
            out.println("Date is: "+ new java.util.Date());
            out.println("</body>");
            out.println("</html>");
        out.close();
      // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
      /** Handles the HTTP <code>GET</code> method.
       * @param request servlet request
       * @param response servlet response
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
        processRequest(request, response);
      /** Handles the HTTP <code>POST</code> method.
       * @param request servlet request
       * @param response servlet response
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
        processRequest(request, response);
      /** Returns a short description of the servlet.
      public String getServletInfo() {
        return "Short description";
      // </editor-fold>
    }

    heyall, just placed the following java code in my src folder in my web app folder in netbeans, anyone tell me how to compile this now?F9
    it asks me for a main but not sure exactly what to putCompiling source files never 'asks .. for a main'. You must be trying to execute it. You can't do that outside the servlet container it is intended for
    COMPILER ERROR - package javax.servlet.http does not exist
    BUT can't even get this far yetSo try compiling it as per your tutorial. Do you understand the difference between 'compile' and 'run'?

  • How To Compile Valhalla Chat Source Code

    Hey guys, I really need to know how to compile the source code of Valhalla Chat (www.valhallachat.com). If anyone knows how to do this, please post it here or email me at [email protected] I need to make a customized version of Valhalla so thats why i need to know how to compile. Thanks so much!

    It's also bad form to cross post.
    {color:0000ff}http://forum.java.sun.com/thread.jspa?threadID=5277791
    {color}
    Cross posting is rude.
    db

  • How to compile Oracle Linux source?

    I accidentally downloaded source DVD "Oracle Linux Release 5 Update 2 source - DVD" instead of installable ISO image. Is there anyway I can compile it to make bootable ISO image?
    I tried to search this forum as well as other places but couldn't find any information hence thought of opening a thread before I proceed to download correct file which will again take 10+ hrs with my Internet speed :(
    Any help is highly appreciated. Also I need to know which packages are required to be installed for compiling the source if at all that is possible. I am using Ubuntu 11.10 Desktop.
    Thanks in advance for any help and hope to get a reply soon :) I need to urgently install Oracle 11gR2 on it.
    Edited by: user6582219 on Apr 12, 2012 1:10 AM
    While browsing the forum for any possible solution I came to a thread that discuss installation of a package oracle-rdbms-server-11gR2-preinstall. When searched through search engine I came to know about recent certification Oracle 11gR2 on Oracle Linux 6, here is the link https://blogs.oracle.com/linux/entry/announcing_oracle_database_11g_r2
    https://blogs.oracle.com/linux/entry/announcing_oracle_database_11g_r2
    Thing is I already have Oracle Linux 6 Update 2 (the latest) installed on my machine in dual boot mode so I dropped the idea of installing version 5.2. As per the documentation 11gR2 was not certified earlier on Linux 6.2 so I thought of installing 5.2 but it is not necessary now.
    I would still appreciate if someone could answer my question just for knowing the procedure compiling source. May be it can help someone else trying to achieve this.
    I have another couple of important questions and need guidance from the experts over here. I am not sure if it is appropriate to open a new thread but for now I am posting them here.
    Before proceeding here are my environment details:
    Machine: x86 32 bit with 2 GB RAM/250 GB HD.
    OS: Kubuntu 11.10 Desktop and Oracle Linux 6 Update 2 in dual boot mode.
    Here are my partition details for your reference but as I am planning to do the installation from the scratch following new ideal scheme you can jump to last paragraph following the line "*********************************" for my questions.
    Unfortunately my partition plan went wrong and here is what I have now:
    Disk /dev/sda: 250.1 GB, 250059350016 bytes
    255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x3d5ba9e1
    Device Boot Start End Blocks Id System
    /dev/sda1 * 2048 1002047 500000 83 Linux
    /dev/sda2 151525080 361253654 104864287+ 7 HPFS/NTFS/exFAT
    /dev/sda4 1003518 151001087 74998785 5 Extended
    /dev/sda5 1003520 7002111 2999296 82 Linux swap / Solaris
    /dev/sda6 7004160 11001855 1998848 83 Linux
    /dev/sda7 11003904 51001343 19998720 83 Linux
    /dev/sda8 51003392 110041087 29518848 83 Linux
    Partition table entries are not in disk order
    /dev/sda1 here is /tmp, /dev/sda2 is my data partition, I have separate /home / (root) partition for Kubuntu and remianing around 20 GB in extended partition is used for Oracle Linux 6.2 with default Oracle suggested LVM partition. I also have separate /boot for Kubuntu and I chose not to install grub while installing Oracle Linux. I later modified grub.cfg to add entries for Oracle Linux and now I can boot both OSs successfully.
    My issue now is I cannot extend 20 GB space (in extended partition) that I have given to Oracle though I have around 40 GB space available. This is because I alreay have 4 primary partitions (one for /boot others for "data" and one extended partition). So I have to make primary partition out of free space and install Oracle in a single partition without following recommended partition layout scheme.
    Now I want to do the installation of both the OS from the scratch and really need an advice on partition layout scheme. Here is summary of what I wan to achieve:
    1. Keep the "data" partition (primary) intact and carve an ideal partition layout for both the OS with separate /boot, /tmp, /home, swap (and may be for /usr???). Also may be I can share swap?
    2. How do I go about using LVM and is it recommended for this case? What would be ideal locations for each partitions and sizes? I already used 100 GB for "data" so now I want to keep 60 GB for Oracle Linux (and Oracle DB for which I will again make few sub-partitions) and remaining will be for Kubuntu.
    Well, I am not sure if this is the right place to ask these questions but since I can see very knowlegeable top contributors here that are willing to help novice users I thought of posting these questions.
    I would really really appreciate if someone can provide me rough draft of partition scheme in my case considering the sub-partitions needed for Oracle DB. I went thorugh number of forums and documentations to come up with solutuion and finally thought of getting help after much confusion.
    I really need to carefully plan this time because it's third time I am doing reinstallation from the scratch because of poor plan I followed previously.
    Thank you very much in advance and please let me know in case more information is needed from my side.
    Regards,
    Ramesh

    I accidentally downloaded source DVD "Oracle Linux Release 5 Update 2 source - DVD" instead of installable ISO image. Is there anyway I can compile it to make bootable ISO image?Google will be your best friend for such a question, for instance, "Creating a Custom centos Linux bootable ISO Image". There is no need to duplicate the effort. I recommend you download the correct installation DVD, e.g. 5.8
    Thing is I already have Oracle Linux 6 Update 2 (the latest) installed on my machine in dual boot mode so I dropped the idea of installing version 5.2. As per the documentation 11gR2 was not certified earlier on Linux 6.2 so I thought of installing 5.2 but it is not necessary now.So you don't need to install 5.2 anymore, but you want the information how to compile a installation DVD from the 5.2 source anyway?!
    I have another couple of important questions and need guidance from the experts over here. I am not sure if it is appropriate to open a new thread but for now I am posting them here.Questions may be important for you, but not necessarily for others. No one will complain if you create a new thread for particular questions or subjects. It is better to separate your topics and questions rather than creating a multi-mega thread, which does little to help anyone else but you. It means more work on your end, but it will be easier for anyone to participate or answer your questions, and it will allow you to better award answers.
    Regarding your partitioning questions: It is generally difficult to address such topics in a forum. You are asking for a book of information. My advice is to drop the old fashioned concepts of dual or triple boot options and install Oracle VirtualBox instead. It will make all of these questions obsolete and you can use whatever defaults when installing your virtual machine guest OS. Its a far more superior way of dealing with multiple operating systems on one and the same computer.
    I am using Ubuntu 11.10 Desktop.
    I need to urgently install Oracle 11gR2 on it.For what it's worth, if you can combine the two source below you should be able to install and run 11gR2 on Ubuntu 11.10.
    Install Oracle 11gR2 on Ubuntu Linux 11.04 (64-bit) Howto
    Install Oracle 11gR2 on Ubuntu Linux 11.04 (64-bit) Howto
    Oracle 11gR2 Express Edition on Linux Ubuntu 11.10 howto
    Oracle 11gR2 Express Edition on Linux Ubuntu 11.10 howto
    However, check out VirtualBox.

  • HOW TO INSTALL JDK1.4 ON LINUX PALTFORM AND HOW TO COMPILE A JAVA  FILE

    SIR PLZ KINDLY TELL ME THE PROCDURE OF INSTALL JSDK1.4 ON LINUX .
    1.I HAVE DOWNLOADED IT ONA I HAVE INSTALL IN
    /usr/local
    but
    2: do nt know how set the CALSSPATH and JAVA_HOME(ENV VARIABLES)
    3:HOW TO COMPILE AND RUN THE JAVA FILE(JSP)

    2.
    export JAVA_HOME=/usr/local/jdk1.4.0
    export CLASSPATH=.
    (amending for your set up.)
    Placing these in your /etc/profile file will make them run automatically on log in of a user.
    3.
    You need tomcat, probably, http://jakarta.apache.org.
    Bhav

Maybe you are looking for

  • Can't boot Windows Vista Installation

    Hi, I installed Leopard and then used Parallels and Windows XP. Then I uninstalled Parallels an XP and used boot camp assistant to create a 32Gb partition for my Windows Vista Ultimate. When I boot from DVD I get the "Loading files..." screen but in

  • Invoice and Invoice amount in FI/CO When enter check number

    Hi  All,    I have a requirement like this. We have custom t-code ZF04 ( FAST CASH ) to post payments to customer accounts. In this t-code, we have one field for Check#.  When they enter Check# number and click on 'SEARCH' icon i need to display list

  • Motion 5 without FCPX

    Is anyone using Motion 5 with Final Cut Pro, but without Final Cut X installed at all? Given the warnings and complicated workarounds that Apple is issuing -- Installation Best Practice guide from Apple -- it sounds as though each launch of Motion 5

  • Not In Process

    Hi, am in 4.6B version, created a copy of std.WFfor Invoice verification for blockedprice event (BUS2081). Event is triggering on blocking an invoice, but when I trace SWEL, I found the process stopped at a task (where workitem is created) with follo

  • Query length input-output

    Hi everybody, I have two doubts: 1)     Has oracle a limit to the length of the query? (number of characters) 2)     Has oracle a limit in the length of the output of a query? (number of characters) I ask these things because I have a long query (abo