I'm having trouble with my semantic web application coding. The error says java.lang.ClassNotFoundException: org.apache.jena.ontology.OntModelSpec. I'm using Eclipse JEE Luna, Apache Tomcat 7, JDK 7u79, and Apache Jena 3.6.0. The class should be included in Jena jar files right? But why can't the class be found? Thank you so much for your help :)
Coding excerpt:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<String> dataList = new ArrayList<String>();
Model modeltmp = null;
OntModel mpidb = null;
System.out.println("DONE1");
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
mpidb = ModelFactory.createOntologyModel(spec,modeltmp);
InputStream in = FileManager.get().open("C:/Users/USER/workspace/FYP/Ontologies/MangrovePlantImageDatabase.owl");
mpidb.read(in,"http://www.mangroveplantimagedatabase.com/ontologies/mangroveplantimagedatabase.owl");
System.out.println("DONE3");
}
Related
I am using Tess4j API for performing OCR and have created a dynamic web project in eclipse. If I create a new java class directly under the Java resources folder, the code is working fine.
public static void main(String[] args){
File image = new File("Scan0008.jpg");
ITesseract instance = new Tesseract();
try{
String result = instance.doOCR(image);
System.out.println(result);
}catch(TesseractException e){
System.err.println(e.getMessage());
}
}
However I am getting an exception when I am calling the same code from my Servlets doPost method.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Validate valObj = new Validate();
valObj.validate();
}
public void validate() {
File image = new File("Scan0008.jpg");
ITesseract instance = new Tesseract();
try {
String result = instance.doOCR(image);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
I have included all the required jars under lib folder of WEB-INF. Have also added the jars in the projects build path. Could anyone please let me know what I am doing wrong.
Exception :
java.lang.IllegalStateException: Input not set
23:33:45.002 [http-bio-8080-exec-5] ERROR net.sourceforge.tess4j.Tesseract - Input not set
java.lang.IllegalStateException: Input not set
I think your current directory is different when you are calling from servlet. the current directory is you tomcat bin folder. so when you are calling like this:
File image = new File("Scan0008.jpg");
your scan0008.jpg must be put in bin folder of tomcat or you must use absolute path of your file.
I'd like to test my servlet by printing the results to the console. System.out.println does not seen to work for a servlet. Does anyone know how I can achieve this? Main purpose is for debugging at a later stage.
public class GetAllStaff extends HttpServlet {
private static final long serialVersionUID = 1L;
static StaffDAO dao = new StaffDAO();
static ArrayList<Staff> sList = null;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
sList = dao.getAllStaff();
for (int i = 0; i < sList.size(); i++)
{
}
}
You could use
ServletContext context = getServletContext( );
context.log("This is a log item");
The logs are not printed in Eclipse console but can be found at logs folder of servlet container (say Apache Tomcat)
Reference: http://www.tutorialspoint.com/servlets/servlets-debugging.htm
You may want to print everything on a browser with the following code?
PrintWriter out = res.getWriter();
out.println("Some information on the browser...");
P.S I tried System.out.println("something"); in my IDE (Intellij), the result showed up in the console.
I use java servlets. I wrote a code which has no error,But it returns me an empty list always.
I dint want to update Datastore from the servlet. i just want to read entities. i'll enclose my code tell me where is the problem.
I always get the data store is empty.This is just a test code.Even this dosent seem to work. searched internet for week . All for vain.
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
resp.getWriter().println(datastoreService.getIndexes());
if (datastoreService.getIndexes().isEmpty())
resp.getWriter().println("the data store is empty");
Query query = new Query("IMAGES");
PreparedQuery pq = datastoreService.prepare(query);
for (Entity entity :pq.asIterable())
{
resp.getWriter().println(entity.getKind() );
resp.getWriter().println(entity.getAppId() );
resp.getWriter().println(entity.getKey() );
}
if (!pq.asIterable().iterator().hasNext())
resp.getWriter().println("the data store is empty");
}
I rectified my problem . I forgot to add a namespace. here is a snippet on How to set namespace in GAE DataStore.
// Set the namepace temporarily to "abc"
String oldNamespace = NamespaceManager.get();
NamespaceManager.set("abc");
try {
... perform operation using current namespace ...
} finally {
NamespaceManager.set(oldNamespace);
}
Why does a wildcard not work in java code below?
My request looks like http://localhost:8080/App/DataAccess?location=Dublin
rob#work:~$ ls /usr/local/CustomAppResults/Dublin/*/.history
/usr/local/CustomAppResults/Dublin/team1/.history
/usr/local/CustomAppResults/Dublin/team2/.history
/usr/local/CustomAppResults/Dublin/team3/.history
Servlet code (DataAccess.java).
(DataAccess.java:27) refers to the for loop ..
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File[] files = finder("/usr/local/CustomAppResults/" +
request.getParameter("location") + "/*/");
for (int i = 0; i < files.length; i++){
System.out.println(files[i].getName());
}
}
private File[] finder(String dirName) {
File dir = new File(dirName);
return dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.endsWith(".history");
}
});
}
Error:
The server encountered an internal error that prevented it
from fulfilling this request.
java.lang.NullPointerException
com.example.servlets.DataAccess.doGet(DataAccess.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
The method public File[] listFiles(FilenameFilter filter)
Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
(http://docs.oracle.com/javase/7/docs/api/java/io/File.html)
So, why do you get this situation? You are trying to use a wildcard char (*) that is evaluated by your shell, but won't be evaluated in new File(path). The new File(path) constructor only works for exact paths.
Things like DirectoryScanner (Apache Ant) or FileUtils (Apache commons-io) will solve your problem. See the comments above for further details on possible solutions, including the Java 7 NIO approach (Files.newDirectoryStream( path, glob-pattern )).
I have a service class that creates reports in xls using dynamicjasper, I wonder how I can include a button in my flex app to execute this method.
#Service("downloadService")
#Transactional
public class DownServiceRelTemp {
private static Logger logger = Logger.getLogger("service");
#Resource(name="sessionFactory")
private SessionFactory sessionFactory;
public void downloadXLS(HttpServletResponse response) throws ColumnBuilderException,
ClassNotFoundException, JRException {
logger.debug("Downloading Excel report");
DynamicReport dr = LayouteRelTemp.buildReportLayout();
JRDataSource ds = getDataSource();
JasperReport jr = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), null);
JasperPrint jp = JasperFillManager.fillReport(jr, null, ds);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Exporter.exportToXLS(jp, baos);
String fileName = "MyReport.xls";
response.setHeader("Content-Disposition", "inline; filename=" + fileName);
response.setContentType("application/vnd.ms-excel");
response.setContentLength(baos.size());
Writer.write(response, baos);
}
Any suggestions, do not have much experience with adobe flex and would like a simple help.
There's some ways to interactive flex with java
Using Web Services
Using servlets
By Remoting objects. By AMF thecnology.
I recommend this tutorial of the evangelist James Ward, in this tutorial him explains the differents ways to connect flex and java with code example. That's how I learned to comunicate flex and Java
Notes that you need to check blazeDs Library