Closed djm34 closed 3 years ago
Hey @djm34,
I see you are trying out the examples repository 💪
So, the CompileAndDeploy
class is not a smart contract that can be compiled with the neow3jCompile
Gradle task. CompileAndDeploy.java is a file that shows how to use the neow3j SDK for compiling and deploying a smart contract. Inside of the file you will find the following line:
CompilationUnit res = new Compiler().compileClass(BongoCatToken.class.getCanonicalName());
This is where the neow3j compiler is invoked and compiles the BongoCatToken
which you can find in the io.neow3j.examples.contractdev.contracts
package.
If you want to compile a contract with the neow3jCompile
Gradle task, you need to use one of the contracts in the io.neow3j.examples.contractdev.contracts
package.
I should make it clear that not every Java class can be compiled to a Neo contract. The class has to adhere to some rules to be compatible with the neo-vm. The Java Virtual Machine (JVM) and the neo-vm are quite different and writing Java classes for the neo-vm has some limitations compared to normal classes for the JVM. If you want to write smart contracts in Java check out this documentation.
Hi @csmuller , ok, but how do I run CompileAndDeploy.java exactly ? Thanks for your help
I tried before: java -cp build/libs/examples-1.0-SNAPSHOT-all.jar io.neow3j.examples.contractdev.CompileAndDeploy
but got that error: Error: Could not find or load main class io.neow3j.examples.contractdev.CompileAndDeploy Caused by: java.lang.ClassNotFoundException: io.neow3j.examples.contractdev.CompileAndDeploy
(same trying the example in readme file with CreateKeyPair actually)
@djm34
Ok, I get your point. You want to execute the examples in the command line, without setting up an IDE or anything like this.
If you would like to run directly with the vanilla java -cp
command, you can, of course, but then you will need to set-up the classpath of all dependencies (JARs), etc. We don't generate a fat JAR with all dependencies. We prefer to use Gradle and let it manage everything for us.
In this case, we just recently committed something that will help you do accomplish what you want: run the examples in the command line.
You can do a git pull
to get the latest version of this (examples) repository and take a look in the README file in the neo3-examples
folder. There's a section called "Run the Examples in the Command Line". There you can find the exact command to run the CompileAndDeploy
from the command line.
Let us know if you manage to run it. 😄
great thanks a lot :)
@djm34 did it work?
If not, feel free to re-open this issue. 😄
Hello,
I have been trying to run the class io.neow3j.examples.contractdev.CompileAndDeploy with through
neow3jCompiler
Gradle task But it fails with this error:Thanks for your help, djm34