I have upgraded my application from Wicket 1.x to 8.x version.
I am facing an issue to convert Excel file into PDF format.
Using this below dependencies:
<dependency>
<groupId>net.sf.jodconverter</groupId>
<artifactId>jodconverter</artifactId>
<version>3.0-beta-4</version>
</dependency>
Using these import classes
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeConnectionProtocol;
import org.artofsolving.jodconverter.office.OfficeManager;
Getting this below error on this line while calling buildOfficeManager() method.
OfficeManager officeManager = eomc.buildOfficeManager();
I am getting this below exception on this above line:
java.lang.ClassNotFoundException: com.sun.star.connection.NoConnectException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
at org.artofsolving.jodconverter.office.ExternalOfficeManager.(ExternalOfficeManager.java:55)
at org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration.buildOfficeManager(ExternalOfficeManagerConfiguration.java:50)
Using below system parameters:
[openofficeHome=C:/Program Files/openoffice.org3, hostname=127.0.0.1, port=8100, protocol=SOCKET]
Below is the more detail of code:
ExternalOfficeManagerConfiguration eomcTest = new ExternalOfficeManagerConfiguration();
eomcTest.setConnectOnStart(true);
eomcTest.setConnectionProtocol(ooConfig.getProtocol());
if (OfficeConnectionProtocol.PIPE.equals(ooConfig.getProtocol())) {
eomcTest.setPipeName("officePipe");
} else {
eomcTest.setPortNumber(ooConfig.getPort());
}
OfficeManager officeManager = eomcTest.buildOfficeManager();
officeManager.start();
OfficeDocumentConverter officeDocConverter = new OfficeDocumentConverter(officeManager);
resultFile = File.createTempFile(sheetName, TypeOfFile.PDF.getFileExtension());
officeDocConverter.convert(tempFile, resultFile);
fout.close();
officeManager.stop();
Kindly anyone let me know why buildOfficeManager() is giving error here and what can be the solution here to resolve this issue. It will be more appreciable.
According to https://search.maven.org/search?q=fc:com.sun.star.connection.NoConnectException you need to add org.libreoffice:libreoffice (or the old org.libreoffice:ridl) dependency to Maven's pom.xml.
I don't see net.sf.jodconverter at https://search.maven.org/search?q=jodconverter. You may try with a more recent version of it - probably any of the listed ones here: https://search.maven.org/search?q=g:org.jodconverter
I have resolved this issue and above code is working fine to convert excel file into pdf file with jodconverter API.
In my case, excel file and pdf file both were having the same name which was causing the issue to return the same excel file on pdf download link. After a change in pdf's name, it resolved my issue.
Related
I am trying to write a java wrapper to use my h2o mojo model. When I load my model zip files in, I receive a null pointer exception. Below is a sample of my code:
public static void main(String[] args) throws Exception {
EasyPredictModelWrapper predict_model = new EasyPredictModelWrapper(
MojoModel.load("prediction_football_model.zip"));
EasyPredictModelWrapper class_model = new EasyPredictModelWrapper(
MojoModel.load("classification_football_model.zip"));
}
and error Message:
Exception in thread "main" java.lang.NullPointerException: entry
at java.util.zip.ZipFile.getInputStream(ZipFile.java:346)
at hex.genmodel.ZipfileMojoReaderBackend.getTextFile(ZipfileMojoReaderBackend.java:18)
at hex.genmodel.ModelMojoReader.parseModelInfo(ModelMojoReader.java:154)
at hex.genmodel.ModelMojoReader.readFrom(ModelMojoReader.java:27)
at hex.genmodel.MojoModel.load(MojoModel.java:35)
at GamePrediction.main(GamePrediction.java:52)
I have been working on this code in eclipse and I have placed both of the zip files in the main project folder. I created the models in R using the h2o.download_mojo() function. I looked into the error message and found that my ZipEntry for the given path's were Null, but I could not find a solution to that.
Any help or insight would be helpful. I couldn't find any other issues like this so if this is a duplicate, please point me to the right direction!
I got the same error and resolved it.
In my case, the mojo runtime file had a problem. I was using 1.8.1.1, and a bug discovered around the time of the version. I simply replaced the file with the latest one. Then everything worked like a charm.
Here is the link for the file. Please notice that this may not be the latest one for you. https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/mojo2-runtime/2.5.9/any/mojo2-runtime-2.5.9-all.jar
I want to save a random forest regression model in PMML from R, and load it in Spark (Scala or Java). Unfortunately I have issues in the second step.
A minimal example of saving a PMML of a random forest regresion model in R is provided below.
When I try to load this model from Scala or Java using jpmml (see code below), I get the following error:
Exception in thread "main" java.lang.IllegalArgumentException: http://www.dmg.org/PMML-4_3
I can overcome this error editing the xml file: the attribute "xmlns" in the tag "PMML" contains the url that appears in the error message. If I remove completely the url or I change 4_3 to 4_2, this error disappears. However, a new error message appears:
Exception in thread "main" org.jpmml.evaluator.UnsupportedFeatureException (at or around line 19): MiningModel
Do you have please any suggestions or ideas on how to solve this specific error or, more in general, how to load in Scala a pmml created in R?
Thank you!
Update: The problem, as answered by #user1808924, was the version of the jpmml library. The code quoted below now works fine. The correct libs should be loaded, for example using the Maven Central Repository:
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-evaluator</artifactId>
<version>1.3.6</version>
</dependency>
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-spark</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Minimal example of saving a PMML of a random forest regresion model in R:
library(randomForest)
library(r2pmml)
data(mtcars)
MPGmodel.rf <- randomForest(mpg~., mtcars, ntree=5, do.trace=1)
# with package "r2pmml", convert model to pmml version 4.3 and save to xml:
r2pmml(MPGmodel.rf, "MPGmodel-r2pmml.pmml")
Loading the model in Scala:
import java.io.File
import org.jpmml.evaluator.Evaluator
import org.jpmml.spark.EvaluatorUtil
val fileNamePmml = "MPGmodel-r2pmml.pmml"
val pmmlFile = new File(fileNamePmml)
// the "UnsupportedFeature MiningModel" error appears here:
val myEvaluator: Evaluator = EvaluatorUtil.createEvaluator(pmmlFile)
I've also tried to load the model using Java, with identical error messages:
import org.dmg.pmml.PMML;
import org.jpmml.evaluator.ModelEvaluator;
import org.jpmml.evaluator.ModelEvaluatorFactory;
import java.io.*;
import java.util.Scanner;
import java.io.ByteArrayInputStream;
File pmmlFile = new File(fileNamePmml );
// the pmml file is successfully loaded as a string:
String pmmlString = null;
pmmlString = new Scanner(pmmlFile).useDelimiter("FILEFINISHESHERE").next();
// a PMML object is successfully created from the pmml string:
PMML myPmml = null;
try(InputStream is = new ByteArrayInputStream(pmmlString.getBytes())){
myPmml = org.jpmml.model.PMMLUtil.unmarshal(is);
}
// the "UnsupportedFeature MiningModel" error appears here:
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
ModelEvaluator<?> modelEvaluator = modelEvaluatorFactory.newModelEvaluator(myPmml);
You're using a legacy JPMML library, which was discontinued 3+ years ago. Naturally, it doesn't support new PMML features (such as PMML 4.2 and 4.3 schemas) that have been added since then.
Simply upgrade to the JPMML-Evaluator library. As a bonus, your code will be much shorter and cleaner.
You could use PMML4S to load the PMML model in Scala, for example:
import org.pmml4s.model.Model
val model = Model.fromFile("MPGmodel-r2pmml.pmml")
val result = model.predict(data)
The input data could be a map, a list of pairs of keys and values, an array, json, or PMML4S's Series.
I have a little problem. I´ve been trying to use different libraries to produce a json token and now I'm using JJWT from Stormpath. They have tutorials well explained. But my problem is, when I try to run the String method in a "public static void main" method, I get a runtime or class error. In their official website says there is a requeriment that the jackson library must being newer than Version 2.8. So I downloaded such library.
Here my source code:
package org.comunidadIT.proyecto.accesoDatos;
import java.security.Key;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.crypto.MacProvider;
public class ValidarToken {
public String token(){
// We need a signing key, so we'll create one just for this example. Usually
// the key would be read from your application configuration instead.
Key key = MacProvider.generateKey();
String compactJws = Jwts.builder()
.setSubject("Joe")
.signWith(SignatureAlgorithm.HS512, key)
.compact();
return compactJws;
}
public static void main(String args[]){
ValidarToken t= new ValidarToken();
System.out.println(t.token());
}
}
The console show following error message:
Exception in thread "main" java.lang.NoSuchFieldError: USE_DEFAULTS
at com.fasterxml.jackson.annotation.JsonInclude$Value.<clinit>(JsonInclude.java:204)
at com.fasterxml.jackson.databind.cfg.MapperConfig.<clinit>(MapperConfig.java:44)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:549)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:465)
at io.jsonwebtoken.impl.DefaultJwtBuilder.<clinit>(DefaultJwtBuilder.java:42)
at io.jsonwebtoken.Jwts.builder(Jwts.java:116)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.token(ValidarToken.java:16)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.main(ValidarToken.java:27)
Image from maven dependencies where appears to be fine with jackson
Image from the console with erros
As you can see the jackson dependencies appears to be fine.
Also I aatached more libreries to the build-path on reference libraries, but they are outside from the pom.xml.
What do I do wrong?
Thank you
I answer myself so perhaps someone could have the same problem.
I've been with this problem about a month, until I got balls to delete some old libraries located in my project.
The problem appeared to be that I declared a Maven dependecy with jackson 2.8.2 or later and in the 'reference libraries' I had libraries lowers than 1.9, when I removed from my Build-Path the problem was gone. And now I can see the String Token.
This is the picture with the problem solved.
Thank you.
How can I set up my project in Intellij to use the ROME library to read a RSS Feed?
So far, I've developed the following:
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import java.net.URL;
public class ReadRSS {
public static void main(String[] args) {
String urlString = "http://news.ycombinator.com/"
boolean ok = false;
if (args.length==1) {
try {
URL feedUrl = new URL(urlString);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
System.out.println(feed);
ok = true;
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}
}
if (!ok) {
System.out.println();
System.out.println("FeedReader reads and prints any RSS/Atom feed type.");
System.out.println("The first parameter must be the URL of the feed to read.");
System.out.println();
}
}
}
But, I get multiple errors when running my code, mainly of the variant:
.. java:package com.sun.syndication.feed.synd does not exist..
How do I import the package in Intellij? Managed to import this my adding jar in my project structure.
But the next problem is: I can't access org.jdom.Document - though I have installed jdom in my project structure. The error I get is
Error:(16, 38) java: cannot access org.jdom.Document class file for
org.jdom.Document not found
How can I resolve this?
If you're using Maven or gradle add the dependency in your configuration file (ex. pom.xml in Maven) and do a build/install to download your dependencies. It should work fine after that. Dependency info is here: http://mvnrepository.com/artifact/rome/rome/0.9
Otherwise add the jar (downloadable from the link above) manually to your project. Look at the first answer in this question to see how to do this: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
I'm a developer of the ROME team. The latest version is ROME 1.5. It can be obtained from the central maven repository: http://search.maven.org/#artifactdetails%7Ccom.rometools%7Crome%7C1.5.1%7Cjar
The groupId has changed to com.rometools in v1.5.0.#
I highly recommend you to use Maven, Gradle or another build tool that is able to resolve transitive dependencies so you won't have to collect all dependencies manually.
I'm using JACOB to do COM calls to PowerPoint and other Office applications from Java. On a particular Windows 7 box I'm getting the following message quite often, but not always:
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.
From excel I get:
ERROR - Invoke of: Open
Source: Microsoft Office Excel
Description: Microsoft Office Excel cannot access the file 'c:\marchena\marchena10\work\marchena\batch_58288\input\content_1.xlsx'. There are several possible reasons:
? The file name or path does not exist.
? The file is being used by another program.
? The workbook you are trying to save has the same name as a currently open workbook.
The Word error is just:
VariantChangeType failed
The following is what I'm running, the error comes from the last line.
ComThread.InitSTA();
slideApp = new ActiveXComponent("PowerPoint.Application");
Dispatch presentations = slideApp.getProperty("Presentations").toDispatch();
Dispatch presentation = Dispatch.call(presentations, "Open", inputFile.getAbsolutePath(),
MsoTriState.msoTrue.getInteger(), // ReadOnly
MsoTriState.msoFalse.getInteger(), // Untitled The Untitled parameter is used to create a copy of the presentation.
MsoTriState.msoFalse.getInteger() // WithWindow
).toDispatch();
I've tried putting a breakpoint just before doing the Open call and the file is there, and I can actually open it with PowerPoint in the GUI but when I step the exception is thrown.
The annoying thing about this issue is that it seems to happen continuously to begin with, but after poking at it for a while (rerunning the same code), it eventually completes successfully, and after that never reoccurs.
Further research I've found this only happens with to .ppt, .doc and .xls files, not .pptx, .docx and .xlsx. And as far as I can tell it's not file system related (I've swapped out the mechanism that copies the files and tried putting the files on a different file system).
I've just noticed that this only happens when the Java application is running as a service, not when I run catalina.bat start from command line.
I had the same problem (jacob in service not working), and this helpful posting (changing the dcomcnfg) did the trick:
http://bytes.com/topic/c-sharp/answers/819740-c-service-excel-application-workbooks-open-fails-when-called-service#post3466746
Does this work for you?
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class PPT {
private static final String inputFile = "c:\\learning.ppt";
public static void main(String[] args) {
ActiveXComponent slideApp = new ActiveXComponent("PowerPoint.Application");
slideApp.setProperty("Visible", new Variant(true));
ActiveXComponent presentations = slideApp.getPropertyAsComponent("Presentations");
ActiveXComponent presentation = presentations.invokeGetComponent("Open",new Variant(inputFile), new Variant(true));
ComThread.Release();
}
}
Update: If this is working the client and it's just automation that is causing the issues, you can view http://support.microsoft.com/kb/257757 to look at possible issues. There error codes are obviously different, but it may help you troubleshoot all the same.