简体   繁体   English

Scala和Eclipse:导出为Jar文件,但找不到主要方法

[英]Scala and Eclipse: Export as Jar File, but cannot find main method

I have a problem exporting a scala project as a .jar file and then run it using a command in the cmd. 我将scala项目导出为.jar文件,然后使用cmd中的命令运行它时遇到问题。 The file takes a port number as its parameter, because it establishes a TCP connection between a server and a client. 该文件将端口号作为其参数,因为它在服务器和客户端之间建立了TCP连接。 There are three files: 有三个文件:

  • Engine.scala = object containing the main method: Starts a web server (waits for input query from a html file and transfers it to a text processing server) and a text processing server (this will take the query and search an inverted index of a text file (alice in wonderland ;) and return all the lines of the text file, in which the query terms occur). Engine.scala =包含主要方法的对象:启动Web服务器(等待html文件中的输入查询并将其传输到文本处理服务器)和文本处理服务器(这将获取查询并搜索a的倒排索引)文本文件(alice in wonderland;)并返回文本文件中出现查询字词的所有行。

  • TextProcessingServer: does the query search TextProcessingServer:查询是否进行搜索

  • WebServer: waits for query input WebServer:等待查询输入

When I start it in eclipse and pass a port number (8090 in my case), everything works fine and I can query my server using a web site. 当我在eclipse中启动它并传递端口号(在我的情况下为8090)时,一切正常,我可以使用网站查询服务器。

However, if I try to export it, it doesn't work anymore. 但是,如果我尝试导出它,它将不再起作用。 To export it to a jar, I do the following: 要将其导出到罐子中,请执行以下操作:

  1. in eclipse, I export it by: Export -> Java -> JAR File -> 1234.jar and check "Export all output folders for checked projects" and "Export Java source files and resources". 在eclipse中,我通过以下方式导出它:导出-> Java-> JAR文件-> 1234.jar,然后选中“导出所有输出文件夹以查看项目”和“导出Java源文件和资源”。

  2. In the command line, I type: java -cp 1234.jar:lib/scala-library.jar assignment1.Engine 8090 在命令行中,输入:java -cp 1234.jar:lib / scala-library.jar assignment1.Engine 8090

Now I get the following error message: 现在,我收到以下错误消息:

Error: Could not find or load main class assignment1.Engine

Versions used: 使用的版本:

Scala IDE build of Eclipse SDK (Version Indigo)

Build id: 3.0.1-vfinal-20130718-1727-Typesafe

Can anybody help me? 有谁能够帮助我? I have tried almost everything suggested on the internet, like adapting the Manifest etc. but nothing seems to work. 我尝试了互联网上几乎所有建议的方法,例如修改清单等,但似乎没有任何效果。 It will just not find the main method :( 它只是找不到主要方法:(

What I already noticed when I run it in Eclipse is that I cannot choose "run as Scala application", I can only run it as Java application. 我在Eclipse中运行它时已经注意到,我不能选择“以Scala应用程序运行”,而只能以Java应用程序运行。 Don't know if that is of any importance... 不知道那有什么意义...

Thanks a lot for your help! 非常感谢你的帮助!

You're from Distributed Systems HS2013, right? 您来自Distributed Systems HS2013,对吗? :-D :-D

The problem is, that in the command line you're typing lib/scala-library.jar but you're not providing the scala library in the same folder as your jar is in. If your jar is on the Desktop you need to copy the folder lib from your scala installation to the Desktop or you just provide the scala-library.jar (than you type scala-library.jar instead of lib/scala-library.jar ). 问题是,在命令行中您输入的是lib/scala-library.jar但没有在jar所在的文件夹中提供scala库。如果您的jar位于桌面上,则需要复制从scala安装到桌面的lib文件夹,或者只提供scala-library.jar(而不是键入scala-library.jar而不是lib/scala-library.jar )。 If you're using Windows you should replace the : with a ; 如果您使用Windows,则应将:替换为; so it looks like this: 所以看起来像这样:

java -cp 1234.jar;lib/scala-library.jar assignment1.Engine 8090

It will probably not find your text file though, so you have to copy it to the same folder (eg Desktop) as well. 但是它可能找不到您的文本文件,因此您也必须将其复制到同一文件夹(例如,桌面)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM