我有一个 dropbox-core-sdk-1.7.5.jar 归档文件。我尝试将它作为一个包安装在我的主目录中:
java -jar dropbox-core-sdk-1.7.5.jar
但终端吐出:“没有主要 list 属性,在 dropbox-core-sdk-1.7.5.jar 中”。跟帖 Can't execute jar- file: "no main manifest attribute"建议我需要添加一行类似于“Main-Class: com.mypackage.MyClass”的 META-INF/MANIFEST.MF 文件。但是我不知道我应该输入什么类。
我在 http://www.wikihow.com/Run-a-.Jar-Java-File 上找到了说明, 但它们同样令人困惑。
有人可以向我解释我应该如何处理这个不可执行的 jar 文件,以便让机器知道这个包的存在吗?
最佳答案
命令行:
如果您尝试在没有 IDE 的情况下构建它并且正在使用 Dropbox Site 中包含的 Main.java 文件...
// Include the Dropbox SDK.
import com.dropbox.core.*;
import java.io.*;
import java.util.Locale;
public class Main
{
public static void main(String[] args) throws IOException, DbxException
{
// Get your app key and secret from the Dropbox developers website.
final String APP_KEY = "INSERT_APP_KEY";
final String APP_SECRET = "INSERT_APP_SECRET";
DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
Locale.getDefault().toString());
DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
// Have the user sign in and authorize your app.
String authorizeUrl = webAuth.start();
System.out.println("1. Go to: " + authorizeUrl);
System.out.println("2. Click \"Allow\" (you might have to log in first)");
System.out.println("3. Copy the authorization code.");
String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
// This will fail if the user enters an invalid authorization code.
DbxAuthFinish authFinish = webAuth.finish(code);
DbxClient client = new DbxClient(config, authFinish.accessToken);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
File inputFile = new File("working-draft.txt");
FileInputStream inputStream = new FileInputStream(inputFile);
try
{
DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
DbxWriteMode.add(), inputFile.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
}
finally
{
inputStream.close();
}
DbxEntry.WithChildren listing = client.getMetadataWithChildren("/");
System.out.println("Files in the root path:");
for (DbxEntry child : listing.children)
{
System.out.println(" " + child.name + ": " + child.toString());
}
FileOutputStream outputStream = new FileOutputStream("magnum-opus.txt");
try
{
DbxEntry.File downloadedFile = client.getFile("/magnum-opus.txt", null,
outputStream);
System.out.println("Metadata: " + downloadedFile.toString());
}
finally
{
outputStream.close();
}
}
}
在相应目录的终端中使用这些命令行:
编译:javac -cp dropbox-core-sdk-1.7.5.jar Main.java
运行:java -cp .;dropbox-core-sdk-1.7.5.jar;jackson-core-2.2.3.jar Main
(使用 :
而不是 ;
用于类 Unix 操作系统)
Eclipse 集成开发环境:
如果您使用的是 Eclipse
IDE,您只需将 dropbox-core-sdk-1.7.5.jar
文件复制到您的项目中,右键单击它,然后选择菜单选项 Build Path -> Add to Build Path
。然后,它应该会出现在 Package Explorer
窗口的 Referenced Libraries
文件夹中,然后您就可以导入和使用它了。
对 jackson-core-2.2.3.jar
重复该过程。
如果您愿意,此链接包含将 .jar
文件添加到项目的一般过程的多个分步图像:http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)
// Import whatever you want from the Dropbox SDK...
import com.dropbox.*; // everything
import com.dropbox.core.*;
import com.dropbox.core.http.*;
import com.dropbox.core.json.*;
import com.dropbox.core.util.*;
public class Test
{
public static void main(String[] args)
{
// Do stuff
}
}
关于java - 没有IDE无法安装jar包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20037741/