Javac编译器与外部JAR使用V4L4J发行



我试图在我的Raspberry Pi上编译Java中的程序,但是我无法接缝以获取Javac(或Java)程序来链接外部库,专门链接V4L4J库。我可以编译和执行一个简单的Java程序,没问题,但是现在我试图链接V4L4J下载的/lib文件夹中的.jar文件。

我正在使用 make 来编译和运行我的代码,这就是我的 makefile 看起来像...

all:  
   /home/pi/java/jdk1.7.0_06/bin/javac -classpath /home/pi/java/v4l4j-0.9.0/lib/junit-4.1.jar SimpleViewer.java  
   /home/pi/java/jdk1.7.0_06/bin/java SimpleViewer

基本上是两行,一条编译,然后是执行。请注意,我没有更改我的班级路径,这就是为什么每行的第一部分链接到Java编译器的直接位置的原因。

当我在命令行中运行 make 时,我会发现

的错误
SimpleViewer.java:10: error: package au.edu/jcu/v4l4j does not exist import au.edu/jcu.v4l4j.FrameGrabber;

我实际上会遇到很多这样的错误。有任何想法吗?谢谢。

这是SimpleViewer类

package v4l4jTest;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import au.edu.jcu.v4l4j.FrameGrabber;
import au.edu.jcu.v4l4j.CaptureCallback;
import au.edu.jcu.v4l4j.V4L4JConstants;
import au.edu.jcu.v4l4j.VideoDevice;
import au.edu.jcu.v4l4j.VideoFrame;
import au.edu.jcu.v4l4j.exceptions.StateException;
import au.edu.jcu.v4l4j.exceptions.V4L4JException;
/**
 * This class demonstrates how to perform a simple push-mode capture.
 * It starts the capture and display the video stream in a JLabel
 * @author gilles
 *
 */
public class SimpleViewer extends WindowAdapter implements CaptureCallback{
        private static int      width = 640, height = 480, std = V4L4JConstants.STANDARD_WEBCAM, channel = 0;
        private static String   device = "/dev/video0";
        private VideoDevice     videoDevice;
        private FrameGrabber    frameGrabber;
        private JLabel          label;
        private JFrame          frame;

        public static void main(String args[]){
                SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                                new SimpleViewer();
                        }
                });
        }
        /**
         * Builds a WebcamViewer object
         * @throws V4L4JException if any parameter if invalid
         */
        public SimpleViewer(){
                // Initialise video device and frame grabber
                try {
                        initFrameGrabber();
                } catch (V4L4JException e1) {
                        System.err.println("Error setting up capture");
                        e1.printStackTrace();
                        // cleanup and exit
                        cleanupCapture();
                        return;
                }
                // create and initialise UI
                initGUI();
                // start capture
                try {
                        frameGrabber.startCapture();
                } catch (V4L4JException e){
                        System.err.println("Error starting the capture");
                        e.printStackTrace();
                }
        }
        /**
         * Initialises the FrameGrabber object
         * @throws V4L4JException if any parameter if invalid
         */
        private void initFrameGrabber() throws V4L4JException{
                videoDevice = new VideoDevice(device);
                frameGrabber = videoDevice.getJPEGFrameGrabber(width, height, channel, std, 80);
                frameGrabber.setCaptureCallback(this);
                width = frameGrabber.getWidth();
                height = frameGrabber.getHeight();
                System.out.println("Starting capture at "+width+"x"+height);
        }
        /** 
         * Creates the UI components and initialises them
         */
        private void initGUI(){
                frame = new JFrame();
                label = new JLabel();
                frame.getContentPane().add(label);
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.addWindowListener(this);
                frame.setVisible(true);
                frame.setSize(width, height);       
        }
        /**
         * this method stops the capture and releases the frame grabber and video device
         */
        private void cleanupCapture() {
                try {
                        frameGrabber.stopCapture();
                } catch (StateException ex) {
                        // the frame grabber may be already stopped, so we just ignore
                        // any exception and simply continue.
                }
                // release the frame grabber and video device
                videoDevice.releaseFrameGrabber();
                videoDevice.release();
        }
        /**
         * Catch window closing event so we can free up resources before exiting
         * @param e
         */
        public void windowClosing(WindowEvent e) {
                cleanupCapture();
                // close window
                frame.dispose();            
        }

        @Override
        public void exceptionReceived(V4L4JException e) {
                // This method is called by v4l4j if an exception
                // occurs while waiting for a new frame to be ready.
                // The exception is available through e.getCause()
                e.printStackTrace();
        }
        @Override
        public void nextFrame(VideoFrame frame) {
                // This method is called when a new frame is ready.
                // Don't forget to recycle it when done dealing with the frame.
                // draw the new frame onto the JLabel
                label.getGraphics().drawImage(frame.getBufferedImage(), 0, 0, width, height, null);
                // recycle the frame
                frame.recycle();
        }
}

您的类路径只有

/home/pi/java/v4l4j-0.9.0/lib/junit-4.1.jar

您必须在类路径中添加其他依赖关系JAR文件。

最新更新