使用v4l4j的外部jar的javac编译器问题
我试图在我的Raspberry Pi上用java编译一个程序,但我无法让java(或java)程序链接外部库,特别是v4l4j库。我可以编译和执行一个简单的java程序,没有问题,但现在我正在尝试链接v4l4j下载的/lib文件夹中的.jar文件 我正在使用make编译和运行我的代码,这就是我的Makefile的样子使用v4l4j的外部jar的javac编译器问题,java,javac,v4l,Java,Javac,V4l,我试图在我的Raspberry Pi上用java编译一个程序,但我无法让java(或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/jun
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文件。您能在eclipse/netbeans中构建/运行项目吗?您能展示您的SimpleViewer.java吗这意味着什么?你能给我举个例子吗?假设你的所有JAR都在/home/pi/java/v4l4j-0.9.0/lib位置,你可以试试javac-classpath/home/pi/java/v4l4j-0.9.0/lib/*SimpleViewer.java,它给了我一个错误,最后一部分lib的“无效标志”/*你的lib文件夹中有多少个JAR。试着用手指分开你所有的罐子;(分号)ex:-/home/pi/java/v4l4j-0.9.0/lib/myfirst.jar/home/pi/java/v4l4j-0.9.0/lib/mysecond.jar。。。。。。