나는 며칠 동안 내 머리카락을 찢어 내고 있는데, 지금은 왜 이런 일이 결코 일어나지 않는지를 알아 내려고 노력하고 있습니다! 첫째, 여기 내 구성입니다 :자바 애플릿에서 직렬 포트에 데이터를 쓰려고하는 중입니까?
윈도우 7 64
JDK 7 86
JRE 씬에서 제공하는 7 개 86
파이어 폭스 86
레일 3
자바 설정은있는 그 "차세대 플러그인"ISN 어떤 식 으로든 다시 활성화됩니다 !!!)
처음에는 RXTX를 시도했지만 "클래스를 찾을 수 없음"오류가 계속 발생했습니다. 나는 이제 winjcom으로 옮겼다. 내가 지금 받고있는 오류는 java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "loadLibrary.winjcom")
입니다.
나는 또한 내 서버 로그가 내가 사용하는 브라우저에 따라 다르다는 것을 알게되었습니다. Firefox를 사용하면 브라우저가 애플릿을로드하려고 시도 할 때 (즉, 애플릿로드가 실패 할 때 더 이상 다운로드되지 않는) GET 로그가 표시되지 않습니다. IE9에서 시도하면 "PortWriter.class"GET 로그를 제외하고 모든 로그가 존재합니다 ... 이는 어떤 이유로 검색되지 않는다는 것을 의미합니다.
JNLP 사용을 피할 때 보안 경고 팝업이 표시되고 "전송"메서드를 실행할 때 보안 액세스 오류를 제외하고 오류가 없습니다. 그러나 내가 JNLP를 사용할 때, IE는 벌금을로드하고 여전히 오류를 준다. 그러나 닫을 때 충돌이 난다. (나는 iexplorer 프로세스를 끝내야한다.) Firefox는 페이지를로드하지 않고 진행 막대에서 멈 춥니 다.
업데이트 - 제가 보안 정책 파일을 통해 보안을 우회하면 애플릿이 작동합니다. 그러나 JNLP는 작동하지 않을 것입니다. 애플릿 태그를 실행할 때 일반적으로 보안 오류가 발생하는 이유라고 생각합니다. JNLP 파일에 직접 액세스 할 때 "PortWriter"클래스를 찾을 수 없다는 오류가 발생합니다. 내 항아리에 문제가 있습니까? 필자는 다른 항아리의 폴더 레이아웃이 디렉토리 구조가 패키지 레이아웃 (예 : 패키지가 com.myname.serialport.PortWriter 인 경우 "com \ myname \ serialport \ PortWriter.jar")과 정확히 일치하는 것으로 나타났습니다. . 그러나 MY JAR 레이아웃은 실제 폴더 레이아웃 (예 : "D : \ Files \ Websites \ pos \ assets \ java \ PortWriter.jar")을 복제합니다. 이것이 오류의 원인입니까? 항아리 내용 (매니페스트 파일 포함)을 루트와 일치하도록 수동으로 변경했지만 어쩌면 내가 잘못한 것일 수도 있습니다. JaNeLa가 확인한 최신 변경 사항을 설명하기 위해이 문제의 JNLP 레이아웃을 업데이트했습니다. I을 어떻게
<applet id="SerialPort" width="1" height="1" codebase="/assets/" code="PortWriter.class" archive="PortWriter.jar">
<param name="jnlp_href" value="PortWriter.jnlp" />
</applet>
:
import com.engidea.comm.CommPort;
import com.engidea.comm.CommPortIdentifier;
import com.engidea.comm.SerialPort;
import com.engidea.comm.SerialPortEvent;
import com.engidea.comm.SerialPortEventListener;
import com.engidea.win32jcom.WinjcomIdentifier;
import java.io.*;
import java.util.Iterator;
import java.util.List;
import java.applet.*;
import java.security.*;
/*
WinJcom is a native interface to serial ports in java.
Copyright 2007 by Damiano Bolla, [email protected]
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This can be used with commercial products and you are not obliged
to share your work with anybody.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Simple class that can list system ports and allow IO
*/
public class PortWriter extends Applet
{
private CommPortIdentifier portIdentifier;
private SerialPort serport;
public void init() {System.out.println("Booting...");}
@SuppressWarnings("unchecked")
public void Sends(String port, String message) throws Exception
{
final String com_port = port;
final String send_message = message;
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
System.out.println("Begin...");
portIdentifier = new WinjcomIdentifier(0);
System.out.println("Selecting Port...");
selectComport(com_port);
new Thread(new PortReader()).start();
System.out.println("Sending...");
typeSendBytes(send_message);
return true;}
});
}
private void typeSendBytes(String message)
{
try
{
System.out.println("Trying To Send...");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String aStr = "";
while (aStr != null)
{
aStr = message + "\r\n";
// WARNING: be careful, you shoulod select the encoding !
// This will timeout if you have FLOW CONTROL and theline is stuck !
byte []buf = aStr.getBytes();
serport.write(buf,0,buf.length);
}
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
private SerialPort openPort (String portName)
{
try
{
CommPort aPort = portIdentifier.getCommPort(portName);
aPort.open();
return (SerialPort)aPort;
}
catch (Exception exc)
{
System.out.println("exc="+exc);
exc.printStackTrace();
}
return null;
}
private void selectComport (String portName)
{
try
{
serport = openPort(portName);
serport.setSerialPortParams(9600,8, SerialPort.STOPBITS_2, SerialPort.PARITY_NONE);
serport.enableReceiveTimeout(20000);
serport.setEventListener(new EventListener());
serport.notifyOnDSR(true);
serport.notifyOnCarrierDetect(true);
serport.notifyOnCTS(true);
}
catch (IOException exc)
{
System.out.println("Exc="+exc);
exc.printStackTrace();
}
}
private final class EventListener implements SerialPortEventListener
{
public void serialEvent(SerialPortEvent ev)
{
System.out.println("Got event="+ev);
}
}
private final class PortReader implements Runnable
{
public void run()
{
try
{
// This will timeout if nothing is received in the specified time.
byte []buff = new byte[1];
while ( serport.read(buff,0,buff.length) > 0)
{
// NOTE: you should be checking the encoding !
System.out.print(new String(buff));
}
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}
}
... 그리고 내 JNLP 파일 :
<?xml version="1.0" encoding="utf-8"?>
<jnlp codebase="http://localhost/assets/" href="PortWriter.jnlp">
<information>
<title>RS232 Communication Applet</title>
<vendor>My Company</vendor>
<description>RS232 Applet for communicating with POS Display Pole</description>
<offline-allowed />
</information>
<security>
<all-permissions/>
</security>
<update check="background" />
<resources>
<jar href="PortWriter.jar" part="com" main="true" />
<jar href="winjcom.jar" part="com" />
<nativelib href="jcomport.jar" part="com" />
</resources>
<applet-desc
name="RS232 Communication Applet"
main-class="PortWriter"
width="1" height="1" />
</jnlp>
... 그리고 내 HTML
이
내 된 .java 파일입니다 이 물건을 작동 시키면 되겠습니까? 나는 Java newb이지만 작업 솔루션을 얻고 싶습니다. 이것은 Rails에서 만들고있는 회사의 POS를위한 것입니다.최종 파일은 다음과 같습니다
/자산/자바 /에서 서버에서:
1) jcomport.jar (서명되지 ...)
2) PortWriter.class (및 모든 관련 클래스 파일)
3) PortWriter.jar
4) PortWriter.% 자바 홈 %에 서명하지/
1) /lib/ext/jcomport.jar()
2)에서 로컬 HD에 JNLP
은 자바의 패키지를 사용하기 위해서는
JNLP가 잘못되었습니다. [JaNeLA] (http://pscode.org/janela/)를 사용하여 검증 해보십시오. –
나는 그랬고, 결과적으로 나의 대답에 명시된 레이아웃에 도달했다 ... 반드시 그런 것은 아니었다. – JakeTheSnake