.java files don't compile on redhat

im using redhat 9.
i installed the binary of JDK
in the bin folder when i type javac and then press enter, it says command not available or something like that
actually i did it after when i could not compile .java files like:
javac Hi.java
moreover it also displays the same message for java
but i have checked it that both of the files: javac and java are present in the bin directory
is there any other method of compiling java files on linux
kindly help me in this regard

It could be that the current working directory your in is not in your path.
You should be able to check that by typing echo $PATHat the command prompt.
I'm using SUSE and the output of the command reads like this: /home/wyd/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:
/usr/lib/java/bin:/usr/lib/ant/bin:/usr/lib/ant/bin:/usr/lib/ant/binAs you see somewhere in there there is the line /usr/lib/java/bin: this needs to show up in your path as well. Otherwise you have to add this directory to your path. Can't tell you how to do this on Redhat sorry.
Furthermore you see that the entry . (thats the dot for the current working directory) is not in my path. So in order to execute a command that is not in the path, you have to type ./javacfor instance. (a dot followed by a backslash, then the command to run) Thereby the shell knows you want to run a program located in the current working directory.
So do the following tests:
cd to the bin-directory of the JDK
type ,/javac and you should the usage info for the compiler
add the bin-directory of the JDK to your path and you should be able to run the compiler from any directory

Similar Messages

  • Automatic created Java file error when compile JSP file

    I got the following error message when i try to load the JSP file given below (FlightSearch.jsp). Given also below the JAVA files (flightsearch$jsp.java) created by the compiler.
    Thanks for your help
    Susan
    Error message
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    C:\jakarta-tomcat\work\client\localhost\client\client\flightsearch$jsp.java:320: 'catch' without 'try'.
    } catch (Throwable t) {
    ^
    C:\jakarta-tomcat\work\client\localhost\client\client\flightsearch$jsp.java:328: 'try' without 'catch' or 'finally'.
    ^
    C:\jakarta-tomcat\work\client\localhost\client\client\flightsearch$jsp.java:328: '}' expected.
    ^
    3 errors, 1 warning
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:285)
    at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:548)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:176)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:188)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
    at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
    at java.lang.Thread.run(Thread.java:536)
    FlightSearch.jsp
    <%@page import="java.util.*" errorPage="ErrorHandler.jsp"%>
    <%@page import="com.client.entity.Flight"%>
    <%@page import="com.client.wsclient.FlightServiceClient"%>
    <H3>Available Flight List</H3>
    <br>We have found the following Available flight(s) : </br>
    <table border="0" cellpadding="0" cellspacing="0" width="100">
    <tr>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Flight Company</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Flight Number</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Depart From<font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Arrive</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Departure Date</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Departure Time</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Arrival Date</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Arrival Time</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Adult Fare</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Child Fare</font></b></td>
    </tr>
    <%
    //Get the search information
    String des = request.getParameter("DFrom");
    String arr = request.getParameter("DTo");
    String fy = request.getParameter(FYear.value);
    String fm = request.getParameter(FMonth.value);
    String fd = request.getParameter(FDay.value);
    String f1 = fy + "-" + fm;
    String FDat = f1 + "-" + fd;
    String ty = request.getParameter(TYear.value);
    String tm = request.getParameter(TMonth.value);
    String td = request.getParameter(TDay.value);
    String t1 = ty + "-" + tm;
    String TDat = t1 + "-" + td;
    String type;
    if( request.getParameter(type[0].checked))
    type = "Return";
    else
    { type = "OneWay";
    String clas;
    if(request.getParameter(clas[0].checked))
    {clas = "ECO";
    else
    {clas = "BUSS";}
    String adult = request.getParameter(Adult.value);
    String child = request.getParameter(Child.value);
    //Get the server Flight Search Service URL
    // ServerFlightSearchBO SFSBO = new ServerFlightSearchBO();
    // ServerFlightSearch FlightSearch = SFSBO.getFlightSearchURL();
    // FlightSearchServiceClient FSearchServiceClient = new FlightSearchServiceClient
    String ServerFlightServiceURL = "http://localhost:7080/AServer/services/FlightService";
    //Find available Flight
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(des, arr, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    %>
    <tr>
    <td width= "10%"><%=flt.getFlightComp()%></td>
    <td width= "10%"><%=flt.getFlightNum()%></td>
    <td width= "10%"><%=flt.getDestination()%></td>
    <td width= "10%"><%=flt.getArrive()%></td>
    <td width= "10%"><%=flt.getFrDate()%></td>
    <td width= "10%"><%=flt.getFlightDptTm()%></td>
    <td width= "10%"><%=flt.getToDate()%></td>
    <td width= "10%"><%=flt.getFlightArrTm()%></td>
    <%
    int adt, chld;
    int far_A, tot_A, far_C, tot_C;
    adt = Integer.parseInt(adult);
    far_A = flt.getAdultFr();
    tot_A = adt * far_A;
    chld = Integer.parseInt(child);
    far_C = flt.getChildFr();
    tot_C = chld * far_C;
    %>
    <td width= "10%"><%=tot_A%></td>
    <td width= "10%"><%=tot_C%></td>
    </tr>
    <%
    if(type = "Return")
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(arr, des, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    %>
    <tr>
    <td width= "10%"><%=flt.getFlightComp()%></td>
    <td width= "10%"><%=flt.getFlightNum()%></td>
    <td width= "10%"><%=flt.getFlightDpt()%></td>
    <td width= "10%"><%=flt.getFlightArr()%></td>
    <td width= "10%"><%=flt.getFlightDptDt()%></td>
    <td width= "10%"><%=flt.getFlightDptTm()%></td>
    <td width= "10%"><%=flt.getFlightArrDt()%></td>
    <td width= "10%"><%=flt.getFlightArrTm()%></td>
    <%
    int adlt, chd;
    int fare_A, totA, fare_C, totC;
    adlt = Integer.parseInt(adult);
    fare_A = flt.getAdultFr();
    totA = adlt * fare_A;
    chd = Integer.parseInt(child);
    fare_C = flt.getChildFr();
    totC = chd * fare_C;
    %>
    <td width= "10%"><%=totA%></td>
    <td width= "10%"><%=totC%></td>
    </tr>
    <%
    %>
    </table>
    flightsearch$jsp.java
    package org.apache.jsp;
    import java.util.*;
    import com.client.entity.Flight;
    import com.client.wsclient.FlightServiceClient;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    import org.apache.jasper.runtime.*;
    public class flightsearch$jsp extends HttpJspBase {
    static {
    public flightsearch$jsp( ) {
    private static boolean jspxinited = false;
    public final void jspxinit() throws org.apache.jasper.runtime.JspException {
    public void _jspService(HttpServletRequest request, HttpServletResponse response)
    throws java.io.IOException, ServletException {
    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    String _value = null;
    try {
    if (_jspx_inited == false) {
    synchronized (this) {
    if (_jspx_inited == false) {
    jspxinit();
    jspxinited = true;
    _jspxFactory = JspFactory.getDefaultFactory();
    response.setContentType("text/html;ISO-8859-1");
    pageContext = _jspxFactory.getPageContext(this, request, response,
    "ErrorHandler.jsp", true, 8192, true);
    application = pageContext.getServletContext();
    config = pageContext.getServletConfig();
    session = pageContext.getSession();
    out = pageContext.getOut();
    // HTML // begin [file="/client/flightsearch.jsp";from=(0,59);to=(1,0)]
    out.write("\r\n");
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(1,43);to=(2,0)]
    out.write("\r\n");
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(2,58);to=(19,0)]
    out.write("\r\n\r\n<H3>Available Flight List</H3>\r\n<br>We have found the following Available flight(s) : </br>\r\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100\">\r\n <tr>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Flight Company</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Flight Number</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Depart From<font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Arrive</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Departure Date</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Departure Time</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Arrival Date</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Arrival Time</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Adult Fare</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Child Fare</font></b></td>\r\n </tr>\r\n");
    // end
    // begin [file="/client/flightsearch.jsp";from=(19,2);to=(66,0)]
    //Get the search information
    String des = request.getParameter("DFrom");
    String arr = request.getParameter("DTo");
    String fy = request.getParameter(FYear.value);
    String fm = request.getParameter(FMonth.value);
    String fd = request.getParameter(FDay.value);
    String f1 = fy + "-" + fm;
    String FDat = f1 + "-" + fd;
    String ty = request.getParameter(TYear.value);
    String tm = request.getParameter(TMonth.value);
    String td = request.getParameter(TDay.value);
    String t1 = ty + "-" + tm;
    String TDat = t1 + "-" + td;
    String type;
    if( request.getParameter(type[0].checked))
    type = "Return";
    else
    { type = "OneWay";
    String clas;
    if(request.getParameter(clas[0].checked))
    {clas = "ECO";
    else
    {clas = "BUSS";}
    String adult = request.getParameter(Adult.value);
    String child = request.getParameter(Child.value);
    //Get the server Flight Search Service URL
    // ServerFlightSearchBO SFSBO = new ServerFlightSearchBO();
    // ServerFlightSearch FlightSearch = SFSBO.getFlightSearchURL();
    // FlightSearchServiceClient FSearchServiceClient = new FlightSearchServiceClient
    String ServerFlightServiceURL = "http://localhost:7080/AServer/services/FlightService";
    //Find available Flight
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(des, arr, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(66,2);to=(68,18)]
    out.write("\r\n<tr>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(68,21);to=(68,40)]
    out.print(flt.getFlightComp());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(68,42);to=(69,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(69,21);to=(69,39)]
    out.print(flt.getFlightNum());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(69,41);to=(70,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(70,21);to=(70,41)]
    out.print(flt.getDestination());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(70,43);to=(71,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(71,21);to=(71,36)]
    out.print(flt.getArrive());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(71,38);to=(72,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(72,21);to=(72,36)]
    out.print(flt.getFrDate());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(72,38);to=(73,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(73,21);to=(73,41)]
    out.print(flt.getFlightDptTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(73,43);to=(74,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(74,21);to=(74,36)]
    out.print(flt.getToDate());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(74,38);to=(75,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(75,21);to=(75,41)]
    out.print(flt.getFlightArrTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(75,43);to=(76,1)]
    out.write("</td>\r\n ");
    // end
    // begin [file="/client/flightsearch.jsp";from=(76,3);to=(87,1)]
    int adt, chld;
    int far_A, tot_A, far_C, tot_C;
    adt = Integer.parseInt(adult);
    far_A = flt.getAdultFr();
    tot_A = adt * far_A;
    chld = Integer.parseInt(child);
    far_C = flt.getChildFr();
    tot_C = chld * far_C;
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(87,3);to=(88,18)]
    out.write("\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(88,21);to=(88,26)]
    out.print(tot_A);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(88,28);to=(89,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(89,21);to=(89,26)]
    out.print(tot_C);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(89,28);to=(91,0)]
    out.write("</td>\r\n</tr>\r\n");
    // end
    // begin [file="/client/flightsearch.jsp";from=(91,2);to=(100,0)]
    if(type = "Return")
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(arr, des, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(100,2);to=(102,18)]
    out.write("\r\n<tr>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(102,21);to=(102,40)]
    out.print(flt.getFlightComp());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(102,42);to=(103,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(103,21);to=(103,39)]
    out.print(flt.getFlightNum());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(103,41);to=(104,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(104,21);to=(104,39)]
    out.print(flt.getFlightDpt());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(104,41);to=(105,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(105,21);to=(105,39)]
    out.print(flt.getFlightArr());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(105,41);to=(106,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(106,21);to=(106,41)]
    out.print(flt.getFlightDptDt());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(106,43);to=(107,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(107,21);to=(107,41)]
    out.print(flt.getFlightDptTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(107,43);to=(108,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(108,21);to=(108,41)]
    out.print(flt.getFlightArrDt());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(108,43);to=(109,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(109,21);to=(109,41)]
    out.print(flt.getFlightArrTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(109,43);to=(110,1)]
    out.write("</td>\r\n ");
    // end
    // begin [file="/client/flightsearch.jsp";from=(110,3);to=(120,1)]
    int adlt, chd;
    int fare_A, totA, fare_C, totC;
    adlt = Integer.parseInt(adult);
    fare_A = flt.getAdultFr();
    totA = adlt * fare_A;
    chd = Integer.parseInt(child);
    fare_C = flt.getChildFr();
    totC = chd * fare_C;
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(120,3);to=(121,18)]
    out.write("\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(121,21);to=(121,25)]
    out.print(totA);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(121,27);to=(122,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(122,21);to=(122,25)]
    out.print(totC);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(122,27);to=(124,0)]
    out.write("</td>\r\n</tr>\r\n");
    // end
    // begin [file="/client/flightsearch.jsp";from=(124,2);to=(126,0)]
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(126,2);to=(127,8)]
    out.write("\r\n</table>");
    // end
    } catch (Throwable t) {
    if (out != null && out.getBufferSize() != 0)
    out.clearBuffer();
    if (pageContext != null) pageContext.handlePageException(t);
    } finally {
    if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);

    i am very glad and appreciate for your help, but i would like to know how to get the value of a radio button.
    like in another JSP file i have :
    <input type="radio" name="type" value="Return" checked>
    Return
    <input type="radio" name="type" value="OneWay">
    One Way
    and when i try to get the value which is checked, i put
    String type = request.getParameter(type.checked);
    but this doesn't work,
    i would be very appreciate for your help. Thank you

  • Is it possible to write a Java file that creates/compiles other Java files?

    My goal is to write a program that writes files containing Java code depending on the user's input. That's the easy part. The tough part, I think, is to get the Java file to use the Java compiler to compile, and run, those newly created files.
    I know this sounds crazy, but I really want to get this to work.
    Can someone please tell me how to do this?

    You could use the eclipse compiler
    http://help.eclipse.org/help31/index.jsp?topic=/org.ec
    lipse.jdt.doc.isv/guide/jdt_api_compile.htm
    Or the one from the JDK (com.sun.javac.Main located
    in the JDKs /lib/tools.jar). But that won't work with
    an JRE unless you ship the tools.jar too. And it
    isn't what i would call an official API. So i would
    rather use the eclipse compiler. I did this once and
    it worked fine.it isn't what sun call an official API, either, which is somewhat more important! the license even used to restrict re-distribution of tools.jar (I think that's changed now)

  • Compiling new classes on the fly without having a .java file

    Hi everybody,
    I'd like to compile dynamically produced JAVA code (code from user input in my application). I don't wanna store the source code in a .java file, but just compile the code (as char[] or something like that) to a byte[].
    Does anybody have an idea ??
    Thanks
    Jan

    Have you looked at the idea of interpreting rather than compiling, say using Jython (a python interpreter written in Java). Python and Java are extremely close in syntax, and it should be relatively easy to do what you are talking about.
    I am worried though, that you are going to let users type in text, and assume that it has valid syntax in the language you are using. Many years of UI experience indicate that letting users type in anything results in a certain error rate. Letting it be instructions you are to follow in your code is even more dangerous.
    There are many programs that let users define actions interactively. They seem to either let the user type in text, and error check it to death (a lot of work, think spreadsheet type programs), or they present the user with a set of choices, often using a wizard type interface, which takes more up front UI work, but only lets the users select valid options.
    It sounds like you want to interpret what the user types in as instructions. Even with Jython (or a similar interpreter), you would need to parse the user input for formatting errors, invalid variable names, and anything else they could make a mistake on, before you could pass any of it to the interpreter.
    Good luck.

  • .java files located in different directories - trouble compiling

    My attempts at getting my main .class file (../master/BicycleMaster.class) to automatically recognize that it's supporting .class file (../master/child/BicycleChild.class) located one directory below keep failing and the .java files won't compile.
    If I move both .java files to the same location (in the ../master directory) then they compile and run just fine, but it's when I want to separate them into the two different directories that I have a problem compiling them. They won't compile because the references in BicycleMaster.jave to BicycleChild.java can't be resolved.
    I was hoping - if you have time - that you might be able to show me by example in the code below? In the file ../master/BicycleMaster.java I added 'package master;' as the first line of the code. It was my impression that this would tell the compiler to look in the sub-directories for any additional .java files. This didn't work either.
    HERE ARE THE DETAILS:
    Directory of K:\COMMON\ITS\STEVEB\java\master
    03/04/2008 04:25 PM <DIR> .
    03/04/2008 04:25 PM <DIR> ..
    03/04/2008 04:24 PM 612 BicycleMaster.java
    03/04/2008 03:54 PM <DIR> child
    1 File(s) 612 bytes
    K:\COMMON\ITS\STEVEB\java\master>type BicycleMaster.java
    package master;
    class BicycleMaster {
        public static void main(String[] args) {
            //Create 2 different bicycle objects
            BicycleChild bike1 = new BicycleChild();
            BicycleChild bike2 = new BicycleChild();
            //Invoke methods on the objects
            bike1.changeCadence(50);
            bike1.speedUp(10);
            bike1.changeGear(2);
            bike1.printStates();
            bike2.changeCadence(50);
            bike2.speedUp(10);
            bike2.changeGear(2);
            bike2.changeCadence(40);
            bike2.speedUp(10);
            bike2.changeGear(3);
            bike2.printStates();
    }Directory of K:\COMMON\ITS\STEVEB\java\master\child
    03/04/2008 03:54 PM <DIR> .
    03/04/2008 03:54 PM <DIR> ..
    03/04/2008 03:54 PM 524 BicycleChild.java
    1 File(s) 524 bytes
    K:\COMMON\ITS\STEVEB\java\master\child>type BicycleChild.java
    class BicycleChild {
        int cadence = 0;
        int speed = 0;
        int gear = 1;
        void changeCadence(int NewValue) {
            cadence = NewValue;
        void changeGear(int NewValue) {
            gear = NewValue;
        void speedUp(int increment) {
            speed = speed + increment;
        void applyBrakes(int decrement) {
            speed = speed - decrement;
        void printStates() {
            System.out.println("Your cadence: "+cadence+", Your speed: "+speed+", Your gear: "+gear);
    }HERE ARE THE ERRORS:
    First I compile the ../master/child/BicycleChild.java file and it compiles fine. This I attempt to compile ../master/BicycleMaster.java and I get the following errors:
    K:\COMMON\ITS\STEVEB\java\master>javac BicycleMaster.java
    BicycleMaster.java:5: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike1 = new BicycleChild();
    ^
    BicycleMaster.java:5: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike1 = new BicycleChild();
    ^
    BicycleMaster.java:6: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike2 = new BicycleChild();
    ^
    BicycleMaster.java:6: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike2 = new BicycleChild();
    ^
    4 errors

    Thanks so much for responding. Progress was definetly made as the compiler now works longer before erroring out. Sadly it's still erroring out for a reason I'm not understanding. Please let me know if you can see where I'm going wrong.
    Here's how it played out for me:
    K:\COMMON\ITS\STEVEB\java>echo %classpath%
    .;k:\common\its\steveb\java\;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip
    K:\COMMON\ITS\STEVEB\java\master\child>javac BicycleChild.java
    K:\COMMON\ITS\STEVEB\java\master\child>cd ..
    K:\COMMON\ITS\STEVEB\java\master>javac BicycleMaster.java
    BicycleMaster.java:5: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike1 = new BicycleChild();
    ^
    BicycleMaster.java:5: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike1 = new BicycleChild();
    ^
    BicycleMaster.java:6: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike2 = new BicycleChild();
    ^
    BicycleMaster.java:6: cannot find symbol
    symbol : class BicycleChild
    location: class master.BicycleMaster
    BicycleChild bike2 = new BicycleChild();
    ^
    4 errors
    Here are the two programs revised as you suggested:
    K:\COMMON\ITS\STEVEB\java\master\child>type BicycleChild.java
    package master.child;
    class BicycleChild {
        int cadence = 0;
        int speed = 0;
        int gear = 1;
        void changeCadence(int NewValue) {
            cadence = NewValue;
        void changeGear(int NewValue) {
            gear = NewValue;
        void speedUp(int increment) {
            speed = speed + increment;
        void applyBrakes(int decrement) {
            speed = speed - decrement;
        void printStates() {
            System.out.println("Your cadence: "+cadence+", Your speed: "+speed+", Your gear: "+gear);
    }K:\COMMON\ITS\STEVEB\java\master>type BicycleMaster.java
    package master;
    class BicycleMaster {
        public static void main(String[] args) {
            //Create 2 different bicycle objects
            BicycleChild bike1 = new BicycleChild();
            BicycleChild bike2 = new BicycleChild();
            //Invoke methods on the objects
            bike1.changeCadence(50);
            bike1.speedUp(10);
            bike1.changeGear(2);
            bike1.printStates();
            bike2.changeCadence(50);
            bike2.speedUp(10);
            bike2.changeGear(2);
            bike2.changeCadence(40);
            bike2.speedUp(10);
            bike2.changeGear(3);
            bike2.printStates();
    }

  • 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..

  • Error when compiling the Java file

    Hi I have created a jsp program that uses the java files. i have jboss installed. when i compile the java file it gives compilation error saying that javax.servlet.jsp.tagext.TagSupport not found.
    Although when i installed the Tomcat seperately i did not get any compilation error. can anyone tell me how to get out of this problem when Tomcat is not installed seperately.
    Thanks,
    Rakesh

    Hi
    I think these errors are due to incorrect classpath settings.While compiling HelloHome ..Helloremote must be in classpath.Also if u have packaged them u must be in the package root during compilation ie if uor remote & home interface is in a package called "ejbserver"
    then while compiling u must be in the folder above ejbserver & compile command is
    javac .\ejbserver\*.java
    If uor home & remote interface is in different folder check wheather u have imported the remote interface inside home interface file.

  • Import statement in .java files and .jsp files ..correction

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement in two.java I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import one.class in My.jsp .That is i have to say
    <%@page import="one"%>
    in My.jsp.
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder and MyJsp is compiled sucessfully.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.

    It has to do with packages. Most java classes are in a package, the name of which must conform to its place on the filesystem relative to the classpath. By that I mean that if you have com.mystuff.One.java, it must be in a folder com/mystuff where com is located somewhere in the classpath.
    What you've done is a little different. I'm assuming a couple of things:
    1. you have no package declaration at the top of one.java or two.java
    2. you have the current directory "." in your classpath.
    Java has the concept of the "default package", which covers classes without a declared package, and in your case is the current directory.
    So when you're in c:\sourcefolder and run the compiler, then "."="c:\sourcefolder", and that directory is part of the default package. No import statements are necessary for classes that are in the same package. This is why two.java can call methods in one.java without an import statement.
    When you run your jsp, the "current directory" part of your classpath is not c:\sourcefolder, but some other value (probably the directory you start your jsp engine from) You will have to import all non-java-library classes because the jsp itself becomes a java class, with a package that is determined by the jsp engine.

  • Finding java version used from compiled code

    Is there a way to find the java version used to compile the java file from the compiled files,i.e., class files?

    that information is encapsulated within the .class file, I don't think so.
    The class file has a minor_version/major_version field.
    However using jikes and sun jdk 1.3.1 both produce a version number of 45.3. According to a footnote in the JVM spec that corresponds to a class file format for java of 1.0.2. And both obviously are newer than that version of java.
    Based on that I don't think one can expect those numbers to changed based on the java version but rather on any changes in the class file itself.

  • Import statement in .java files and .jsp files

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import the class I want to use.That is i have to say
    <%@page import="one"%>
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.
    In this case the pSo I am wondering in JSP why it doesn't take the class I am looking for from the classpath .
    Help.

    You have to understand Java scoping rules. In the 1st scenario with the two Java files I am guessing neither one of them begins with a package statement. This means that they belong to the default package. When you compile the compiler uses the classpath to resolve method calls looking in the default package since there was no import statement specified in two.java. JSP is a little different. Now I just read this here in these forums a couple of days ago. Since the classfiles generated from the JSP files are not in the CLASSPATH they are loaded by a different classloader. This is why you have to import all references to all classes in the default package.

  • How to convert .class files to .java files

    Hi,
    I want to convert .class files to .java files. Is there is any software for that doing except Dj DCompiler? Because if i am using this i am not getting proper code i mean as it is available in the file.
    I tried by writing simple java file and i compiled Sample.java file and i got a .class file then i converted this Sample.class to Sample.java file by using DjDcompiler but i was missing some statements i need entire code that is available in Sample.java file. Please tell me any other software for that doing.
    Thank you in advance

    I want to convert .class files to .java files.
    iles. Is there is any software for that doing except
    Dj DCompiler? Because if i am using this i am nothttp://www.google.com/search?hl=en&q=java+decompiler&meta=
    getting proper code i mean as it is available in the
    file.I doubt you ever will.
    I tried by writing simple java file and i compiled
    Sample.java file and i got a .class file then i
    converted this Sample.class to Sample.java file by
    using DjDcompiler but i was missing some statements i
    need entire code that is available in Sample.java
    file. Please tell me any other software for that
    doing.Did you hear about "compiler opimizations"?

  • Suddenly, my java programs won't compile : Class not found error

    Hello, the strangest things happened on my win xp pro computer...
    My java-files wo'nt compile anymore. The compiler (javac) is complaning about classes he can't find. But these classes are in the same directory....
    Can anyone help me?

    generally female version are more complaining then the male versions!!
    if the male version is complaining then it must be something wrong in your path or classpath!!
    1) have you tried before to complie? and it has been complied successfully in past?
    2) check out your classpath.. is it containing "." ( a dot)? if not then just put a ".;" in starting of your classpath & start compiling your code in new command prompt...
    hope now your compiler will not complain... :)

  • Import a java file?

    Hi,
    I created a StockTablePanel.java file, and then compiled it fine.
    Then, I wrote in a new file, StockTableTabPanel.java, the followings:
    //top:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    // Import our other components
    import StockTablePanel;
    (other code)
    It failed in compile, and the error is:
    '.' expected
    import StockTablePanel;
    ^
    What is the problem and its solution?
    Thanks a lot.

    the correct syntax is:
    import your.domain.name.projectname..StockTablePanel;and you also have to store your class StockTablePanel in this package:
    package your.domain.name.projectname; //define package name for this class
    public class StockTablePanel {
    }See also the chapter "Packages" in the Java Language Specification: http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#60384

  • Applet.java file which used to compile, now does not

    I cannot re-compile a java file which I used to compile many times.
    It keeps saying:
    error: cannot read PopupNavigatorApplet.java
    1 error
    I extracted the original from the archive - the same result
    What might be wrong?

    Perhaps you don't have the rights to access the file in the filesystem? Are you working on *nix or Windoze (or any other)? Is your classpath set properly (including the current working directory '.')?
    So many questions and no answers.. ;o)
    cheers,
    kelysar

  • Error while compiling java file using J2SE 1.5.0

    Dear Sir,
    I'm getting the following error while compiling the java file.The code is also given.
    package test;
    public class TestRowSet {
    public TestRowSet() {
    "TestRowSet.java": cannot access java.lang.Object,bad class file: D:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar\java\lang\Object.class,class file has wrong version 49.0, should be 48.0,Please remove or make sure it appears in the correct subdirectory of the classpath. at line 4, column 1
    Please help me out.
    --Suketu Naik.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    But I'm compiling within "Borland JBuilder 9.0". I've
    set the JDK path of the current project to point to
    the path of JDK 1.5.0 . I've also tried to compile at
    command prompt with "javac". I'm getting the same
    error of "Undefinedclassloader" with long StatckTrace.
    I don't know anything about JBuilder either. If you use the command prompt and enter the full path to the 1.5 javac.exe then that will prove whether the issue is using an older javac or not. For example "c:\j2sdk1.5.0_01\bin\javac HelloWorld.java"

Maybe you are looking for

  • Responsible Service Org and Service Team (partner function)

    Hi all CRM gurus, I'm trying to understand the reasons behind the following design and I hope someone can clarify some points for me: 1. Organisation structure in CRM is set up with service organisation followed by service team, e.g. ABC Company |_Ca

  • Please email and I forgot the password icloud help me please,

    Please email and I forgot the password icloud help me please,

  • Unzip error

    when i unzip my zip file it shows execute permissions denied. below is the error message. could anyone help me on this. # unzip hpia64_11gR2_database_1of2.zip sh: unzip: Execute permission denied.

  • MIGO change header data before saving

    Hi all, I want to update header data (budat) before saving the material document with MIGO. Has anybody an idea? I tried with Badi: mb_document_badi or similar user-exit MB_CF001 but with none of these I can CHANGE header data. Is it possible? Thanks

  • FCP 7 won't open

    I have been using FCP 7 for two years, no problems. Now it won't open. I re loaded the program, now  I click on the icon , it loads to 100% and beach ball. PLS help in the middle of a huge indie project. Thanks Mammaslom