I'm working on a project to communicate to the serial ports using Java. Do I need to have a device connected to serial port to test the following code?
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = "Parallel";
break;
case CommPortIdentifier.PORT_SERIAL:
type = "Serial";
break;
default: /// Shouldn't happen
type = "Unknown";
break;
}
System.out.println(port.getName() + ": " + type);
}
Any solution to make this code working. Currently I'm getting an error as follows.(without attaching any device to serial port.
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.comm.SunrayInfo.isSessionActive()Z
at com.sun.comm.SunrayInfo.isSessionActive(Native Method)
at com.sun.comm.Portmapping.registerCommPorts(Portmapping.java:155)
at com.sun.comm.Portmapping.refreshPortDatabase(Portmapping.java:100)
at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:138)
at PortTest.main(PortTest.java:9)
Java Result: 1
I've configured comm with jre. I've followed this blog to do it.
You're missing the native libraries required. The line above the error lines you posted is telling you that.
You need to install the javax.comm extention - http://www.oracle.com/technetwork/java/index-jsp-141752.html
If you're using windows, it's no longer supported or available from Sun/Oracle. You may be able to find an older version on the net or someone else porting it.
After a bit struggles, I got the code running.
One mistake I made was using RxTx 2.2 library for Fedora 13. It uses 2.2 version of libSerial and libParellal files and 2.1 RxTxComm jar file. When I removed it and used RxTx2.1 I got an error like following.
gnu.io.RXTXCommDriver cannot be cast to javax.comm.CommDriver
While checking for this error, I found the second mistake I made and solution for the above problem. I was using RxTx Driver with java Comm API. Actually the required class files in Java Comm API is already available in the RxTx library with in "gnu.io" package.
So I changed all the javax.comm.* packages to gnu.io.*. Now I can run the application without any error.
Related
I'm trying to port over some old Ruby code I used to run on Heroku to a Python-based Google Cloud Function.
This code runs Apple's Reporter tool which is "a command-line tool that you can use to download your Sales and Trends reports and Payments and Financial Reports". Docs can be found here.
The Ruby code worked well for years until yesterday, running on Heroku with a Ruby + Java build pack. A small snippet of this, where options are args received :
options = [
vendor_id,
file_type,
sub_file_type,
'Daily',
trimmed_date,
version
]
Dir.chdir("#{Rails.root}/tmp/") do
stdout, stderr, status = Open3.capture3("java -jar #{Rails.root}/public/jars/Reporter.jar p=Reporter.properties m=Robot.XML Sales.getReport #{options.join(', ')}")
return {:status => status, :error => stderr.to_s, :stdout => stdout.to_s }
end
The error I'm seeing on Heroku after no code or stack updates is Network is available but cannot connect to application. Check your proxy and firewall settings and try again.
Most of our other similar processes have been moved to Google Cloud Functions, so after getting nowhere with the above error I thought I'd move this also.
So a similar snippet this time in Python:
from subprocess import Popen, PIPE
def execute_reporter_jar(vendor_id, trimmed_date, file_type, api_version):
process = Popen(["java -jar Reporter.jar p=Reporter.properties Sales.getReportVersion Sales, Detailed"], stdin=PIPE, stdout=PIPE, shell=True)
out, err = process.communicate()
print("returncode = %s", process.returncode)
print("stdout = %s", out)
print("stderr = %s", err)
This works well locally, but when I deploy to Gooogle Cloud it seemingly runs successfully in a few ms, however, nothing actually happens and when I dig deeper it seems the subprocess is returning a 127 - command not found error. So it seems the cloud function can't access Java.
After a good 24hrs, I've hit a wall with this. Can anyone help? I have zero Java knowledge and I know cloud functions have a Java runtime, but I would prefer to stick with Python.
The ultimate aim is for Apple's reporter to run and save the requested file to Google Cloud Storage.
Thanks in advance!
The execution environment for Cloud Function's with Python runtime (both 3.7 and 3.8) is currently based in Ubuntu 18.04 (check the information in this link).
The runtime only includes the following system packages and running subprocess is usually not a recommended idea as the system packages included are limited.
If it's paramount for you to stick with Python you could try to deploy your function using the BuildPack CLI and extending the builder image to install Java on the Python runtime or if your application can be dockerized consider building an image yourself with Java included and deploying your application in Cloud Run.
I'm trying for some days to execute a ".dll" file from an JAVA application. If you are interested you can read my first question: Call a .dll function using command line
I used "com4j" to create the COM classes for my DLL. The generated classes looks good and I tried to execute the code, more exactly a method called "getUnitInfo" located in a class called "_Tester":
#DISPID(1610809376) //= 0x60030020. The runtime will prefer the VTID if present
#VTID(8)
int getUnitInfo(
java.lang.String strRequest,
Holder<java.lang.String> strUnitInfo,
#Optional #DefaultValue("") java.lang.String strStationName,
#Optional #DefaultValue("") java.lang.String strUserID);
The instance:
Holder<String> holder = new Holder<String>("test");
_Tester instance = ClassFactory.createTester();
instance.getUnitInfo("", holder, "", "");
But it throws this exception:
Exception in thread "main" com4j.ExecutionException: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
at com4j.ComThread.execute(ComThread.java:203)
at com4j.Task.execute(Task.java:25)
at com4j.COM4J.createInstance(COM4J.java:97)
at com4j.COM4J.createInstance(COM4J.java:72)
at DLL.ClassFactory.createTester(ClassFactory.java:21)
at proiect.DllTest.run(DllTest.java:17)
at proiect.DllTest.main(DllTest.java:11)
I have read a lot of posts regarding this problem on the internet but nothing helped.
Using "PE deconstruct" tool to find out that the .dll file that I need to execute is 32 bit based. I have a 64 bit Windows OS but I installed a 32 bit JAVA and Eclipse.
If I execute "java -version" o the command line:
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) Client VM (build 25.171-b11, mixed mode)
The com4j documentation is lacking information, I think the new generated JAva code still need to communicate with the old DLL but I don't know how it has to be referenced.
Can anybody help?
EDIT
The instance is create using this UUID:
public static DLL._Tester createTester() {
return COM4J.createInstance( DLL._Tester.class, "{4B7CF2DB-F936-4BA3-9DC6-5E99E5220270}" );
}
And I found this in the Windows registry:
CoCreateInstance failed : Class not registered means the GUID you provided does not match any COM item in your Windows registry.
You can try loading a COM object with a different GUID- go into system registry and find any valid GUID, maybe the one associated with Microsoft Excel (in my case, the entry is located under Computer\HKEY_CLASSES_ROOT\Excel.Application\CLSID).
To register your DLL, maybe How do I register a DLL file on Windows 7 64-bit? helps.
EDIT
Check your registry under Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID.
Is you GUID listed under Classes?
Hi i have faced the same issue one month back and the final resolution i have founded which has resolved my issue is changing my java 64bit to 32 bit, and it started working.
note- only add com4j.jar in build path and do not register any .dll files.
Hope this will work for you
I need to create a Java stored procedure in Oracle. I have used IBM's sample class for creating an MQ message from a simple class outside of Java EE environment. I have tested the class by itself and it is working.
My Oracle vesrion is 11i.
When I am trying to add the jars used in the simple application to load to Oralce along with my simple class, I am getting errors about class not found, even if same jars work with the test case. I am stuck with this for over a week and am desperately hoping that someone would be able to help me with it.
Kinds of errors I am getting are like this from -v flag with loadjava utility on the client
on line 326 / 327, you see this:
creating : class com/ibm/mq/jms/admin/AP loading : class
com/ibm/mq/jms/admin/AP
and then at the end starting from line 6224 to end, it indicates that the above class can’t be resolved:
com/ibm/mq/jms/admin/APRCXI: ORA-29534: referenced object
xxxx.com/ibm/mq/jms/admin/AP could not be resolved
com/ibm/mq/jms/admin/APSDX: ORA-29534: referenced object xxxx.com/ibm/mq/jms/admin/AP could not be resolved exiting : errors
resolving class com/ibm/mq/jms/admin/AP
the command I used is:
c:\Oracle\product\11.2.0\client_1\bin\loadjava.bat -f -jarsasdbobjects
-prependjarnames -stoponerror -u xxxx/yyyy#SID -v -resolve lib\jms.jar lib\com.ibm.mqjms.jar lib\com.ibm.mq.jmqi.jar lib\dhbcore.jar
lib\fscontext.jar src\com\test\javasp\mq\JmsProducer.java
I also tried with -genmissing option with some additional jars ( list I found here ), but still get similar error for a different class.
Other issue with this that I am facing is that if I get an error and try to use the dropjava command from Oracle, it doesn't work either.
I also saw from this link, that this person was successful, but unfortunately, he/she didn't indicate how they used loadjava to load the jars.
If i can provide any other information, please let me know.
If anyoneone has any idea on how to get the Java Stored Procedure to use IBM MQ working with Oracle 11i, I would really appreciate the help.
Found a detailed answer in this blog entry. I tried it and it worked for me.
In Oracle there is no concept of CLASSPATH, so the standard MQ Client install is useless. You can only load the jars reference by your app within the database schema. Classes are resolved when loaded with the -r option. You can further on specify your own resolved using -r -Resolver (schemas). (check Oracle docs for exact format). So in effect the database schemas becomes the classpath.
Using Websphere MQ classes for Java poses a number of problems, you have to ensure that the Oracle JDK version is at an appropriate support level to connect to the chosen MQ server version. Check the system requirements for websphere MQ Vx.x. You should find IBM's web references. check the support for MQ classed for java.
I have such an issue at the moment trying to connect to Mq using Oracle 10 and JDK 1.4.2. I had to recompile my Java code using JDK 1.4.x. This does not work and I assume it is because I connect to MQ 7.0.1.7 which requires JRE 1.7 as minimum.
I'm running Mac OS 10.6, Java 1.6_17, Scala 2.8.1 final. I'm attempting to make a simple Skype call using Skype4Java by doing the following:
$>export JAVA_OPTS=-d32
$>scala -classpath .:./skype/release/skype.jar
scala> com.skype.Skype.makeCall("echotest")
I'm getting the error
"invalid attempt to access memory at location 0x0 ... bus error".
Anybody else experience this and find a solution?
Note: I'm able to use this api perfectly fine by invoking one of the samples when I run it using command line java. Attempting to execute the same sample using command line scala fails with the error above.
Try object Test { def main(args:Array[String]) { ... } }
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!!)