1

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

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.

I've found instructions on http://www.wikihow.com/Run-a-.Jar-Java-File, but they are just as confusing.

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?

Community
  • 1
  • 1
Andrei
  • 135
  • 5
  • 18
  • 1
    You don't "run" that sort of .jar file. You import it into your project and use it. Which IDE are you using for development? If you aren't using an IDE, this may help you: http://stackoverflow.com/questions/4732892/how-to-add-reference-jar-files-in-your-project-when-you-dont-have-an-ide – Ryan Nov 18 '13 at 01:47
  • @Ryan : `javac -classpath dropbox-core-sdk-1.7.5.jar Main.java` worked. `java -classpath dropbox-core-sdk-1.7.5.jar Main`, however, didn't. – Andrei Nov 18 '13 at 04:35
  • 1
    Yep, need to include the ".java" on each file you are compiling with javac. – Ryan Nov 18 '13 at 04:45
  • @Ryan : `java -classpath dropbox-core-sdk-1.7.5.jar Main.java` `Error: Could not find or load main class Main.java` – Andrei Nov 18 '13 at 04:54
  • try `java -classpath . Main` or replace `.` with where the compiler output directory is. – Ryan Nov 18 '13 at 04:59
  • @Ryan : 1st case - threw a bunch of `java.lang.Class.`... errors. 2nd case (`java -classpath '/home/owner/Desktop/courses/fall-2013/bb-cpe400/cpe400-project02' Main`) - did the same thing, a bunch of errors. – Andrei Nov 18 '13 at 05:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/41378/discussion-between-andrey-and-ryan) – Andrei Nov 18 '13 at 05:06
  • Try `java -classpath dropbox-core-sdk-1.7.5.jar Main` ...probably still needs to reference the `.jar` – Ryan Nov 18 '13 at 05:11
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/41384/discussion-between-andrey-and-ryan) – Andrei Nov 18 '13 at 06:48

1 Answers1

3

Command Line:

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:

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:

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.

Repeat the process for jackson-core-2.2.3.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)

enter image description here

// 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
    }
}
Ryan
  • 672
  • 8
  • 15
  • Ur code doesn't work as I get this exception:Exception in thread "main" com.dropbox.core.DbxException$BadRequest: {"error_description": "given \"code\" is not valid", "error": "invalid_grant"} at com.dropbox.core.DbxRequestUtil.unexpectedStatus(DbxRequestUtil.java:202) senthil – user1503117 Dec 04 '13 at 07:12
  • 1
    This code, as I mentioned at the top of my answer, is copied directly from Dropbox's website (minus the part where they didn't escape the quotation marks in the one string). It compiles fine, but I can't comment on it's functionality, as I haven't used it personally. It is simply sample code they have provided to get you started. Although, if I were to take any guesses upon seeing that exception, I'd say the authorization code you entered is invalid. – Ryan Dec 04 '13 at 12:21