I am developing web application using Java + OpenOffice to generate report documents.
A tomcat server and the war file is installed on a Fedora machine.
Below code works fine to create writer documents on Windows OS but giving error on the Fedora machine while calling from client side using war file:
String oooExeFolder = "/usr/lib/openoffice.org3/program";
XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
XMultiComponentFactory xMultiComponentFactory = xContext.getServiceManager();
XComponentLoader xcomponentloader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, xMultiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));
XComponent xcomp = xcomponentloader.loadComponentFromURL(filep[i], "_blank", 0, new PropertyValue[0]);
This is the Error :
CE> /usr/lib/openoffice.org3/program/soffice.bin X11 error: Can't open display:
CE> Set DISPLAY environment variable, use -display option
CE> or check permissions of your X-Server
CE> (See "man X" resp. "man xhost" for details)
Can anyone help to identify possible causes for this problem?
You need to launch soffice in "headless" mode. I suggest you look at JODReports or Docmosis since they will save you a lot of time in this type of setup problem. Please note I work for the company that created Docmosis.
After Setting display to "1.0" with following code manually problem has been resolved and i am able to access Open Office from web application to generate report
oooExeFolder = "/usr/lib/openoffice.org3/program/";
List<String> oooOptions = OOoServer.getDefaultOOoOptions();
oooOptions.add("-display");
oooOptions.add(":1.0");
OOoServer server = new OOoServer(oooExeFolder, oooOptions);
XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
Related
Im working with Graal VM, using combined languages like Java and Python. I have a problem when try to execute Python sintax to read/create files using context.eval().
I use this code using Graalpython in terminal:
out_file = File.new("cadena.txt", "w+")
out_file.puts("write your stuff here")
out_file.close
and works, but when I tried to run a code to read the file in context.eval() with Java:
codigoPython += "fichw = open('cadena.txt','r')";
codigoPython += "fichw.read() ";
codigoPython += "fichw.close() ";
Value filecontent = context.eval("python", codigoPython);
it throws me this error:
PermissionError: (1, Operation not permitted, cadena.txt, None, None)
I also tried running it using sudo and sudo su but it gives me the same error. Does anyone know why this happened?
Thanks
You need to give your context permission to do IO:
Context context = Context.newBuilder("python").allowIO(true).build();
For experimenting/prototyping it may be useful to allow everything:
Context context = Context.newBuilder("python").allowAllAccess(true).build();
test.vbs file contains following snippet..
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\testing\new1.xlsm")
objExcel.Application.Visible = True
objExcel.DisplayAlerts = False
Set Sheeet1 = objWorkbook.Worksheets(1)
'The above script is working when I execute manually via command prompt
Sheeet1.Activate
Sheeet1.TextBox1.value = "C:\testing\"
objWorkbook.Save
objExcel.Application.Run "Execute Calculator"
objWorkbook.Save
objWorkbook.Close
objExcel.Quit
Set Sheeet1 = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
Above snippet works fine when I doubleclick on test.vbs file. But it fails to run/waiting for infinite time without any error or warning with Java Executor thread.
Software Configuration:
Excel 2013
Windows 7 OS
Above script is working in Windows 10 and Excel 2016 version.
What is the problem, is there any security setting changes required in PC? Can anybody give the solution, who come across this issue?
XLLoop is opensource framework to java. For example we can use function from java in excel. Below is very simple example of usage:
package org.boris.xlloop.util;
import org.boris.xlloop.FunctionServer;
import org.boris.xlloop.handler.*;
import org.boris.xlloop.reflect.*;
public class ServerExample
{
public static void main(String[] args) throws Exception {
// Create function server on the default port
FunctionServer fs = new FunctionServer();
// Create a reflection function handler and add the Math methods
ReflectFunctionHandler rfh = new ReflectFunctionHandler();
rfh.addMethods("Math.", Math.class);
rfh.addMethods("Math.", Maths.class);
rfh.addMethods("CSV.", CSV.class);
rfh.addMethods("Reflect.", Reflect.class);
// Create a function information handler to register our functions
FunctionInformationHandler firh = new FunctionInformationHandler();
firh.add(rfh.getFunctions());
// Set the handlers
CompositeFunctionHandler cfh = new CompositeFunctionHandler();
cfh.add(rfh);
cfh.add(firh);
fs.setFunctionHandler(new DebugFunctionHandler(cfh));
// Run the engine
System.out.println("Listening on port " + fs.getPort() + "...");
fs.run();
}
}
I understand it and generally programm is working. But if I go to excel, it isn't working.
I try:
=FS("Math.random")
=Math.random()
But I got #NAME? twice
So I suppose that I should make something yet. Could you tell me step by step how configure excel and java to do this? What should I do with xlloop-0.3.2 (Microsoft Excel XLL Add-In) file ?
I tried running the code and I got the following output.
All I had to do was to launch Excel and add the XLLoop addin.
. Press Alt+G or click on the Go button beside Manage Excel Add-ins.
. Click on Browse and provide the path to the xlloop-0.3.2.xll file. If you had downloaded xlloop-0.3.2.zip,extract it and you will find it inside /xlloop/bin
Hope that helps.
Edit:
Launch Excel.
Start the server(run the Main class) and test the formulas.
I tested the following 2(typed them on the Excel formula bar and hit/press Enter) and it worked fine. :)
=FS("Math.sin", 3.14)
=FS("Math.random")
For anyone running into the same problem:
You have to add the correct Addin Version to your excel installation.
If you are getting the error message: "The file format and extension [...] don't match.", it means that you are using a 64bit excel and the 32bit XLLoop addin.
You have to either install a 32bit Excel, or you have to get the 64bit version of the XLLoop Plugin.
We ran into the same problem, and created a 64bit version of the addin: https://github.com/PATRONAS/xlloop
I am trying to build a java project which contains R codes. Main logic behind that is I want to automate the data structuring and data analysis with in a same project. Partially I am being able to do that. I connected R to Java and my R codes are running well. I did all my set up in the local machine and its giving me all output as I need. As data set is big I am trying to run this on amazon server. But when I am shifting it to server, my project is not working properly. Its not being able to execute library(XLConnect), library(rJava). When ever I am calling this two libraries in my java project it's crashing. Independently in R codes are running and giving me output. What I can I for that, and how to fix thus error. Please help me out from this.
My java codes is
import java.io.InputStreamReader;
import java.io.Reader;
public class TestRMain {
public static void main(String[] arg)throws Exception{
ProcessBuilder broker = new ProcessBuilder("R.exe","--file=E:\\New\\Modified_Best_Config.R");
Process runBroker = broker.start();
Reader reader = new InputStreamReader(runBroker.getInputStream());
int ch;
while((ch = reader.read())!= -1)
System.out.print((char)ch);
reader.close();
runBroker.waitFor();
System.out.println("Execution complete");
}
}
And in the Modified_Best_Config.R I have written these codes
library('ClustOfVar');
library("doBy");
library(XLConnect)
#library(rJava)
#library(xlsx)
path="E:/New/";
############Importing and reading the excel files into R##############
Automated_R <- loadWorkbook("E:/New/Option_Mix_Calculation1.xlsx")
sheet1 <- readWorksheet(Automated_R, sheet = "Current Output")
sheet2 <- readWorksheet(Automated_R, sheet = "Actual Sales monthly")
sheet3 <- readWorksheet(Automated_R, sheet = "Differences")
#####################Importing raw Data###############################
optionData<- read.csv(paste(path,"ModifiedStructureNewBestConfig1.csv",sep=""),head=TRUE,sep=",");
nrow(optionData)
optionDemand=sapply(split(optionData,optionData$Trim),trimSplit);
optionDemand1=t(optionDemand[c(-1,-2),]);
optionDemand1
################Calculating the equipment Demand####################
optionDemand2<-t(optionDemand2[c(-1,0)]);
Rownames <- as.data.frame(row.names(optionDemand2))
writeWorksheet(Automated_R,Rownames, sheet = "Current Output", startRow = 21, startCol = 1)
writeWorksheet(Automated_R,optionDemand2, sheet = "Current Output", startRow = 21, startCol = 2)
saveWorkbook(Automated_R)
But java is stopping its operation after these line.
library("doBy");
Whole set of codes are running on nicely on my local machine. But whenever I am trying to run this on amazon server it's not running. Individually in R this code is running on server. I have couple of more R codes which are running with out any error. What can I do for that, please help me out.
Thanks for updating your question with some example code. I cannot completely replicate your circumstances because I presently don't have immediate access to Amazon EC2, and I don't know the specific type of instance you are using. But here a couple of suggestions for de-bugging your issue, which I have a hunch is being caused by a missing package.
1. Try to install the offending packages via your R script
At the very beginning of your R script, before you try to load any packages, insert the following:
install.packages(c("XLConnect", "rJava"))
If your instance includes a specified CRAN mirror (essentially, the online repository where R will first look to download the package source code from), this should install the packages in the same repo where your other packages are kept on your server. Then, either library or require should load your packages.
(sidenote: rJava is actually a dependency of XLConnect, so it will automatically load anyway if you only specify library(XLConnect))
2. If the above does not work, try installing the packages via the command line
This is essentially what #Ben was suggesting with his comment. Alternatively, see perhaps this link, which deals with a similar problem with a different package. If you can, in terminal on the server, I would try entering the following three commands:
sudo add-apt-repository ppa:marutter/rrutter
sudo apt-get update
sudo apt-get install r-cran-XLConnect
In my experience this has been a good go-to repo when I can't seem to find a package I need to install. But you may or may not have permission to install packages on your server instance.
I have a Java application for MAC OSX that I have coded and made a .pkg of it. While creating the .pkg I gave it a version number also. Now I need to get the version number of this application in my java code so that i can check for updates when the application runs. When I right-click on my app file it doesn't show me the version I entered while creating the package.
Do I need to set the version of my app file that I created using the jar bundler for building the pkg???
Please suggest me how I could accomplish this.
The version number you set while creating the package (in the PackageMaker Project) is the version of the installer, not the version of your .app-File. It is needed, so that another installer can see if he downgrades the current installation or not. The installer will never ever look at the contents it is installing to the system.
To set the version of your your .app-Bundle, right-click your .app-file and select "Show Package Contents" from the appearing menu. Open the folder "Contents", there you will find a file called "Info.plist". You have to edit this file and have to set your version-info for your application there. You can do this by using Property List Editor (included in the Apple Developer Tools) or another tool like BBEdit for example.
To read from your .plist in your application, you need a special library. I recommend the Java property list library from Daniel Dreibrodt (more information about the .plist-Format you'll find in this post on my blog).
Generelly, you should set the version-info of your app-bundle, anyway you use it for updating-purposes or not. If it is not set, the user has no chance to get information about the version he has installed without launching your software.
What you need is not the version of your .pkg file, you need the version of your .app-Bundle. Anyway - the version of your .pkg-file is handled the same way as your .app-file. There is also the Info.plist, where you find the informations. It can also be parsed with the same library.
The pkg is a zip file containing a.o. a file called PackageInfo. PackageInfo is an XML file looking like this:
<pkg-info format-version="2" identifier="com.mycompany.pkg.MyApp" version="1.2.0" overwrite-permissions="false" install-location="/" auth="root">
<payload installKBytes="4717" numberOfFiles="146"/>
<scripts>
<preinstall file="./preinstall"/>
<postinstall file="./postinstall"/>
</scripts>
<bundle-version>
<bundle path="./Applications/MyApp.app" CFBundleShortVersionString="1.2.0" CFBundleVersion="166" id="com.mycompany.MyApp" CFBundleIdentifier="com.mycompany.MyApp">
<bundle path="./Contents/Library/LoginItems/HelperApp.app" CFBundleShortVersionString="1.0" CFBundleVersion="1" id="com.mycompany.HelperApp" CFBundleIdentifier="com.mycompany.HelperApp"/>
</bundle>
</bundle-version>
</pkg-info>
To get the package version, you could use the following XPath:
pkg-info/#version
To get the application version:
pkg-info/bundle-version/bundle/#CFBundleShortVersionString
And the build number is here:
pkg-info/bundle-version/bundle/#CFBundleVersion
I know it is a quite old question but the answers are not satisfying. Here is my solution:
A MacOS .pkg file is an archive in XAR format. So any XAR archive reader can read its contents. I found an XAR reader for Java from Sprylab here. This library has Apache 2.0 license so it is free to use also for commercial products. It is quite old but it works. The file "Distribution" in the archive is in XML format and gives details about the installer bundle, e.g. the version ;)
I am using JSON so I did not want to add an XML reader for reading just one value. So the following code uses the XAR library and a custom XML reader to extract the version of the bundle in the .pkg installer.
public static void main(String [ ] args) throws XarException {
XarSource xar = new FileXarSource(new File("PathToPkgFile/PkgFilename.pkg"));
XarEntry entry = xar.getEntry("Distribution");
String distributionStr = new String(entry.getBytes());
String bundleVersionXml = getSubstringByStr(distributionStr, "<bundle-version>", "</bundle-version>");
String bundleAttrStr = getSubstringByStr(bundleVersionXml, "<bundle", "/>");
String version = getAttributeValue(bundleAttrStr, "CFBundleVersion");
System.out.println(bundleVersionXml);
System.out.println(bundleAttrStr);
System.out.println(version);
}
private static String getSubstringByStr(String xmlString, String start, String end) {
int startIdx = xmlString.indexOf(start);
int endIdx = xmlString.indexOf(end);
return xmlString.substring(startIdx + start.length(), endIdx);
}
private static String getAttributeValue(String tagContentString, String attribute) {
int startIdx = tagContentString.indexOf(attribute) + attribute.length() + "=\"".length();
int endIdx = startIdx + tagContentString.substring(startIdx).indexOf("\"");
return tagContentString.substring(startIdx, endIdx);
}