Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala script error #65

Closed
SaschaSchmidt opened this issue Oct 23, 2013 · 16 comments
Closed

Scala script error #65

SaschaSchmidt opened this issue Oct 23, 2013 · 16 comments
Assignees
Labels
Milestone

Comments

@SaschaSchmidt
Copy link
Contributor

Can't start scala script with newest master. I tried running this code with "vertx run Server.scala":

import org.vertx.scala.core.net.NetSocket
import org.vertx.scala.core.streams.Pump

vertx.createNetServer().connectHandler({ socket: NetSocket =>
    Pump.createPump(socket, socket).start
}).listen(1234)

and got this error:

Try running file:/D:/FH/_Campudus_Praktika/Server.scala as script
<console>:7: error: object scala is not a member of package org.vertx
       import org.vertx.scala._, org.vertx.scala.core._, org.vertx.scala.core.http._
                        ^
<console>:7: error: object scala is not a member of package org.vertx
       import org.vertx.scala._, org.vertx.scala.core._, org.vertx.scala.core.http._
                                           ^
<console>:7: error: object scala is not a member of package org.vertx
       import org.vertx.scala._, org.vertx.scala.core._, org.vertx.scala.core.http._
                                                                   ^
Not a script, try running file:/D:/FH/_Campudus_Praktika/Server.scala as class
D:\FH\_Campudus_Praktika\Server.scala:4: error: expected class or object definition
vertx.createNetServer().connectHandler({ socket: NetSocket =>
^
@Narigo
Copy link
Member

Narigo commented Oct 23, 2013

I get the same error - we both added the entries for scala in langs.properties in Vert.x 2.0.2-final. @galderz can you please have a look at this? Seems like running scripts doesn't really work when using vertx run X ?

@galderz
Copy link
Contributor

galderz commented Oct 23, 2013

If you're trying to use latest master, you have to build mod-lang-scala jars locally and copy them over to you have to copy over the jar files. These are the instructions I use (adjust to your own env) when testing scripts with snapshot releases I build locally.

@Narigo
Copy link
Member

Narigo commented Oct 23, 2013

Okay, so after doing this:

./gradlew install
vertx install io.vertx~lang-scala~0.2.0-SNAPSHOT

I don't have the jar files of mod-lang-scala inside its own module dir in sys-mods, even though the .class files are available directly in the module directory (not in lib/ as jars).

So putting these .class files into a jar and adding those into the modules lib directory seems to do the trick.

Why is that? Is this a general Vert.x issue, that it needs the language modules in a really strange format and cannot do that itself on install? Do we have to change something in the gradle build?

Will users have to do this themselves when they try to run Scala code?

@purplefox
Copy link
Member

You shouldn't have to copy anything manually - perhaps you're not building mod-lang-scala properly with the jar files in it's lib directory?

@Narigo
Copy link
Member

Narigo commented Oct 24, 2013

@purplefox we have the following structure in the module:

lib/
  + scala-library.jar
  + scala-compiler.jar
  + scala-reflect.jar
org/vertx/scala/
  + All the class files in their respective package...
mod.json

It looks like we need to have all the org/vertx/scala/<class-files> in a .jar and put that inside the lib/ directory as well, otherwise it won't work. That's strange that it somehow doesn't use the class files directly. Just tried a JS Script which downloaded lang-rhino and a Groovy Script with lang-groovy: Their modules have the same structure and do not need their class-files (or js scripts) in a jar lying in <mod-name>/lib/<classes-jar>. So something still is wrong with the Scala module and we shouldn't need to copy anything around in it... Guess the interpreter somehow gets the wrong ClassLoader so it doesn't have org.vertx.scala.* available? Or that regex stuff which adds the *.jar files should add the module directory itself, too?

@purplefox
Copy link
Member

Most probably you have a classloader issue in the mod-lang-scala module. Did you implement the recommendation I made last time about removing the second classloader that was being specifically used for scripts?

@Narigo
Copy link
Member

Narigo commented Oct 24, 2013

Looks like it doesn't have a second class loader anymore. @galderz knows more about the implementation now...

@purplefox
Copy link
Member

This line looks suspicious to me:

https://github.com/vert-x/mod-lang-scala/blob/master/src/main/scala/org/vertx/scala/lang/ScalaInterpreter.scala#L28

Does this mean it's setting the context class loader to null?

@purplefox
Copy link
Member

Looks like this assembles the classpath for the interpreter:

https://github.com/vert-x/mod-lang-scala/blob/master/src/main/scala/org/vertx/scala/platform/impl/ScalaVerticleFactory.scala#L126

But it looks strange to me, can't the interpreter just load resources from the context classloader? It seems odd to have to construct it this way...

@raniejade
Copy link
Contributor

As far as I know you cant, you have to explicitly set the interpreter's
classpath.

On Thu, Oct 24, 2013 at 7:19 PM, Tim Fox notifications@github.com wrote:

Looks like this assembles the classpath for the interpreter:

https://github.com/vert-x/mod-lang-scala/blob/master/src/main/scala/org/vertx/scala/platform/impl/ScalaVerticleFactory.scala#L126

But it looks strange to me, can't the interpreter just load resources from
the context classloader? It seems odd to have to construct it this way...


Reply to this email directly or view it on GitHubhttps://github.com//issues/65#issuecomment-26974153
.

Ranie Jade Ramiso
Software Engineer | Open Source Enthusiast | Professional Slacker
Philippines

w: raniejaderamiso.com
e: raniejaderamiso@gmail.com

@galderz
Copy link
Contributor

galderz commented Oct 25, 2013

Guys, leave this with me and I'll sort it out :)

@ghost ghost assigned galderz Oct 25, 2013
galderz added a commit to galderz/mod-lang-scala that referenced this issue Oct 25, 2013
… factory

* Fixed resolution of class name as well.
* Added clearer messages of what the Scala verticle factory tries to do
and hide away scripting errors.
galderz added a commit to galderz/mod-lang-scala that referenced this issue Oct 25, 2013
… factory

* Fixed resolution of class name as well.
* Added clearer messages of what the Scala verticle factory tries to do
and hide away scripting errors.
@galderz
Copy link
Contributor

galderz commented Oct 25, 2013

My fault guys, I messed it up when I refactored the ScalaVerticleFactory to split the interpreter out. PR coming right up...

galderz added a commit that referenced this issue Oct 30, 2013
* Fixed resolution of class name as well.
* Added clearer messages of what the Scala verticle factory tries to do
and hide away scripting errors.
@galderz galderz closed this as completed Oct 30, 2013
@galderz galderz reopened this Nov 7, 2013
@galderz
Copy link
Contributor

galderz commented Nov 7, 2013

This is very weird. While trying to verify fix for #69 this issue seems to have reappeared :|. This was working with the 2.0.x snapshot, so maybe when we switched to 2.1-M1 something changed in the way Vert.x module classloader. Looking into it...

galderz added a commit to galderz/mod-lang-scala that referenced this issue Nov 7, 2013
galderz added a commit to galderz/mod-lang-scala that referenced this issue Nov 13, 2013
…f println

* Correct source code root for interpreter boot classpath
* Use a privileged action in order to figure out location root of the module
* ScalaVerticleFactory should use a Logger instead of println
galderz added a commit to galderz/mod-lang-scala that referenced this issue Nov 14, 2013
…f println

* Correct source code root for interpreter boot classpath
* Use a privileged action in order to figure out location root of the module
* ScalaVerticleFactory should use a Logger instead of println
galderz added a commit to galderz/mod-lang-scala that referenced this issue Nov 14, 2013
…f println

* Correct source code root for interpreter boot classpath
* Use a privileged action in order to figure out location root of the module
* ScalaVerticleFactory should use a Logger instead of println
galderz added a commit that referenced this issue Nov 14, 2013
* Correct source code root for interpreter boot classpath
* Use a privileged action in order to figure out location root of the module
* ScalaVerticleFactory should use a Logger instead of println
@galderz
Copy link
Contributor

galderz commented Nov 14, 2013

Fixed properly now. Apologies for the inconvenience.

@galderz galderz closed this as completed Nov 14, 2013
@ghost
Copy link

ghost commented Dec 7, 2013

I still get this error when using 2.1M2 ?

λ omnivore scala → λ git master → vertx run http/Server.scala
Downloading io.vertxlang-scala0.2.0. Please wait...
Downloading 100%
Module io.vertxlang-scala0.2.0 successfully installed
Compiling http/Server.scala as Scala script
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
:7: error: object scala is not a member of package org.vertx
import org.vertx.scala., org.vertx.scala.core., org.vertx.scala.core.buffer., org.vertx.scala.core.dns., org.vertx.scala.core.eventbus., org.vertx.scala.core.file., org.vertx.scala.core.http., org.vertx.scala.core.json., org.vertx.scala.core.net., org.vertx.scala.core.streams.
^
Script contains compilation errors, or http/Server.scala is a Scala class (pass -Dvertx.scala.interpreter.verbose=true to find out more)
Compiling as a Scala class
/Volumes/data-store/src/vertx-examples/src/raw/scala/http/Server.scala:17: error: expected class or object definition
vertx.createHttpServer.requestHandler { req: HttpServerRequest =>
^
Failed in deploying verticle
java.lang.IllegalArgumentException: Unable to run http/Server.scala as neither Scala script nor Scala class
at org.vertx.scala.platform.impl.ScalaVerticleFactory$$anonfun$1.apply(ScalaVerticleFactory.scala:116)
at org.vertx.scala.platform.impl.ScalaVerticleFactory$$anonfun$1.apply(ScalaVerticleFactory.scala:116)
at scala.Option.getOrElse(Option.scala:120)
at org.vertx.scala.platform.impl.ScalaVerticleFactory.load(ScalaVerticleFactory.scala:115)
at org.vertx.scala.platform.impl.ScalaVerticleFactory.createVerticle(ScalaVerticleFactory.scala:68)
at org.vertx.java.platform.impl.DefaultPlatformManager$19.run(DefaultPlatformManager.java:1540)
at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:176)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:724)

Failed in deploying verticle
java.lang.IllegalArgumentException: Unable to run http/Server.scala as neither Scala script nor Scala class
at org.vertx.scala.platform.impl.ScalaVerticleFactory$$anonfun$1.apply(ScalaVerticleFactory.scala:116)
at org.vertx.scala.platform.impl.ScalaVerticleFactory$$anonfun$1.apply(ScalaVerticleFactory.scala:116)
at scala.Option.getOrElse(Option.scala:120)
at org.vertx.scala.platform.impl.ScalaVerticleFactory.load(ScalaVerticleFactory.scala:115)
at org.vertx.scala.platform.impl.ScalaVerticleFactory.createVerticle(ScalaVerticleFactory.scala:68)
at org.vertx.java.platform.impl.DefaultPlatformManager$19.run(DefaultPlatformManager.java:1540)
at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:176)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:724)

@galderz
Copy link
Contributor

galderz commented Dec 9, 2013

You are using the latest available release, 0.2.0, which is known to have that issue. In the mean time, please do gradle install from master locally and then point conf/lang.properties to the 0.3.0-SNAPSHOT version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants