Doc and Docx to PDF conversion , using Java on Linux - java

I have a Java code to convert doc,docx to pdf using document4j it work fine on windows, but in linux I have this problem. Can I use this library on linux? Whats alternatives can I have?
The error is
java.io.IOException: Cannot run program "cmd" (in directory "/tmp/1542047549404-0"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) ~[na:1.8.0_171]
2018-11-12 18:32:29.508 ERROR 10831 --- [pool-1-thread-1] c.d.c.msoffice.MicrosoftWordBridge : Unable to run script: /tmp/1542047549404-0/word_start184242440.vbs
java.io.IOException: Could not execute [cmd, /S, /C, ""/tmp/1542047549404-0/word_start184242440.vbs""] in /tmp/1542047549404-0.
at org.zeroturnaround.exec.ProcessExecutor.invokeStart(ProcessExecutor.java:936) ~[zt-exec-1.8.jar!/:na]

I think there are several reasons listed on their homepage why conversion cannot work under linux:
[...] the LocalConverter can only be run if:
The JVM is run on a MS Windows platform that ships with the Microsoft Scripting Host for VBS (this is true for all contemporary versions of MS Windows.
MS Word is installed in version 2007 or higher. PDF conversion is only supported when the PDF plugin is installed. The plugin is included into MS Word from Word 2010 and higher.
MS Word is not already running when the LocalConverter starts. This is in particularly true for MS Word instances that are run by another instance of LocalConverter. (As mentioned, be aware that this is also true for instances running on a different JVM or that are loaded by a different class loader.)
MS Word is properly activated and configured for the user running the JVM. MS Word does therefore not require any configuration on program startup or any other wizard.
When the JVM application which uses the LocalConverter is run as a service, note the information on using MS Word from the MS Windows service profile below.
For alternative approaches see How to convert MS doc to pdf

Related

JPackage getting ERROR: Unknown exception caught trying to find MSI installer

I'm getting the following error in JPackage using JDK-19 and JavaFX-19. Same configuration used to work using JDK-18 and JavaFX-16. It builds the install image, but is missing the msi installer.
Required environment variables:
PATH_TO_FX = C:\Java\javafx-19\sdk\lib
PATH_TO_FX_MODS = C:\Java\javafx-19\jmods
JPackage Version 19
[2022/11/12 10:46:54.801, jpackage.dll (PID: 5696, TID: 11192), jpackage.cpp:155 (Java_jdk_jpackage_internal_WinExeBundler_embedMSI)]
ERROR: Unknown exception caught
[10:45:03.636] Running candle.exe
[10:45:03.647] Running C:\Program Files (x86)\WiX Toolset v3.11\bin\candle.exe
[10:45:03.784] Running light.exe
[10:45:03.788] Running C:\Program Files (x86)\WiX Toolset v3.11\bin\light.exe
[10:45:03.989] Detected [candle.exe] version [3.11.2.4516].
[10:45:03.989] Detected [light.exe] version [3.11.2.4516].
[10:45:03.990] WiX 3.11.2.4516 detected. Enabling advanced cleanup action.
Any guidance or where I might get help is much appreciated.
Thank you
Unfortunately, I needed to replace my boot drive, which involved reinstalling Windows and WIX Toolkit and Java plus all the other stuff. The error no longer occurs. I have no idea what fixed it, the new SSD is built the same as the old with the same versions of all software. There is not a software migration history on the new SSD as there was on the old HD. I'm using the same procedures as before.
I hate when we fix things and not know why, but such is life.

Tomcat9 creates files in /tmp/systemd-private*** path instead of my given path [duplicate]

I'd like for my webapp which is deployed as a war ROOT.war to have write access to /var/www/html/static/images so that it can write uploaded and converted images to that folder so nginx can serve it statically. Currently it doesn't work and triggers a java.nio.file.FileSystemException exception together with the Filesystem is read-only message.
But the filesystem is not read-only and is in great condition. The folder has already been chmodded 777.
Extra info:
The tomcat setup is running on an Ubuntu 18.04 Azure VM with managed disk. The folder is residing on an Ext4 formatted drive
Let's start with: chmod 777 is great for testing, but absolutely unfit for the real world and you shouldn't get used to this setting. Rather set the owner/group correctly, before you give world write permissions.
Edit: A similar question just came up on the Tomcat mailing list, and Emmanuel Bourg pointed out that Debian Tomcat is sandboxed by systemd. Read your /usr/share/doc/tomcat9/README.Debian which contains this paragraph:
Tomcat is sandboxed by systemd and only has write access to the
following directories:
/var/lib/tomcat9/conf/Catalina (actually /etc/tomcat9/Catalina)
/var/lib/tomcat9/logs (actually /var/log/tomcat9)
/var/lib/tomcat9/webapps
/var/lib/tomcat9/work (actually /var/cache/tomcat9)
If write access to other directories is required the service settings
have to be overridden. This is done by creating an override.conf file
in /etc/systemd/system/tomcat9.service.d/ containing:
[Service]
ReadWritePaths=/path/to/the/directory/
The service has to be restarted afterward with:
systemctl daemon-reload
systemctl restart tomcat9
Edit 2022: Note that these are the 2019 paths - validate the file locations for later versions. From the comments to this answer (thank you to V H and Ng Sek Long) here are some updates:
In current Ubuntu file is here: sudo vi /etc/systemd/system/multi-user.target.wants/tomcat9.service – V H Feb 26, 2022 at 19:55
Mine (Ubuntu 20) is installed here /lib/systemd/system/tomcat9.service smh everybody use a different path. – Ng Sek Long Mar 28, 2022 at 8:36
End of edit, continuing with the passage that didn't solve OP's problem, but should stay in:
If - all things tested - Tomcat should have write access to that directory, but doesn't have it, the error message points me to an assumption: Could it be that
Tomcat is running as root?
The directory is mounted through NFS?
The default configuration for NFS is that root has no permissions whatsoever on that external filesystem (or was it no write-permission? this is ancient historical memory - look up "NFS root squash" to get the full story)
If this is a condition that matches what you are running, you should stop running Tomcat as root, and rather run it as an unprivileged user. Then you can set the permissions on the directory in question to be writeable by your tomcat-user, and readable by nginx, and you're done.
Running Tomcat as root is a recipe for disaster: You don't want a process that's available from the internet to run as root.
If these conditions don't meet your configuration: Elaborate on the configuration. I'd still stand by this description for others who might find this question/answer later.

Wix pre-processor rejecting class files with `$anon$` in them from a Scala application

I'm trying to automate the build process of my Scala application for producing a msi installer.
When doing so, windows claims that certain files cannot be found. Here is the command that gets run
[21:39:01.842] Running C:\Program Files (x86)\WiX Toolset v3.11\bin\candle.exe in C:\Users\RUNNER~1\AppData\Local\Temp\jdk.jpackage6105194214114584024\images\win-msi.image\krystalbull
and further down, i start seeing errors like this:
C:\Users\runneradmin\AppData\Local\Temp\jdk.jpackage6105194214114584024\config\bundle.wxf(56) : error LGHT0103 : The system cannot find the file 'C:\Users\RUNNER~1\AppData\Local\Temp\jdk.jpackage6105194214114584024\images\win-msi.image\krystalbull\app\classes\com\krystal\bull\gui\FileMenu$anon$2.class'.
C:\Users\runneradmin\AppData\Local\Temp\jdk.jpackage6105194214114584024\config\bundle.wxf(71) : error LGHT0103 : The system cannot find the file 'C:\Users\RUNNER~1\AppData\Local\Temp\jdk.jpackage6105194214114584024\images\win-msi.image\krystalbull\app\classes\com\krystal\bull\gui\dialog\ViewEventDialog$anon$10$anon$21$anonfun$lessinit$greater$1.class'.
C:\Users\runneradmin\AppData\Local\Temp\jdk.jpackage6105194214114584024\config\bundle.wxf(81) : error LGHT0103 : The system cannot find the file 'C:\Users\RUNNER~1\AppData\Local\Temp\jdk.jpackage6105194214114584024\images\win-msi.image\krystalbull\app\classes\com\krystal\bull\gui\SettingsMenu$anon$5.class'.
You can see more instances of this error in the build log here:
https://github.com/bitcoin-s/krystal-bull/runs/2697961906?check_suite_focus=true#step:8:11
My question is this:
What are the limitations in the windows file system or the program candle.exe that prevent the pre-processor from reading Scala files that include things like $anon$
Is there a valid syntax guide somewhere?
Will I need to manually rename all of these files?

RSelenium UnknownError - java.lang.IllegalStateException with Google Chrome

I am running the following script based on the RSelenium Basics CRAN page:
library(RSelenium)
startServer(args = c("-port 4455"), log = FALSE, invisible = FALSE)
remDr <- remoteDriver(browserName = "chrome")
remDr$open()
This produces the following error:
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.
at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:492)
at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:305)
at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:64)
Based on the comments from this conversation on GitHub, I've modified my startServer() command like so:
startServer(args = c("-port 4455"), log = FALSE, invisible = FALSE)
I then receive the following error in my console:
Error: Summary: UnknownError
Detail: An unknown server-side error occurred while processing the command.
class: java.lang.IllegalStateException
And this error in the Java prompt that pops up:
14:38:55.098 INFO - Launching a standalone Selenium Server
14:38:55:161 INFO - Java: Oracle Corporation 25.40-b25
14:38:55.161 INFO - OS: Windows 7 6.1 amd64
14:38:55.161 INFO - v2.46.0, with Core v2.46.0. Built from revision 87c69e2
14:38:55.209 INFO - Driver class not found: com.opera.core.systems.OperaDriver
14:38:55.209 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
14:38:55:289 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4455/wd/hub
14:38:55:289 INFO - Selenium Server is up and running
I'm not sure if the lack of an Opera driver is an actual error or just a warning. Regardless, I would like to use Chrome, so it seems like it shouldn't matter. What am I doing wrong?
I was finally able to get RSelenium to work by piecing together information from a number of different sources. I think it would be helpful to have all of this information in one location, so here is the process that I went through to get RSelenium to work on Windows 7 (64-bit) with Chrome as the browser:
Download the 64-bit version of Java. I could not get anything to work with the standard download.
Download ChromeDriver.
Download the Selenium Standalone Server or run checkForServer() from R.
Create a batch file to start the Selenium server. I initially tried to use startServer() from an R script, but it would frequently get stuck and not carry on to the next line in the script. Here is the batch file that I created:
java -jar C:\path\to\selenium-server-standalone.jar -Dwebdriver.chrome.driver=C:\path\to\chromedriver.exe
ChromeDriver can be put in the PATH environmental variable, but I decided to add in the path to ChromeDriver to the batch file (which accomplishes the same goal).
Run the R script. Here is my final script:
library(RSelenium)
shell.exec(paste0("C:\\path\\to\\yourbatchfile.bat"))
Sys.sleep(5)
remDr <- remoteDriver(browserName = "chrome")
remDr$open(silent = TRUE)
remDr$navigate("http://www.google.com")
The Sys.sleep() call was necessary because I would get an error in the remoteDriver() call if it ran before the Selenium Server had finished starting.
It is worth noting that RSelenium has some annoying differences for OSX. The invisible=T/silent=T arguments will not work when you run the yourcommand.command file and the remDr$open() method, respectively. The invisible=T will actually remind you that it only works on Windows. Not a huge deal (and if someone has a workaround I'd appreciate it).
For posterity's sake here's a slight variation for OSX to replace shell.exec using a .command file instead of a .bat with the same contents as above:
yourcommand.command file contents
java -jar /path/to/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/path/to/chromedriver
R script modification
library(RSelenium)
system(paste("open","/path/to/yourcommand.command"))
Sys.sleep(5)
...

JPOS Configuration Problems for an Epson POS printer in Windows

I'm trying to print using jPOS in Windows and get the following exception:
jpos.JposException: Could not connect to service with logicalName = Printer: Exception.message=jp.co.epson.uposcommon.util.EpsonJposServiceInstanceFactory
at jpos.loader.simple.SimpleServiceConnection.connect(Unknown Source)
at jpos.BaseJposControl.open(Unknown Source)
...
More information:
I'm trying to port our Java printing software from Linux (where it works well) to Windows. We are using an Epson TM-T70 receipt printer. I installed the regular printer drivers and was immediately able to print stuff using notepad, for instance.
Now I installed the Epson JavaPoS ADK. I configured the printer using the SetupPOS application that comes with the ADK. I created a new configuration for my printer with Logical Device Name "Printer". I saved everything and it created the jpos.xml file.
When I try run our application and it executes printer.open("Printer") where "Printer" is the logical device name and printer is a POSPrinter instance, I get the exception above.
I know that my generated jpos.xml file is being used because if I provide a random logical device name, I get a different exception.
I guess the problem is in the port configuration of SetupPOS. The printer is connected through USB. I tried the Port name that appears in the windows printer properties (ESDPRT001) and I even tried all combiniations of COM1 to COM10 but nothing works.
Does anyone have some suggestion? Thanks!
The Installation Routine of the Epson JavaPOS ADK is ... ahm ... let me say: "very special". So the Installation copies some jar files (like epsonupos.jar, jposXXX.jar and some more) in the ext/lib Directory of the JRE (!!!) (which must be selected while installing the JavaPOS Driver). We had also some very strange effects if we install another JavaPOS Version, switching to another JRE/JDK, using other Printers which are not from Epson or somthing else.
May be your problem is a result of any conflicts between different jar Version or JDK's or somthing else ...
EDIT:
Since ADK Version 1.11.anywhat (not realy sure, but I mean 1.11.9) you can specify the path in which the additional jar files are stored. But: Some DLL's will be also in the currently newest ADK Version (1.13.17) stored into the bin directory of the selected JRE. May be this is also a conflict between different Versions of used jar's and used DLLs or something else ...
I Solved this adding the following library paths to java project:
C:\Program Files\EPSON\JavaPOS\lib
C:\Program Files\EPSON\JavaPOS\SetupPOS
With javaPOS 1.14.6, on Debian 9 Linux I solved with LD_LIBRARY_PATH:
$ export LD_LIBRARY_PATH = /opt/EpsonJavaPOS/bin && javapos_application_to_run
On windows 10 copy:
BluetoothIO.DLL
epsonjpos.dll
EthernetIO31.DLL
SerialIO31.dll
USBIO31.DLL
from C:\Program Files\EPSON\JavaPOS\bin\
to C:\Program Files\Java\jre1.8.0.171\bin\
Run javaPOS application.
I know is a little late for response but may help others with similar problems.
In my case i am interacting with a Data logic Scanner using javapos, and i was having this message:
ERROR: Failed to open DL-Magellan-9400i-USB-OEM-Scanner-Scale profile, jpos.JposException: Could not connect to service with logicalName = DL-Magellan-9400i-USB-OEM-Scanner-Scale:
Exception.message=com.dls.jpos.service.DLSScannerInstanceFactory
i started looking in the javapos software that downloaded from datalogic and found that there was a jar file that was not included in my classpath (JavaPOS.jar) and that was why i was getting the error, take a look netx image:
I wanted to share in case someone has same issues.
(Took me almost 2 days to get it done!!)

Categories