Running Scala project whose directory structure does not match packages in source

585 views
Skip to first unread message

brai...@gmail.com

unread,
Jun 17, 2013, 3:45:27 PM6/17/13
to scala-i...@googlegroups.com
Hi,

I'm working on a Scala project where the packages declared in the source file "import ..." statement does not match the directory structure.
The project builds and runs with SBT, but I can't get Eclipse to run the main class.

However, if I import the project to Eclipse (with sbteclipse), and right click on main() -> Run As..., I do not get the option to "Run as Scala Application".
If I add a Run Configuration with main class "myproject.hello.mainclass.MainClass", I get the error "Cannot locate main type main type ... For this to work the package name in the source needs to match the source's physical location."

Is there a way to run the main class without modifying the directory structure? (I'm working on a large project and don't have the flexibility to change the directory structure.)

Thanks!

----

Here's an example of the compile/run working in SBT:

tba:test$ cat build.sbt
name := "A Project"

version := "0.1"

scalaVersion := "2.10.1"

tba:test$ cat ./src/main/scala/hello/hello.scala
package myproject.hello.mainclass // <-- doesn't match the directory src/main/scala/hello/

object MainClass {
    def main( args:Array[String] ) {
        System.out.println("hi")
    }
}

tba:test$ sbt "run-main myproject.hello.mainclass.MainClass"
[info] Loading global plugins from /Users/tba/.sbt/plugins
[info] Set current project to A Project (in build file:/Users/tba/HMC/research/workspace/test/)
[info] Running myproject.hello.mainclass.MainClass
hi
[success] Total time: 0 s, completed Jun 17, 2013 12:16:01 PM

Mirco Dotta

unread,
Jun 18, 2013, 1:31:51 AM6/18/13
to scala-i...@googlegroups.com
Hi,

Hi,

I'm working on a Scala project where the packages declared in the source file "import ..." statement does not match the directory structure.
The project builds and runs with SBT, but I can't get Eclipse to run the main class.

However, if I import the project to Eclipse (with sbteclipse), and right click on main() -> Run As..., I do not get the option to "Run as Scala Application".
If I add a Run Configuration with main class "myproject.hello.mainclass.MainClass", I get the error "Cannot locate main type main type ... For this to work the package name in the source needs to match the source's physical location."

This is a bug. In fact, if in the Run Configuration you use "myproject.hello.mainclass.MainClass" as 
Main class, the program is indeed executed, despite the info dialog.

Is there a way to run the main class without modifying the directory structure? (I'm working on a large project and don't have the flexibility to change the directory structure.)

Please, check in the console, you should see the expected output.

I understand (and absolutely agree) it's annoying to close the dialog every time you run the application, but you should be able to run the main class as it is.

Thanks!

Thank **you** for reporting the problem!

I've opened a ticket for this problem here https://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1001760, feel free to add any additional information.


----

Here's an example of the compile/run working in SBT:

tba:test$ cat build.sbt
name := "A Project"

version := "0.1"

scalaVersion := "2.10.1"

tba:test$ cat ./src/main/scala/hello/hello.scala
package myproject.hello.mainclass // <-- doesn't match the directory src/main/scala/hello/

object MainClass {
    def main( args:Array[String] ) {
        System.out.println("hi")
    }
}

tba:test$ sbt "run-main myproject.hello.mainclass.MainClass"
[info] Loading global plugins from /Users/tba/.sbt/plugins
[info] Set current project to A Project (in build file:/Users/tba/HMC/research/workspace/test/)
[info] Running myproject.hello.mainclass.MainClass
hi
[success] Total time: 0 s, completed Jun 17, 2013 12:16:01 PM

--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mirco Dotta

unread,
Jun 28, 2013, 11:59:58 AM6/28/13
to scala-i...@googlegroups.com
Hi,

Hi,

I'm working on a Scala project where the packages declared in the source file "import ..." statement does not match the directory structure.
The project builds and runs with SBT, but I can't get Eclipse to run the main class.

However, if I import the project to Eclipse (with sbteclipse), and right click on main() -> Run As..., I do not get the option to "Run as Scala Application".
If I add a Run Configuration with main class "myproject.hello.mainclass.MainClass", I get the error "Cannot locate main type main type ... For this to work the package name in the source needs to match the source's physical location."

This is a bug. In fact, if in the Run Configuration you use "myproject.hello.mainclass.MainClass" as 
Main class, the program is indeed executed, despite the info dialog.

Is there a way to run the main class without modifying the directory structure? (I'm working on a large project and don't have the flexibility to change the directory structure.)

Please, check in the console, you should see the expected output.

I understand (and absolutely agree) it's annoying to close the dialog every time you run the application, but you should be able to run the main class as it is.

Thanks!

Thank **you** for reporting the problem!

I've opened a ticket for this problem here https://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1001760, feel free to add any additional information.

The above ticket has been fixed in the freshly announced 3.0.1-RC2 (http://scala-ide.org/blog/release-notes-3.0.1-RC02.html)

Would be great if you could upgrade and let us know if it works fine now.

-- Mirco
Reply all
Reply to author
Forward
0 new messages