我现在需要做一个功能,在服务器端以java web start方式启动客户端程序。而这个客户端程序其中的一个功能就是打开客户的摄像头进行拍照后上传到服务器。 现在完成了一个简单的测试代码,在本地运行一切正常。将其打为JAR文件,部署到服务器上的时候。每当点击菜单调用这个类的时候,java控制台就报异常。我查了GOOGLE上很多资料。都说是jar文件的数字签名问题。现在我对jar做了签名。但还是出现这个异常。我不知道是不是我的签名有问题,还是因为代码的问题导致的这个原因。这方面不是很懂。看了很多文档。还是没有找到解决的办法。希望各位能帮我看一下。谢谢大家了。异常信息java.lang.RuntimeException: No permission to capture from applets
java.lang.RuntimeException: No permission to capture from applets
javax.media.NoPlayerException: Error instantiating class: com.sun.media.protocol.vfw.DataSource : java.lang.RuntimeException: No permission to capture from applets
at javax.media.Manager.createPlayerForContent(Manager.java:1362)
at javax.media.Manager.createPlayer(Manager.java:417)
at javax.media.Manager.createRealizedPlayer(Manager.java:553)
at ins.filemanager.fileuploader.Camera.play(Camera.java:88)
at ins.filemanager.fileuploader.FileUploaderFrame$3.actionPerformed(FileUploaderFrame.java:124)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ins.filemanager.fileuploader.Camera.play(Camera.java:106)
at ins.filemanager.fileuploader.FileUploaderFrame$3.actionPerformed(FileUploaderFrame.java:124)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
签名的方法是参照此文章
http://my.oschina.net/zjun/blog/69
java.lang.RuntimeException: No permission to capture from applets
javax.media.NoPlayerException: Error instantiating class: com.sun.media.protocol.vfw.DataSource : java.lang.RuntimeException: No permission to capture from applets
at javax.media.Manager.createPlayerForContent(Manager.java:1362)
at javax.media.Manager.createPlayer(Manager.java:417)
at javax.media.Manager.createRealizedPlayer(Manager.java:553)
at ins.filemanager.fileuploader.Camera.play(Camera.java:88)
at ins.filemanager.fileuploader.FileUploaderFrame$3.actionPerformed(FileUploaderFrame.java:124)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ins.filemanager.fileuploader.Camera.play(Camera.java:106)
at ins.filemanager.fileuploader.FileUploaderFrame$3.actionPerformed(FileUploaderFrame.java:124)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
签名的方法是参照此文章
http://my.oschina.net/zjun/blog/69
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;import javax.media.Buffer;
import javax.media.CannotRealizeException;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import javax.swing.JButton;import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;public class Camera implements ActionListener { private CaptureDeviceInfo captureDeviceInfo = null;
private MediaLocator mediaLocator = null;
private static Player player = null;
private Component imagePanel = null;
private JButton shutter;
private Buffer buffer = null;
private BufferToImage bufferToImage = null;
private Image image = null;
private Frame mainPaner = null; private int videoWidth = 0;
private int videoHeight = 0;
private int controlHeight = 30;
private int insetWidth = 10;
private int insetHeight = 30; private static Camera instanceCamera = null; public static Camera getInstance() {
if (instanceCamera == null) {
synchronized (Camera.class) {
if (instanceCamera == null) {
instanceCamera = new Camera();
}
}
}
return instanceCamera;
} public void play() {
mainPaner = new Frame("摄像头捕获");
mainPaner.setResizable(false);
mainPaner.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
if (player != null) {
player.close();
}
System.exit(0);
}
}); String str = "vfw:Microsoft WDM Image Capture (Win32):0";
captureDeviceInfo = CaptureDeviceManager.getDevice(str);
mediaLocator = new MediaLocator("vfw://0");
imagePanel = new Container();
shutter = new JButton("拍 照");
shutter.addActionListener(this);
try {
player = Manager.createRealizedPlayer(mediaLocator);
player.prefetch();
if ((imagePanel = player.getVisualComponent()) != null) {
Dimension size = imagePanel.getPreferredSize();
videoWidth = size.width;
videoHeight = size.height;
mainPaner.add(imagePanel);
} else {
videoWidth = 320;
}
player.start();
} catch (NoPlayerException e) {
e.printStackTrace();
} catch (CannotRealizeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
player.realize(); mainPaner.add(shutter, BorderLayout.SOUTH);
// 如果分辨率太小调大显示区域,如果分辨率太大,则调小显示区域
if (videoWidth < 320 || videoHeight < 240) {
mainPaner.setSize(320, 240);
} else if (videoWidth > 640 || videoHeight > 480) {
mainPaner.setSize(640, 480);
} else {
mainPaner.setSize(videoWidth + insetWidth, videoHeight + controlHeight
+ insetHeight);
}
Dimension winSize = Toolkit.getDefaultToolkit().getScreenSize(); // 屏幕分辨率
mainPaner.setLocation((winSize.width - mainPaner.getWidth()) / 2,
(winSize.height - mainPaner.getHeight()) / 2);
mainPaner.setVisible(true);
mainPaner.validate();
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == shutter) {
if (null != player && player.getState() == Player.Started) {
player.stop();
FrameGrabbingControl fgc = (FrameGrabbingControl) player
.getControl("javax.media.control.FrameGrabbingControl"); buffer = fgc.grabFrame();
bufferToImage = new BufferToImage((VideoFormat) buffer.getFormat());
image = bufferToImage.createImage(buffer);
shutter.setText("点击继续");
saveImage(image, "temp.jpg");
mainPaner.validate();
} else {
player.start();
shutter.setText("拍 照");
} }
} public void saveImage(Image image, String path) {
BufferedImage bi = new BufferedImage(image.getWidth(null),
image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(image, null, null);
FileOutputStream fos = null; try {
fos = new FileOutputStream(path); } catch (FileNotFoundException e) {
e.printStackTrace();
}
JPEGImageEncoder je = JPEGCodec.createJPEGEncoder(fos);
JPEGEncodeParam jp = je.getDefaultJPEGEncodeParam(bi);
jp.setQuality(1f, false);
je.setJPEGEncodeParam(jp);
try {
je.encode(bi);
fos.close();
} catch (ImageFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
}