facebook

Import of External Jars/Libraries

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #609435 Reply

    jjones7947
    Participant

    How is this import done in version 218.12?

    #609437 Reply

    support-swapna
    Moderator

    Jim,

    Welcome back 🙂

    For normal Web/Java projects, you can add it to the project’s Build Path page, in the Libraries tab (click on the Add External JARs button).

    If you are looking for a different case, then please share with us more details about the type/kind of project, the jars/libraries you are trying to import to help us assist you further.

    –Swapna
    Genuitec Support

    #609520 Reply

    jjones7947
    Participant

    This is the tutorial I aam trying to do: “https://medium.com/programmers-blockchain/create-simple-blockchain-java-tutorial-from-scratch-6eeed3cb03fa”
    When I follow the directions in the tutorial for importing gson I get an error that the GsonBuilder cannot be found

    #609528 Reply

    support-swapna
    Moderator

    Jim,

    For a java project, you have to add the said jar to the Classpath section in the Libraries tab.
    Please see the attached screenshot for your reference. I assume you have already downloaded the gson-2.6.2.jar as mentioned in the tutorial you pointed.

    Select the Classpath entry in the Libraries tab and the button to add external jar will be enabled, then browse to the downloaded gson-2.6.2.jar to add it. Apply and close should make the error go away.

    Hope this helps. Please let us know how it works for you.

    –Swapna
    Genuitec Support

    Attachments:
    You must be logged in to view attached files.
    #609551 Reply

    jjones7947
    Participant

    This puts the jar into a directory called Referenced Libraries, but I still have a red underline indicating error and if I run it anyway the error is:
    Exception in thread “main” java.lang.Error: Unresolved compilation problem:
    GsonBuilder cannot be resolved to a type

    at noobchain/noobchain.NoobChain.main(NoobChain.java:19)

    #609552 Reply

    jjones7947
    Participant

    This puts the jar into a directory called Referenced Libraries, but I still have a red underline indicating error and if I run it anyway the error is:
    Exception in thread “main” java.lang.Error: Unresolved compilation problem:
    GsonBuilder cannot be resolved to a type

    at noobchain/noobchain.NoobChain.main(NoobChain.java:19)

    package noobchain;

    import java.util.ArrayList;
    import com.google.gson.GsonBuilder;

    public class NoobChain {

    public static void main(String[] args) {

    Block genesisBlock = new Block(“Hi im the first block”, “0”);
    System.out.println(“Hash for block 1 : ” + genesisBlock.hash);

    Block secondBlock = new Block(“Yo im the second block”,genesisBlock.hash);
    System.out.println(“Hash for block 2 : ” + secondBlock.hash);

    Block thirdBlock = new Block(“Hey im the third block”,secondBlock.hash);
    System.out.println(“Hash for block 3 : ” + thirdBlock.hash);

    String blockchainJson = new GsonBuilder().setPrettyPrinting().create().toJson(genesisBlock);
    System.out.println(blockchainJson);
    }
    }

    #609555 Reply

    support-swapna
    Moderator

    Jim,

    Sorry that you are still seeing the problem.

    Can you please share with us the screenshot of the editor (showing the error on import) along with the project structure in the MyEclipse Project Explorer view to help us get a visual? If possible, please share with us the zipped project to help us replicate the error at our end.

    –Swapna
    Genuitec Support

    #609561 Reply

    jjones7947
    Participant

    Attached zip of project

    Attachments:
    You must be logged in to view attached files.
    #609564 Reply

    support-swapna
    Moderator

    Jim,

    Thank you for the project files. We will check and get back to you soon.

    –Swapna
    Genuitec Support

    #609568 Reply

    jjones7947
    Participant

    Discovered that the Referenced Libraries direectory shows up in the IDE but not in the cmd console or windows explorer

    #609594 Reply

    support-swapna
    Moderator

    Jim,

    Your project has module-info.java file which is introduced from Java 9 onwards.
    Please read these for more details about modules :
    https://www.oracle.com/corporate/features/understanding-java-9-modules.html
    http://www.codenuclear.com/module-directives-in-java-9/

    If there is a module-info.java file in the project, then you need to add the jar to the Modulepath section in the Libraries tab instead of Classpath and then declare the module dependencies in the file. For this case of gson jar, this is how the module-info.java file should look :

    module noobchain {
       requires gson;
    }

    Please make the changes accordingly and let us know how it works.

    –Swapna
    Genuitec Support

    #609599 Reply

    jjones7947
    Participant

    Name of automatic module ‘gson’ is unstable, it is derived from the module’s file name.
    The above warning is shown on line 9 of the moddule-info.java file

    When run, I get:
    Exception in thread “main” java.lang.NoClassDefFoundError: java/sql/Time
    at gson@2.6.2/com.google.gson.Gson.<init>(Gson.java:250)
    at gson@2.6.2/com.google.gson.GsonBuilder.create(GsonBuilder.java:568)
    at noobchain/noobchain.NoobChain.main(NoobChain.java:16)
    Caused by: java.lang.ClassNotFoundException: java.sql.Time
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    … 3 more

    #609647 Reply

    support-swapna
    Moderator

    Jim,

    On further investigation, it looks like the problem is with the gson jar which is not modular and so there is a warning for it in the module-info.java. Please see similar report for gson jar : https://stackoverflow.com/questions/51479742/modular-jar-of-gson
    The fix should be available when gson-2.8.6.jar releases.

    Now since this particular dependency (gson jar) is not modularized, I suggest you delete the module-info.java file from the project and add the gson jar to the Classpath section for MyEclipse to pick it up during compiling and running of your project.

    Hope this helps. Please let us know if you still see issues.

    –Swapna
    Genuitec Support

Viewing 13 posts - 1 through 13 (of 13 total)
Reply To: Import of External Jars/Libraries

You must be logged in to post in the forum log in