- This topic has 12 replies, 2 voices, and was last updated 5 years, 9 months ago by support-swapna.
-
AuthorPosts
-
jjones7947ParticipantHow is this import done in version 218.12?
support-swapnaModeratorJim,
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
jjones7947ParticipantThis 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
support-swapnaModeratorJim,
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 SupportAttachments:
You must be logged in to view attached files.
jjones7947ParticipantThis 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 typeat noobchain/noobchain.NoobChain.main(NoobChain.java:19)
jjones7947ParticipantThis 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 typeat 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);
}
}
support-swapnaModeratorJim,
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
jjones7947ParticipantAttached zip of project
Attachments:
You must be logged in to view attached files.
support-swapnaModeratorJim,
Thank you for the project files. We will check and get back to you soon.
–Swapna
Genuitec Support
jjones7947ParticipantDiscovered that the Referenced Libraries direectory shows up in the IDE but not in the cmd console or windows explorer
support-swapnaModeratorJim,
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
jjones7947ParticipantName 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 fileWhen run, I get:
Exception in thread “main” java.lang.NoClassDefFoundError: java/sql/Time
at [email protected]/com.google.gson.Gson.<init>(Gson.java:250)
at [email protected]/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
support-swapnaModeratorJim,
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 -
AuthorPosts