• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Compile .java file on JSP

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have a JSP page which generates a java file. This java file contains the code for an applet. I have been using java to compile the .java file itself by this code:





But now I would like to compile my .java file through my JSP page itself. I tried to import tools and use javac but it did not work...

Thanks!
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charles,
Welcome to CodeRanch!

I don't follow your question. It sounds like you are asking how you would stick the code you already have in a JSP. (Which would be poor practice, but the answer would be copy/paste.) I think you are asking something else though.

Also, note I added code tags to your post to make it easier to read.
 
Charles Philip
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply,

The server generates an applet code which does not do the same thing each time. This means that my .java file(which contains the applet) is different each time. How to compile this file on the server? I tried this code below but it did not work even though I imported what was needed. I get an error saying that it could not compile.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I get an error saying that it could not compile.



Where did you see the error message and exactly what did it say.

Bill
 
Charles Philip
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I put tools.jar in my build path in order to use javac and the error(HTTP Status 500) is:


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 468 in the jsp file: /CodeGenerator.jsp
com.sun.tools.javac.Main cannot be resolved to a type
465:
466: String javacArguments[] = new String[1];
467: javacArguments[0] = "SimApplet.java";
468: com.sun.tools.javac.Main.compile(javacArguments);

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


Charles
 
Ranch Hand
Posts: 87
Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
com.sun.tools package is not standardized and is meant for internal usage only.

What version of java are you using ? If you are using Java 6 , have a look at the new compiler api.

http://download.oracle.com/javase/6/docs/api/javax/tools/package-summary.html
 
Charles Philip
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the codes in the link but it did not work. I wrote a .bat file and it solved my problem.

Thanks anyway!
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic