aspose file tools*
The moose likes JSP and the fly likes Compile .java file on JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Compile .java file on JSP" Watch "Compile .java file on JSP" New topic

Compile .java file on JSP

Charles Philip

Joined: Feb 26, 2011
Posts: 5

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

Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29287

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Charles Philip

Joined: Feb 26, 2011
Posts: 5
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.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12682
I get an error saying that it could not compile.

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


Java Resources at
Charles Philip

Joined: Feb 26, 2011
Posts: 5
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 cannot be resolved to a type
466: String javacArguments[] = new String[1];
467: javacArguments[0] = "";


prem pillai
Ranch Hand

Joined: Nov 02, 2007
Posts: 87 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.
Charles Philip

Joined: Feb 26, 2011
Posts: 5
I tried the codes in the link but it did not work. I wrote a .bat file and it solved my problem.

Thanks anyway!
I agree. Here's the link:
subject: Compile .java file on JSP
Similar Threads
Trying to use a bean
Using a JavaBean tags in a JSP page
Log4j and WSAD 5.0
connection can not be resolved
taglib in JSP not working in struts