我正在嘗試編寫一個可以使用節儉的基本java應用程序。我缺少的東西是一個工作的jar文件。包org.apache.thrift不存在
我已經從官方網站下載頁面下載了0.8.0 gz的節儉版本,並自行創建了jar文件(jar cf thrift-0.8.0.jar src/org
)。我已經將新的jar文件移動到我的項目目錄中。然後,我將這個jar文件手動添加到項目中 - 我正在使用NetBeans IDE。一切似乎都應該起作用,但它不會 - 在我想要使用節儉庫的任何地方都會出現紅色錯誤消息。這是一張我的代碼:
package com.blogspot.symfonyworld.thrift;
import com.blogspot.symfonyworld.thrift.server.MainService;
import org.apache.thrift.TException;
public class MainServiceHandler implements MainService.Iface {
@Override
public int add(int n1, int n2) throws TException {
return n1 + n2;
}
@Override
public int sub(int n1, int n2) throws TException {
return n1 + n2;
}
}
和其他文件:
/**
* Autogenerated by Thrift Compiler (0.8.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package com.blogspot.symfonyworld.thrift.server;
import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;
import org.apache.thrift.scheme.TupleScheme;
import org.apache.thrift.protocol.TTupleProtocol;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Set;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Collections;
import java.util.BitSet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MainService {
public interface Iface {
public int add(int n1, int n2) throws org.apache.thrift.TException;
public int sub(int n1, int n2) throws org.apache.thrift.TException;
}
public interface AsyncIface {
public void add(int n1, int n2, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.add_call> resultHandler) throws org.apache.thrift.TException;
public void sub(int n1, int n2, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.sub_call> resultHandler) throws org.apache.thrift.TException;
}
當我運行的身材,我收到以下錯誤:
ant -f /var/www/laughing-thrift-duck jar
init:
Deleting: /var/www/laughing-thrift-duck/build/built-jar.properties
deps-jar:
Updating property file: /var/www/laughing-thrift-duck/build/built-jar.properties
Compiling 2 source files to /var/www/laughing-thrift-duck/build/classes
/var/www/laughing-thrift-duck/src/com/blogspot/symfonyworld/thrift/MainServiceHandler.java:4: package org.apache.thrift does not exist
import org.apache.thrift.TException;
/var/www/laughing-thrift-duck/src/com/blogspot/symfonyworld/thrift/server/MainService.java:9: package org.apache.thrift.scheme does not exist
import org.apache.thrift.scheme.IScheme;
/var/www/laughing-thrift-duck/src/com/blogspot/symfonyworld/thrift/server/MainService.java:10: package org.apache.thrift.scheme does not exist
import org.apache.thrift.scheme.SchemeFactory;
/var/www/laughing-thrift-duck/src/com/blogspot/symfonyworld/thrift/server/MainService.java:11: package org.apache.thrift.scheme does not exist
import org.apache.thrift.scheme.StandardScheme;
/var/www/laughing-thrift-duck/src/com/blogspot/symfonyworld/thrift/server/MainService.java:13: package org.apache.thrift.scheme does not exist
import org.apache.thrift.scheme.TupleScheme;
/var/www/laughing-thrift-duck/src/com/blogspot/symfonyworld/thrift/server/MainService.java:14: package org.apache.thrift.protocol does not exist
import org.apache.thrift.protocol.TTupleProtocol;
# and many many more...
的主要問題是:包org.apache.thrift不存在 - 怎麼回事?
有人可以指點我做了什麼錯誤導入自定義jar到我的項目?我認爲這與精確節儉沒有任何關係,但是通常會導入罐子。
下載Apache Thrift並將jar放入類路徑中。如果它是一個Web應用程序,請將其放入'WEB-INF/lib'文件夾中。 – 2013-03-15 15:11:06