2017-01-22 113 views
1

我已经成功编译并执行了'Walkthrough' repository中的Cyelon代码,方法是右键单击一个函数并选择'Run functionName'。从IntelliJ编译代码

我也尝试创建自己的Ceylon项目(名为POSTtoFile),并看看我是否可以从那里执行'Hello World'功能。我不能。我想我必须建立某种形式的生成配置我的项目,但我不知道是什么填补到这些表单字段:

enter image description here

Installing Ceylon IDE for IntelliJ指南是在这个问题上完全沉默。如果它包含一个名为“制作您的第一个锡兰”项目的部分,那将会很整洁。知道该文档的所有以前的读者必须事先知道这些信息是令人不安的。所以我就在这里!唯一的例外。

在“锡兰模块”下拉菜单中,有一个选项,名称为module default "unversioned"。我尝试选择一个,然后点击'运行' - >'运行POSTtoFile'。我得到这个输出:

"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 

编辑:

如可以在下面的截图中可以看出,我在的IntelliJ窗口的底部没有工具栏,我看没有名为工具窗口“锡兰问题” :

enter image description here

至于你的其他问题:

  • ŧ他'模块'文件夹是空的
  • IntelliJ似乎工作,当我点击Build>Rebuild Project。这是输出:

enter image description here

  • 这是我的版本号:

enter image description here

  • 当我把如下因素代码在我main.ceylon文件:

    shared void hello(){ print(“Hello,World!”); }

(对不起,堆栈溢出不会格式化此为代码,即使我有4位中的每一行的前面)

我得到的绿色箭头功能hello左,但后来我无法点击它。它说, '这里没有什么':

enter image description here

编辑2: 我试图移动从根目录(POSTtoFile)源目录(POSTtoFile/source)的源代码文件(main.ceilon)。 然后我点击Run - >Run 'POSTtoFile'

这给了我以下新的输出:

"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 

这是main.ceilon内容:

shared void hello() { 
    print("Hello , World!"); 
} 

编辑3:

main.ceilon的内容改变之后:

void hello() { 
    print("Hello, World!"); 
} 

hello(); 

我做Run时,得到如下的输出 - >Run 'POSTtoFile'

enter image description here

现在突然我有底部工具栏上的按钮Ceylon problems!它说我有三个问题:

incorrect syntax: no viable alternative at token end of file. 
missing declaration or argument name. 
not an annotation constructor: hello 

我不明白为什么我得到的错误,虽然,因为我的代码是直接从Tour of Ceylon的。

+0

有几个问题可以帮助我找出发生了什么:您是否在底部工具栏中看到一个名为“锡兰问题”的工具窗口?如果是,这意味着锡兰在您的项目中正确配置。你在'modules'目录中看到什么了吗? (它应该被标记为输出目录)。如果您执行“生成”>“重建项目”,是否有任何更改?你使用的是什么版本的IntelliJ和Ceylon IDE? –

+0

如果一切配置都正确,一旦你创建了一个文件,并在其中放置了一个没有参数的“共享”顶级函数,左边就会出现一个绿色的箭头。您可以使用它来自动构建和运行代码。 –

+0

@BastienJansen我更新了我的问题并回答了您的问题。感谢您的帮助:) – loldrup

回答

3

同意,文档缺少“IntelliJ入门”部分,本周我将解决这个问题。

以下是在IntelliJ中运行简单项目所需的步骤。

通过File > New > Project创建一个新项目并选择Ceylon类别。

New Ceylon project

点击Next,并选择是否要编译/运行在JVM上项目,上JS或两个:

Ceylon project wizard: choose target platforms

点击Next两次,输入项目名称并点击Finish。您的项目现在已准备好举办新锡兰代码:

Project structure

在项目视图中,可以看到一些现有的文件和文件夹:

  • .ceylon包含可被重复使用内部配置CLI工具,你不应该直接修改它的大部分时间。
  • modules是Ceylon模块将被编译的输出目录。
  • resource包含resources
  • source包含source modules

锡兰代码添加到这个项目中,你可以把文件直接下source文件夹,将其添加到default模块,或创建一个新的模块和将源文件添加到此模块。在这两种情况下,.ceylon文件必须位于source文件夹中,而不是直接位于项目文件夹中。

  • 将文件添加到default模块,在source文件夹右键单击并选择New > Ceylon File/Declaration,输入一个名称(例如run),然后单击OK
  • 要创建一个新的模块,在source文件夹右键单击并选择New > Ceylon Module,输入一个名称,如my.ceylon.example,调整版本,如果你不喜欢1.0.0,设置可运行的单位名称为类似run并单击OK。将创建新文件夹(my/ceylon/example)以及模块描述符(module.ceylon),程序包描述符(package.ceylon)和可运行单元(run.ceylon)。

在这一点上,标题为Ceylon Problems工具窗口应该出现在底部的工具栏,表明IDE现在已了解,该项目包含锡兰代码和配置是否正确:

Ceylon Problems view

现在该项目已经建立,是时候添加代码:)。打开run.ceylon并添加以下代码:

shared void run() { 
    print("hello"); 
} 

的绿色箭头将出现在左排水沟,点击该箭头运行或调试run功能:

Run Ceylon function

点击Run 'run',这会自动创建运行配置,生成项目并打印hello

Running the file prints 'hello'

关于你的最后一个错误:

incorrect syntax: no viable alternative at token end of file.

就像Java和其main()方法,当你声明在锡兰可运行功能,您不必手动实际调用它。 Ceylon跑步者会为你做(IDE或ceylon run当你使用CLI)。锡兰只接受顶级声明,没有报表,所以这段代码触发解析错误,当它在一个文件的根的发现:

hello(); 

这是一个有点误导,如果你已经尝试了web IDE因为web IDE会自动将你的代码放在run函数的底层,所以上面的语句永远不会是顶级语句。

+0

现在,它的工作,但只有当我明确运行hello函数。如果我只是运行 - >运行 - > POSTtoFile,我会得到这个长的错误信息,你可以在我的帖子上面看到。 因此,如果我没有任何模块,那么我如何为我的项目或我的main.ceylon文件指定一个“可运行的单元名称”? – loldrup

+0

找到它:) 它的Runnable声明在运行 - >'构建配置'窗口中 – loldrup