I want to render a previously designed BIRT report to HTML in Eclipse Indigo. I am using BIRT 4.2.1. When I do it in a normal Java application it runs fine. However, when I want to do the same from a RCP application it does not.
This is my code:
IRunAndRenderTask task=null;
IReportEngine engine=null;
EngineConfig config = null;
IReportRunnable design = null;
try{
config = new EngineConfig( );
IReportEngineFactory factory = (IReportEngineFactory) Platform.
createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
//use this if the report is in the bundle
Bundle bundle = org.eclipse.core.runtime.Platform.getBundle("com.accenture.workforceplanning.ui");
URL url = FileLocator.find(bundle, new Path("/reports/scenarioAnalysis.rptdesign"), null);
String rpt = FileLocator.toFileURL(url).getPath();
//Open the report design
design = engine.openReportDesign(rpt);
task = engine.createRunAndRenderTask(design);
HTMLRenderOption options = new HTMLRenderOption();
options.setImageDirectory("./");
URL url1 = FileLocator.find(bundle, new Path("/reports"), null);
String rpt1 = FileLocator.toFileURL(url1).getPath();
options.setOutputFileName(rpt1 +"/scenarioAnalysis.html");
options.setOutputFormat("html");
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
}catch( Exception ex){
ex.printStackTrace();
}
When the program reaches the task.run() I get the following error:
org.eclipse.birt.report.engine.api.UnsupportedFormatException: The output format html is not supported.
at org.eclipse.birt.report.engine.api.impl.EngineTask.setupRenderOption(EngineTask.java:2047)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:96)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
at com.accenture.workforceplanning.ui.composites.OutputComposite.reportToHtml(OutputComposite.java:470)
at com.accenture.workforceplanning.ui.composites.OutputComposite.createReportScenarioAnalysis(OutputComposite.java:410)
at com.accenture.workforceplanning.ui.composites.OutputComposite.access$6(OutputComposite.java:308)
at com.accenture.workforceplanning.ui.composites.OutputComposite$4.widgetSelected(OutputComposite.java:214)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.accenture.workforceplanning.application.Application.start(Application.java:26)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
It happens the same for any type of outputformat that I want to render.
Any idea what I am doing wrong?
Thanks
Yulexi
I have managed to solve issue. Just in case somebody encounters the same problem this is what I did:
I added manually all the BIRT plug-ins to the dependencies of the product of my RCP application(For some reason, the required plug-ins were not added). Still I don't know what was the missing plug-in. But the application works fine now.
Related
I am trying to open the firefox browser in mac machine.
As I am using latest selenium jar file, so for opening the Firefox browser, I am using geckodriver but not able to launch the browser.
Below are the code which I am using for opening the browser using geckodriver:
public class Apache_POI_TC {
private static WebDriver driver = null;
public static void main(String[]arg) throws Exception{
//This is to open the Excel file. Excel path, file name and the sheet name are parameters to this method
ExcelUtils.setExcelFile(Constant.Path_TestData+ Constant.File_TestData, "Sheet1");
System.setProperty("webdriver.gecko.driver", "/Users/ileadsynapse/Desktop/CT/geckodriver");
DesiredCapabilities capabilities= DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
driver.get("http://www.store.demoqa.com");
SignIn_Action.Execution(driver);
System.out.println("Login successfully.");
Home_Page.lnk_LogOut(driver).click();
driver.quit();
//This is to send the PASS value to the Excel sheet in the result column.
ExcelUtils.setCellData("Pass", 1, 3);
}
}
Error
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger
at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39)
at org.apache.logging.log4j.jcl.LogAdapter.newLogger(LogAdapter.java:34)
at org.apache.logging.log4j.jcl.LogAdapter.newLogger(LogAdapter.java:30)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:40)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:55)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
at org.apache.http.conn.ssl.AbstractVerifier.<init>(AbstractVerifier.java:61)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.<init>(AllowAllHostnameVerifier.java:44)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.<clinit>(AllowAllHostnameVerifier.java:46)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:146)
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:71)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:247)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:224)
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:59)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:49)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:137)
at automationFramework.Apache_POI_TC.main(Apache_POI_TC.java:31)
Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 more
Can anyone please help me to resolve the problem. Thanks in Advance.
My issue for not opening the Firefox browser using geckodriver in mac machine get resolved after configuring the below jars in build path:
log4j-1.2.16.jar
slf4j-api-1.7.6.jar
slf4j-simple-1.7.6.jar
xuggle-xuggler-5.4.jar
I am asking this question because I was unable to find a similar question. I recently completed this college project where I made a console application that connected to the database and everything seemed perfectly fine. The method I used to connect to the database is this:
private static Connection getConnection()
{
Connection connection = null;
try
{
String dbDirectory = "c:/murach/java/db";
System.setProperty("derby.system.home", dbDirectory);
String dbURL = "jdbc:derby:MurachDB2";
String username = "";
String password = "";
connection = DriverManager.getConnection(dbURL, username, password);
System.out.println("connect works");
return connection;
} //end try connection statement
catch (SQLException e)
{
for (Throwable t : e)
{
e.printStackTrace();
System.out.println("something went wrong on connection method");
} //end for loop for errors
} // end catch statement for connection error
return connection;
}
As I said before I created the console application and everything seemed fine and I turned it in. However, I wanted to experiment with something, I wanted to make another version of this application but instead a GUI application using Jform. I used all of the same classes as before, except that instead of a main class, I used a jform. The method and class is exactly the same, because the database didn't change locations in my folder, however when I run it in the Jform application I get a runtime error.
What it was a null point error and I knew it had something to do with connecting to the database because I wrote a System.out.Println in the catch SQL Exception to notify that something went wrong with the method. The connect to the database is fine with the console application, but my question is if there is any further measures I need to take when it comes to working with a JFrame application. Is there anything I am missing or is there any extra step I need to do. For further measures I will display the whole class that works with the database, and I will also use the event handlers in the Jframe.
I want to make this clear in which that I am not required to do this. I am just playing around with Java, and I could easily leave this alone without consequences, but I feel I really want to learn this so this is why I am asking for help. Any kind of advice or if any of you can let you know what I am missing I would really appreciate it.
Edit
adding error information
>java.sql.SQLException: No suitable driver found for jdbc:derby:MurachDB2
something went wrong on connection method
java.lang.NullPointerException
something went from with dislay part
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at CustomerInvoiceDB.getConnection(CustomerInvoiceDB.java:38)
at CustomerInvoiceDB.getCustomers(CustomerInvoiceDB.java:67)
at CutomerInvoice.displayButtonActionPerformed(CutomerInvoice.java:111)
at CutomerInvoice.access$000(CutomerInvoice.java:24)
at CutomerInvoice$1.actionPerformed(CutomerInvoice.java:57)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
I have made a basic application where I use Stanford Parser through OpenIE Lib and when the StanfordCoreNLP is initialized with the specified properties it stops as pos (pos-tagger). I do think all the required models are included so not sure why the process is unable to find the model data.
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation doc = new Annotation(testString);
pipeline.annotate(doc);
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class))
{
Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
for (RelationTriple triple : triples) {
System.out.println(triple.confidence + "\t" +
triple.subjectLemmaGloss() + "\t" +
triple.relationLemmaGloss() + "\t" +
triple.objectLemmaGloss());
}
}
The includes are
stanford-parser.jar
stanford-parser-3.5.2-models.jar
stanford-openie.jar
stanford-openie-models.jar
JDK1.8
Stack-trace when the StanfordCoreNLP class is initiated.
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [1.2 sec].
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: REQUIREMENTS
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.requires(POSTaggerAnnotator.java:169)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:362)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:131)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:127)
at org.sjdp.q2sm.GUI.extractTriplets(GUI.java:373)
at org.sjdp.q2sm.GUI.processSPARQL(GUI.java:353)
at org.sjdp.q2sm.GUI.actionPerformed(GUI.java:153)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6535)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6300)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
This is almost certainly a class incompatibility bug from including both the parser and the OpenIE system at the same time. It'll be fixed in the next release (3.5.3) when everything syncs up again, but since OpenIE didn't exist at the 3.5.2 release the code in that jar is a bit "ahead" of the parser.
The easiest way to run the two at the same time is to run from the Github version of CoreNLP. The command ant jar should create a jar file which contains both the parser and the OpenIE system. The most recent models (warning: large download) should have both the parser and OpenIE models.
I have tried tess4j as a standalone java program and it worked properly giving the text output.
Now i am trying to create a spring mvc web project adding the dependencies for tess4j in pom and i have added the tess4j source inside my project.
File imageFile = new File("D:/Data/jars/tess/eurotext.tif");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
try {
result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
The above code works properly when i tried to run a standalone java program inside the project.so its clear that the jar files are added to build path properly.
but when i call the code in a controller mapping or service it throws a run time exception.
SEVERE: Unsupported image format. May need to install JAI Image I/O package.
https://java.net/projects/jai-imageio/
java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I/O package.
https://java.net/projects/jai-imageio/
at net.sourceforge.vietocr.ImageIOHelper.getIIOImageList(ImageIOHelper.java:324)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:173)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:158)
at com.ocr.tesseract.TesseractExample.getTextFromImage(TesseractExample.java:27)
at com.cogz.tp.controller.HomeController.view(HomeController.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I/O package.
https://java.net/projects/jai-imageio/
Please let me know what am missing.Thanks in advance.
Even I faced the similar problem of using tess4j for DynamicWebProject. But thanks to comment by #nguyenq that helped me I got it working.
Mostly tess4j uses TIFF handler for optical recognition. The dependencies required for it are not available with default ImageIO.
So, jai-imageio.jar is required. All I did was added line ImageIO.scanForPlugins() before I called the wrapper class that performed doOCR.
I had following jars in my lib:-
tess4j.jar
jai_imageio.jar
ghost4j-0.3.1.jar
jna.jar
junit-4.10.jar
Here's the sample code:
TessractOCR tessocr = new TessractOCR();
ImageIO.scanForPlugins();
String extractedString = tessocr.extractTextFromImage(binarizrImage);
The function
public static String extractTextFromImage(BufferedImage image){
RenderedImage img = image;
String result =null;
try {
File outputfile = new File("saved.png");
ImageIO.write(img, "png", outputfile);
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
instance.setDatapath("E:\\OCR-data\\Tess4J-1.2-src\\Tess4J");
result = instance.doOCR(outputfile);
System.out.println(result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
return result;
}
It works 100% :)
Below is the working code sharing for all:
public static String doOCR(File pdfInvoice) {
String result = "";
long totalTime = 0;
long endTime = 0;
long startTime = System.currentTimeMillis();
File imageFile = new File("D:\\docfolder\\9011121584.pdf");
Tesseract instance = Tesseract.getInstance(); //
try {
ImageIO.scanForPlugins();
result = instance.doOCR(imageFile);
endTime = System.currentTimeMillis();
totalTime = endTime - startTime;
System.out.println("Total Time Taken For OCR: " + (totalTime / 1000));
return result;
} catch (Exception e) {
System.err.println(e.getMessage());
result = "";
return result;
}
}
I am trying to integrate mahout into solr (Using updateRequestProcessor chain) But whenever i try to initialise classifierContext i get following error.
INFO: model path :/home/bayes-model
java.lang.IllegalStateException: /home/bayes-model/trainer-weights/Sigma_j/part-*
at org.apache.mahout.common.iterator.sequencefile.SequenceFileDirIterable.iterator(SequenceFileDirIterable.java:79)
at org.apache.mahout.classifier.bayes.SequenceFileModelReader.loadFeatureWeights(SequenceFileModelReader.java:72)
at org.apache.mahout.classifier.bayes.SequenceFileModelReader.loadModel(SequenceFileModelReader.java:46)
at org.apache.mahout.classifier.bayes.InMemoryBayesDatastore.initialize(InMemoryBayesDatastore.java:72)
at org.apache.mahout.classifier.bayes.ClassifierContext.initialize(ClassifierContext.java:44)
at solr.mypkg.CategorizeDocumentFactory.init(CategorizeDocumentFactory.java:67)
at org.apache.solr.core.SolrCore.createInitInstance(SolrCore.java:449)
at org.apache.solr.core.SolrCore.initPlugins(SolrCore.java:1569)
at org.apache.solr.update.processor.UpdateRequestProcessorChain.init(UpdateRequestProcessorChain.java:57)
Caused by: javax.security.auth.login.LoginException: unable to find LoginModule
class: org.apache.hadoop.security.UserGroupInformation$HadoopLoginModule
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:808)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
at javax.security.auth.login.LoginContext.login(LoginContext.java:579)
at org.apache.hadoop.security.UserGroupInformation.getLoginUse
My code is as below :
params = SolrParams.toSolrParams((NamedList) args);
BayesParameters p = new BayesParameters();
String modelPath = params.get("model");
File file=new File(modelPath);
p.set("basePath",file.getAbsolutePath());
LOG.info("model path :"+file.getAbsolutePath());
p.set("classifierType","bayes");
p.set("dataSource","hdfs");
Datastore ds = new InMemoryBayesDatastore(p);
Algorithm alg = new BayesAlgorithm();
ctx = new ClassifierContext(alg,ds);
ctx.initialize();
What could be the reason?