Results 1 to 20 of 25
Thread: javax.comm Run Problem
- 08-09-2011, 10:20 PM #1
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
javax.comm Run Problem
Hi
I am using javax.comm package to write an application that sends and receives data using the serial port. My operating system is windows XP. When I run the code from NetBeans6.8 everything works perfectly but when I package it (Build it) and run it from the run prompt like this:
java -jar "C:\RS232InternetPC\dist\RS232InternetPC.jar"
The application fails to find any serial port although the same application works just fine when I run it from the NetBeans6.8. How can I solve this issue?
Any ideas comments are highly appreciated.
Best Regards.
Anderson.
- 08-09-2011, 10:49 PM #2
Do you have all the parts where they need be? Does this version use the comm.jar file? Is it on the classpath?
Is there a .dll needed?
Do you get any error messages?
- 08-09-2011, 11:04 PM #3
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Dear Norm
I have placed the following three files as shown below:
comm.jar
win32com.dll
javax.comm.properties
comm.jar should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib/ext
win32com.dll should be placed in:
%JAVA_HOME%/bin
%JAVA_HOME%/jre/bin
%windir%System32
javax.comm.properties should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib
I am not getting any Error Messages.
The application works just fine when I run it from netbeans but when I run it from the command prompt it doesn't recognize any port (no serials nor parallels).
Regards.Last edited by mr_anderson; 08-09-2011 at 11:07 PM.
- 08-09-2011, 11:08 PM #4
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
I also have read online that I should set the system security manager to null --> System.setSecurityManager(null);
I tried it but I still have the same problem
- 08-09-2011, 11:10 PM #5
Does your code ignore any caught exceptions? I assume all catch blocks have printStackTrace calls in them.
My serial port program gives me this when I run it on this PC that does not have a serial port:
Open port error SerialComm.SerialConnectionException
on port: COM1
openGPS() returned ex: WayPointApps.GPSDevices.SerialCommException: openGPS: open port error, SerialComm.SerialConnectionException
I have no idea where this message comes from. I haven't looked at the code in years.
I have all the files (dll, jar and properties) in one folder and have the manifest Class-path set to:
Class-Path: comm.jar DocumentViewerWParser.jarLast edited by Norm; 08-09-2011 at 11:14 PM. Reason: Added more
- 08-09-2011, 11:21 PM #6
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
I will double check and keep you informed about it.
Thank you for your time.
Regards.
- 08-09-2011, 11:33 PM #7
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Dear Norm
For test purposes I made a very simple program that just counts the available ports
When I run it from NetBeans it runs perfectly but when I run it from command line it doens't read the available ports. Bythe way how can I/We catch any thrown exception in the code below ?
Java Code:import java.util.Enumeration; import javax.comm.CommPortIdentifier; public class Main { public static void main(String[] args) { System.setSecurityManager(null); Enumeration port_list = CommPortIdentifier.getPortIdentifiers(); while (port_list.hasMoreElements()) { CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement(); if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println("Serial port:"+ port_id.getName()+" "); } else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL) { System.out.println("Parallel port:" + port_id.getName()); } else{ System.out.println("Other port:" + port_id.getName()); } } } }
- 08-09-2011, 11:39 PM #8
Sorry, my serial port code is as of 1998. I don't have that class.CommPortIdentifier.getPortIdentifiers();
No idea why it works in the IDE and not in a jar. Usually the problem is in the configuration of the jar file.
What is in the jar file's manifest file? You can open a jar file with a zip utility.
- 08-09-2011, 11:44 PM #9
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Dear Norm
I have attached the needed files (comm.jar, win32com.dll, javax.comm.properties) in this post.I opened the JAR's META-INF Folder and I got the contents of the MANIFEST.MF which are:
Regards.Java Code:Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.1 Created-By: 17.0-b17 (Sun Microsystems Inc.) Main-Class: javaapplication6.Main Class-Path: lib/comm.jar X-COMMENT: Main-Class will be added automatically by build
- 08-09-2011, 11:51 PM #10
Is the comm.jar file in the lib folder and the lib folder in the same folder as your jar file?
- 08-09-2011, 11:53 PM #11
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Yes I have checked that.
The comm.jar is in the lib folder and the JavaApplication6.jar (my application) are in the same folder.
- 08-09-2011, 11:55 PM #12
Your jar file should NOT be in the same folder with the comm.jar file. It needs to be in the folder that has the lib folder in it.
- 08-10-2011, 12:14 AM #13
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
They are not in the same folder I meant that the jar file and the lib folder are in the same folder and the lib folder has the comm.jar file inside it.
Regards.
- 08-10-2011, 12:23 AM #14
One thing that is different from my setup is that I have everything in the same folder. That shouldn't make a difference. No other ideas
Try a test by changing to: Class-Path: comm.jar
The folder I run the jar file from contains:
Java Code:D:\Work\TestFromJar>dir Volume in drive D is Work Volume Serial Number is 1463-F5AE Directory of D:\Work\TestFromJar 05/10/2010 08:00 PM <DIR> . 05/10/2010 08:00 PM <DIR> .. 11/15/1998 04:00 PM 28,043 comm.jar 12/05/2001 02:34 PM 76,799 DocumentViewerWParser.jar 12/18/2000 01:17 PM 768 FileWptsIcon.jpg 07/28/2004 11:59 AM 412 GPS Device Communicator.lnk 05/04/2011 02:45 PM 345,955 GPSDevComm.jar 09/17/2005 02:21 PM 301,315 GPSDevCommOLD.jar 09/30/2004 11:23 AM 293 GPSDeviceCommunicator.ini 05/10/2010 08:01 PM 421 GPSDeviceCommunicator.log 12/18/2000 01:26 PM 1,069 GPSRteIcon.jpg 12/18/2000 01:13 PM 966 GPSWptsIcon.jpg 11/15/1998 03:59 PM 467 javax.comm.properties 10/28/2005 11:01 AM 32 QuesReGPSpgm.txt 05/07/2004 09:34 AM 1,023 Readme.txt 07/04/2006 09:12 PM <DIR> Waypoints 11/15/1998 04:00 PM 27,648 win32com.dll 05/07/2004 09:35 AM 351 _MakeGPSDevComZIP.bat 15 File(s) 785,562 bytes 3 Dir(s) 1,370,492,928 bytes free D:\Work\TestFromJar>Last edited by Norm; 08-10-2011 at 12:25 AM.
- 08-10-2011, 12:46 AM #15
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Dear Norm
My manifest file is generated by Netbeans IDE and here is how it looks
I can see your class path is set to :Java Code:Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.1 Created-By: 17.0-b17 (Sun Microsystems Inc.) Main-Class: javaapplication6.Main Class-Path: lib/comm.jar X-COMMENT: Main-Class will be added automatically by build
as compared to my class path you have two jars while mine has only 1?Java Code:Class-Path: comm.jar DocumentViewerWParser.jar
I tried to unzip my Jar file---> edit itz content and re-rar it then change the extension to jar file so that I have my new Jar file with the manifest's class path set by me but it gave me an error of "Jar corrupted".
By the way which compiler do you use?
- 08-10-2011, 12:51 AM #16
I use the JDK's javac command to compile and the jar command to build my jar files. I create the manifest file with an editor and a batch file to run the jar command with an editor. I don't use any of the IDEs.
Yes I have some other code in the second jar file that my GPS code uses.class path you have two jarsLast edited by Norm; 08-10-2011 at 01:35 AM.
- 08-10-2011, 12:57 AM #17
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Did the following code run normally with you (I mean when you build it as a jar and run it from CMD) ?
Java Code:import java.util.Enumeration; import javax.comm.CommPortIdentifier; public class Main { public static void main(String[] args) { System.setSecurityManager(null); Enumeration port_list = CommPortIdentifier.getPortIdentifiers(); while (port_list.hasMoreElements()) { CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement(); if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println("Serial port:"+ port_id.getName()+" "); } else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL) { System.out.println("Parallel port:" + port_id.getName()); } else{ System.out.println("Other port:" + port_id.getName()); } } } }
- 08-10-2011, 01:34 AM #18
I haven't done anything with your code. If the code works in your IDE, then the problem must be in the way the jar file is being built.
- 08-10-2011, 06:06 AM #19
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Dear Norm
I am thinking of rebuilding the same project using Eclipse, and if it fails I may build my jar file using the java javac commands. What do you think about that?
Best Regards.
Anderson.
- 08-10-2011, 02:09 PM #20
You build a jar with the jar command.I may build my jar file using the java javac commands.
The javac command generates .class files from .java files in a process known as compiling. The java command reads and executes the .class files.
Here is a sample batch file I use to build a jar file:
PHP Code:@Rem create the GetURLText.jar file: %DEV_DRIVE% cd %DEV_HOME%\JavaDevelopment\NormsTools\GetURLText jar -cmf GetURLText.mnf %JAVA_RUN%\GetURLText.jar GetURLText*.class cd %DEV_HOME%\JavaDevelopment\ jar -uf %JAVA_RUN%\GetURLText.jar NormsTools\IntInputField*.class NormsTools\ErrDialog*.class NormsTools\MyLabel*.class NormsTools\MakeEnterDoAction*.class NormsTools\MessageArea*.class NormsTools\ArrayUtil*.class NormsTools\ChoiceOfYesOrNo*.class NormsTools\ShowMsgBox*.class NormsTools\ShowCounters*.class cd %DEV_HOME%\JavaDevelopment\Misc_Projects\DownloadFilesProject jar -uf %JAVA_RUN%\GetURLText.jar DownloadFilesProject.html @Echo ---- Created %JAVA_RUN%\GetURLText.jar ---- MORE
Similar Threads
-
Add new package javax.comm
By rjagan in forum New To JavaReplies: 5Last Post: 04-12-2011, 09:07 AM -
import javax.comm
By kareena in forum Threads and SynchronizationReplies: 2Last Post: 09-21-2010, 03:45 PM -
javax.comm:Error instantiating class com.sun.comm.Win32Driver
By bbq in forum Advanced JavaReplies: 7Last Post: 07-12-2010, 04:24 PM -
javax/comm/SerialPortEvent
By musiigedeo in forum Threads and SynchronizationReplies: 9Last Post: 11-24-2008, 11:07 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks