如果没有IDE,则无法安装jar包 [英] Cannot install a jar package without an IDE
问题描述
我有一个dropbox-core-sdk-1.7.5.jar存档文件.我尝试使用
I have a dropbox-core-sdk-1.7.5.jar archive file. I tried to install it as a package in my Home directory with:
java -jar dropbox-core-sdk-1.7.5.jar
java -jar dropbox-core-sdk-1.7.5.jar
但是终端弹出:在dropbox-core-sdk-1.7.5.jar中没有主清单属性".线程无法执行jar文件:无主清单属性" ; 建议我需要添加类似于"Main-Class:com.mypackage.MyClass" META-INF/MANIFEST.MF文件的行.但是我不知道我应该输入什么课程.
but the terminal spits out: "no main manifest attribute, in dropbox-core-sdk-1.7.5.jar". The thread Can't execute jar- file: "no main manifest attribute" suggests that I need to add a line similar to "Main-Class: com.mypackage.MyClass" META-INF/MANIFEST.MF file. But I don't know what class I'm supposed to type in.
我在 http://www.wikihow上找到了说明. com/Run-a-.Jar-Java-File ,但它们同样令人困惑.
I've found instructions on http://www.wikihow.com/Run-a-.Jar-Java-File, but they are just as confusing.
有人可以向我解释这个不可执行的jar文件应该怎么做,以便我可以让机器知道该软件包存在吗?
Can someone explain to me what I should do about this non-executable jar file so that I could let the machine know that this package exists?
推荐答案
命令行:
If you are trying to build it without an IDE and are using the Main.java file included on the Dropbox Site...
// 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();
}
}
}
在相应目录的终端中使用以下命令行:
Use these command lines in a terminal from the appropriate directory:
要编译: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的操作系统,使用:
代替;
)
To Compile: javac -cp dropbox-core-sdk-1.7.5.jar Main.java
To Run: java -cp .;dropbox-core-sdk-1.7.5.jar;jackson-core-2.2.3.jar Main
(use :
instead of ;
for Unix-like operating systems)
Eclipse IDE:
如果使用的是Eclipse
IDE,则只需将dropbox-core-sdk-1.7.5.jar
文件复制到项目中,右键单击它,然后选择菜单选项Build Path -> Add to Build Path
.然后,它应该出现在Package Explorer
窗口的Referenced Libraries
文件夹中,然后您就可以导入和使用它了.
If you are using the Eclipse
IDE, you can simply copy the dropbox-core-sdk-1.7.5.jar
file into your project, right click on it, and select the menu option Build Path -> Add to Build Path
. It should then appear in your Referenced Libraries
folder in the Package Explorer
window, and then you should be able to import and use it.
重复jackson-core-2.2.3.jar
的过程.
如果您愿意,此链接包含将.jar
文件添加到项目的一般过程的多个分步图像:
This link has multiple step by step images of the general process of adding a .jar
file to your project if you prefer: 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
}
}
这篇关于如果没有IDE,则无法安装jar包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!