The JSPC can be Jspc.setargs (args), set the required parameters, and compile the same with the instructions.
Use the instructions to compile the example:
JAVA-CP Jasper.jar;servlet-api.jar; Fcatalina.jar; F:\server\tomcat.6\bin\tomcat-juli.jar;ant.jar;jsp-api.jar;jasper-el.jar;el-api.jar;jstl.jar;standard.jar; Jasper-el.jar;jasper-jdt.jar org.apache.jasper.jspc-uriroot./temp-d temp temp.jsp
You can also set parameters by calling the Set method
Java code
- Public class Test1 {
- Public String Jspctest () {
- String error="";
- try {
- JSPC JSPC = new JSPC ();
- /*string[] arg0 = {"-uriroot", "E:/JSPC", "-D", "d:/t",
- "Temp/temp.jsp"};
- Jspc.setargs (ARG0); * *
- Jspc.seturiroot ("D:/JSPC"); Web app's root directory
- Jspc.setoutputdir ("d:/t"); Output directories for. java files and. class Files
- Jspc.setjspfiles ("temp/temp.jsp"); The JSP to be compiled
- Jspc.setcompile (true); Whether to compile false or not specify only the. java file is generated
- Jspc.execute ();
- } catch (Exception e) {
- Error=e.tostring ();
- }
- return error;
- }
- public static void Main (String args[]) {
- Test1 t=New Test1 ();
- System.out.println (T.jspctest ());
- }
- }
Here the jar packages are referenced from Tomcat
The test class compiles the necessary jar packages:
D:/tomcat5.5/common/lib/jasper-compiler.jar
D:/tomcat5.5/common/lib/jasper-runtime.jar
JSP compiles the necessary jar packages, in addition to the jar that references the class in the JSP:
D:/tomcat5.5/common/lib/commons-el.jar
D:/tomcat5.5/common/lib/jasper-compiler.jar
D:/tomcat5.5/bin/commons-logging-api-1.1.1.jar
D:/tomcat5.5/common/lib/jsp-api.jar
D:/tomcat5.5/common/lib/jasper-compiler-jdt.jar
D:/tomcat5.5/common/lib/servlet-api.jar
D:/tomcat5.5/common/lib/jasper-runtime.jar
D:/tomcat5.5/server/lib/catalina-ant.jar
If you are running the engineering environment in a Tomcat Web environment, add the ant jar to
Original: http://kjah.iteye.com/blog/625588
Compiling JSP files with Org.apache.jasper.JspC--reprint