import java.util.Date;
import java.text.SimpleDateFormat;
class hprsPurchase {
public static Date snagFinalPaymentDate()
{
return new Date();
}
} // endclass
$ javac hprsPurchase.java
$ jar cf hprsPurchase.jar hprsPurchase.class
$ sudo cp hprsPurchase.jar $CATALINA_HOME/common/lib
Date now = new hprsPurchase.snagFinalPaymentDate();
Date now = new Date();
now = hprsPurchase.snagFinalPaymentDate();
package hprsPurchase;
import java.text.SimpleDateFormat;
import java.util.Date;
public class HprsPurchase {
public static Date snagFinalPaymentDate() {
return new Date();
}
} // endclass
package hprsPurchase;
import java.util.Date;
import java.text.SimpleDateFormat;
public class HprsPurchase {
public static Date snagFinalPaymentDate()
{
return new Date();
}
} // endclass
I did: $ javac HprsPurchase.java
$ jar cf HprsPurcahse.jar HprsPurchase.class
$ sudo cp HprsPurchase.jar $CATALINA_HOME/common/lib
<%@ page import="hprsPurchase.HprsPurchase"%>
is what you need
No - it resolves to a type (as long as you used the code i posted)hprsPurchase.HprsPurchase resolves to a package
jar tf HprsPurchase.jar
hprsPurchase/HprsPurchase.class
is what the listing should sayjar cf hprsPurchase.jar hprsPurchase
and of course HprsPurchase.class should be in directory hprsPurchase as a result of compilation
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 21 in the generated java file
Only a type can be imported. hprsPurchase.HprsPurchase resolves to a package
An error occurred at line: 192 in the jsp file: /finalPaymentReport.jsp
HprsPurchase cannot be resolved
The jar now contains:<%@ page import="hprsPurchase.HprsPurchase" %>
Date now = HprsPurchase.snagFinalPaymentDate();
If I change to <%@ page import="hprsPurchase.HprsPurchase.*" %> // wildcard
the import error goes away
<%@ page import="hprsPurchase.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="HprsPurchase.HprsPurchase.*" %>
<html>
<body>
<%
Date now = HprsPurchase.snagFinalPaymentDate();
%>
</body>
</html>
$ cd $CATALINA_HOME/common/lib
1 01:20:35 root@webserver:/srv/tomcat/common/lib
$ ls -ltr
total 1192
-rw-r-xr-x 1 root root 253122 2007-09-29 17:10 sqljdbc.jar*
-rw-r-xr-x 1 root root 57779 2009-01-09 12:16 commons-fileupload-1.2.1.jar*
-rw-r-xr-x 1 root root 109043 2009-01-10 09:01 commons-io-1.4.jar*
-rw-r-xr-x 1 root root 466359 2009-07-14 06:36 sqljdbc4.jar*
-rwxr-xr-x 1 root root 14146 2013-09-30 12:56 opencsv-2.3.jar*
-rwxr-xr-x 1 root root 284220 2013-12-19 04:12 commons-lang-2.6.jar*
-rwxr-xr-x 1 root root 833 2014-01-04 12:37 HprsPurchase.jar*
is of course wrong. It should be<%@ page import="java.util.Date" %> <%@ page import="HprsPurchase.HprsPurchase.*" %> <html> <body> <% Date now = HprsPurchase.snagFinalPaymentDate(); %> </body> </html>
<%@ page import="hprsPurchase.*" %>
$ jar tvf /srv/tomcat/common/lib/HprsPurchase.jar
0 Sat Jan 04 14:26:18 EST 2014 META-INF/
68 Sat Jan 04 14:26:18 EST 2014 META-INF/MANIFEST.MF
0 Sat Jan 04 14:24:54 EST 2014 hprsPurchase/
326 Sat Jan 04 14:24:54 EST 2014 hprsPurchase/HprsPurchase.class
<%@ page import="java.util.Date" %>
<%@ page import="hprsPurchase.*" %>
<html>
<body>
<%
Date now = HprsPurchase.snagFinalPaymentDate();
out.println(now);
%>
</body>
</html>
import hprsPurchase.*;
:
Date now = HprsPurchase.snagFinalPaymentDate();
System.out.println(now);
but, I have to make sure the HprsPurchase.[java | class | jar ] files are *not* in the same directory as my java program. javac will pick them up and generate errors.I think you are right about the jar needing to be in WEB-INF/lib. I made a symlink from thereMaking a symlink could be dodgy. It could cause classloading problems