Error opening jar on command line

Asked

Viewed 244 times

2

I have the following code and am using a library to list the citizen card fields.

When I try to run in the DOS it doesn’t work.

import java.io.*;
import pteidlib.*;
public class main {

        public String nome;
        public String data;
        public String pais;
        public String sexo;


        static
          {
            try
            {

                System.loadLibrary("pteidlibj");


            }
            catch (UnsatisfiedLinkError e)
            {
              System.err.println("Native code library failed to load.\n" + e);
              System.exit(1);
            }
          }


        public void PrintIDData(PTEID_ID idData) throws FileNotFoundException, UnsupportedEncodingException
          {
                nome = idData.firstname + " " + idData.name ;
                data =  idData.birthDate;
                pais = idData.country;
                sexo = idData.sex;
                    PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");

           writer.println(nome);   
            writer.println(data);
            writer.close();
                System.out.print(nome);
          }


    public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, PteidException{
              main  test = new main();

           pteid.Init("");
      //test.TestChangeAddress();
        // Don't check the integrity of the ID, address and photo (!)
      pteid.SetSODChecking(false);

      int cardtype = pteid.GetCardType();
      switch (cardtype)
      {
          case pteid.CARD_TYPE_IAS07:
              System.out.println("IAS 0.7 card\n");
              break;
          case pteid.CARD_TYPE_IAS101:
              System.out.println("IAS 1.0.1 card\n");
              break;
          case pteid.CARD_TYPE_ERR:
              System.out.println("Unable to get the card type\n");
              break;
          default:
              System.out.println("Unknown card type\n");
      }

      // Read ID Data
      PTEID_ID idData = pteid.GetID();
      if (null != idData)
      {
        test.PrintIDData(idData);
      }


}
}

I need to run this on the command line java -cp test.jar main and then being called on the command line gives me this error:

inserir a descrição da imagem aqui

  • To execute a jar per command line is java -jar seujar.jar .

  • And what is the relative path of your external library?

  • My path to the outer bilbiotace is in the C:\

  • @user2964140 did not take a test here, but I believe that if you do java -jar test.jar -cp .;c:\ will work

  • Give me this error in the main manifest attribute,in test.jar

  • I can take the jar generated by my code and put it in c:\ ?

  • test there ...only print if you have a citizen card

  • does not work with this command...

Show 3 more comments

1 answer

2

Adding to the @user2964140 response, and assuming the library is in c: as you said, the command to execute should be:

java -cp .;c:\suabiblioteca.jar -jar test.jar

This response assumes that your test.jar jar jar was done correctly (i.e., it includes a MANIFEST.MF with the header that speaks which class contains your method public static void main(String args[]).
If this is not the case, it is advisable to read the Oracle tutorials on how to create jars and manifest files.

One last suggestion is to include your library in the directory lib/ inside your jar, so that your application contains everything you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.