问题
I've managed to compile and execute Cyelon code in the 'Walkthrough' repository, by right clicking a function and choosing 'Run functionName'.
I've also tried creating my own Ceylon-project (named POSTtoFile) and seeing if I could execute a 'Hello World' function from there. I couldn't. I guess I have to create some sort of build configuration for my project, but I don't know what to fill into these form fields:
The Installing Ceylon IDE for IntelliJ guide is completely silent on this question. It would be neat if it had included a section named 'making your first Ceylon'-project. It's embarrasing to know that all previous readers of that document must have known that stuff in advance. So here I am! The single exception.
In the 'Ceylon module' drop down, there is a single option, named module default "unversioned"
. I tried choosing that one and then clicking 'Run' -> 'Run POSTtoFile'. I got this output:
"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Dceylon.system.repo=C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\repo -Didea.launcher.port=7536 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\bin" -Dfile.encoding=windows-1252 -classpath "C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\lib\ceylon-bootstrap.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.redhat.ceylon.launcher.Bootstrap run --run "" default/unversioned
ceylon run: Module default/unversioned not found in the following repositories:
C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\repo
C:\Users\Jon\Auchitect\POSTtoFile\modules
C:\Users\Jon\.ceylon\cache
https://modules.ceylon-lang.org/repo/1
[Maven] Aether
[NPM] npm
Process finished with exit code 1
EDIT:
As can be seen in the screenshot below, I have no toolbar in the bottom of the IntelliJ window, and I see no tool window named 'Ceylon problems':
As to your other questions:
- The 'modules' folder is empty
- IntelliJ seems to do work when I click
Build>Rebuild Project
. This is the output:
- These are my version numbers:
When I put the folowing code in my
main.ceylon
file:shared void hello() { print("Hello , World!"); }
(sorry, stack overflow won't format this as code, even though I have 4 spaces in front of each line)
I get the green arrow to the left of the function hello
, but then I can't click on it. It says 'Nothing here':
EDIT 2:
I tried moving the source code file (main.ceilon
) from the root directory (POSTtoFile
) to the source directory (POSTtoFile/source
).
Then I clicked Run
-> Run 'POSTtoFile'
.
This gave me the following new output:
"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Dceylon.system.repo=C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\repo -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\bin" -Dfile.encoding=windows-1252 -classpath "C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\lib\ceylon-bootstrap.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.redhat.ceylon.launcher.Bootstrap run --run "" default/unversioned
ceylon run: String index out of range: 0
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at ceylon.modules.api.runtime.AbstractRuntime.invokeRun(AbstractRuntime.java:53)
at ceylon.modules.api.runtime.AbstractRuntime.execute(AbstractRuntime.java:105)
at ceylon.modules.api.runtime.AbstractRuntime.execute(AbstractRuntime.java:101)
at ceylon.modules.Main.execute(Main.java:69)
at ceylon.modules.Main.main(Main.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.modules.Module.run(Module.java:308)
at org.jboss.modules.Main.main(Main.java:487)
at ceylon.modules.bootstrap.CeylonRunTool.run(CeylonRunTool.java:292)
at com.redhat.ceylon.common.tools.CeylonTool.run(CeylonTool.java:547)
at com.redhat.ceylon.common.tools.CeylonTool.execute(CeylonTool.java:423)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.redhat.ceylon.launcher.Launcher.runInJava7Checked(Launcher.java:108)
at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:38)
at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.redhat.ceylon.launcher.Bootstrap.runVersion(Bootstrap.java:162)
at com.redhat.ceylon.launcher.Bootstrap.runInternal(Bootstrap.java:117)
at com.redhat.ceylon.launcher.Bootstrap.run(Bootstrap.java:93)
at com.redhat.ceylon.launcher.Bootstrap.main(Bootstrap.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 2
This is the content of main.ceilon
:
shared void hello() {
print("Hello , World!");
}
EDIT 3:
After changing the content of main.ceilon
to this:
void hello() {
print("Hello, World!");
}
hello();
I get this output when doing Run
-> Run 'POSTtoFile'
:
and now all of a sudden I have the Ceylon problems
button in the bottom toolbar! It says I have three problems:
incorrect syntax: no viable alternative at token end of file.
missing declaration or argument name.
not an annotation constructor: hello
I don't understand why I get errors, though, as my code is straight out of the Tour of Ceylon.
回答1:
Agreed, the documentation lacks a "Getting started with IntelliJ" section, I'm going to fix that this week.
Here are the steps needed to run a simple project in IntelliJ.
Create a new project via File > New > Project
and choose the Ceylon
category.
Click Next
and choose whether you want to compile/run your project on the JVM, on JS or both:
Click Next
twice, enter a name for your project and click Finish
. Your project is now ready to host new Ceylon code:
In the Project view, you can see a few existing files and folders:
.ceylon
contains internal configuration that can be reused by the CLI tools, you shouldn't have to modify it directly most of the time.modules
is the output directory where Ceylon modules will be compiled.resource
contains resourcessource
contains source modules
To add Ceylon code to this project, you can either put files directly under the source
folder to add them to the default
module, or create a new module and add source files to this module. In both cases, .ceylon
files must be in the source
folder, not directly in the project folder.
- To add a file to the
default
module, right-click on thesource
folder and chooseNew > Ceylon File/Declaration
, enter a name (for examplerun
) and clickOK
. - To create a new module, right-click on the
source
folder and chooseNew > Ceylon Module
, enter a name likemy.ceylon.example
, adjust the version if you don't like1.0.0
, set the runnable unit name to something likerun
and clickOK
. New folders will be created (my/ceylon/example
), along with a module descriptor (module.ceylon
), a package descriptor (package.ceylon
) and your runnable unit (run.ceylon
).
At this point, a tool window titled Ceylon Problems
should be present in the bottom tool bar, indicating that the IDE is now aware that the project contains Ceylon code and is correctly configured:
Now that the project is set up, it's time to actually add code :). Open run.ceylon
and add the following code:
shared void run() {
print("hello");
}
A green arrow will appear in the left gutter, click on that arrow to run or debug the run
function:
Click on Run 'run'
, this will automatically create a run configuration, build the project and print hello
:
Regarding your last error:
incorrect syntax: no viable alternative at token end of file.
Just like Java and its main()
method, when you declare a runnable function in Ceylon, you don't have to actually call it manually. The Ceylon runner will do it for you (either the IDE or ceylon run
when you use the CLI). Ceylon only accepts toplevel declarations, not statements, so this code triggers a parse error when it's found at the root of a file:
hello();
This is a bit misleading if you've already tried the web IDE because the web IDE automatically wraps your code in a run
function under the hood, so the above statement would never be a toplevel statement.
来源:https://stackoverflow.com/questions/41793357/compiling-code-from-within-intellij