如何从Eclipse部署Scala项目? [英] How to deploy a Scala project from Eclipse?

查看:252
本文介绍了如何从Eclipse部署Scala项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中有一个Scala项目,我需要打包,所以我可以将其部署到一个服务器上。它基于Jetty,但它作为独立应用程序运行。它包含Scala类,Java类和多个第三方jar。



我认为Scala Eclipse插件中会有某种部署选项,但是我已经绘制一个空白。



将Scala项目打包成可运行文件以便可以部署的最简单的方法是什么?



任何帮助非常感谢。
干杯。

解决方案

经过大量的尝试和错误,这是我发现用于打包Scala的最好方法应用程序分发:



首先,创建一个Java类作为应用程序的主要入口点,如 Gary Boon 。这允许您使用java命令从JAR运行应用程序。我发现使用java命令运行Scala类是有问题的,即使您的源路径上有Scala库:

  import java.util.ArrayList; 

import scala.tools.nsc.MainGenericRunner;


public class Main {
public static void main(String [] args){
ArrayList< String> argList = new ArrayList< String>();
argList.add(fully.qualified.ClassName);
for(String s:args){
argList.add(s);
}
MainGenericRunner.main(argList.toArray(new String [0]));
}
}

现在您可以使用Eclipse的导出Runnable JAR 命令将所有的类和库打包成一个JAR文件。将JAR的主类设置为Java入口点。您还可以将Eclipse生成的输出设置保存为ANT构建文件,以便您进行调整。使用ANT使用Java入口点创建JAR产生最佳结果。您还可以以这种方式打包其他JAR依赖关系,这使得在尝试在不同的主机上运行JAR时,它变得更加简单。至少您将需要Scala库和Scala工具JAR。

 < zipfileset excludes =META-INF / * .SFsrc =$ {scala.lib.jar}/> 
< zipfileset excludes =META-INF / *。SFsrc =$ {scala.tools.jar}/>

如果您使用嵌入式Jetty,就像我一样,您可以作为守护进程运行服务器使用以下命令(来源):

  nohup java -jar MyJettyServer.jar< / dev / null>> server.log 2>> server_error.log& 

将程序作为后台进程运行,该过程独立于当前用户会话,因此进程将继续退出主机后。


I have a Scala project in Eclipse that I need to package up so I can deploy it to a server. It's based on Jetty but it runs as a standalone application. It contains Scala classes, Java classes and a number of 3rd party jars.

I assumed there would be some kind of deployment option in the Scala Eclipse plugin but I've drawn a blank.

What is the simplest way to package the Scala project into a runnable file so it can be deployed?

Any help greatly appreciated. Cheers.

解决方案

After a lot of trial and error, this is the best method I found for packaging the Scala app for distribution:

First, create a Java class to be the main entry point for the application as described by Gary Boon. This allows you to run the application from a JAR with the java command. I found that running a Scala class with the java command is problematic, even when you have the Scala libs on the source path:

import java.util.ArrayList;

import scala.tools.nsc.MainGenericRunner;


public class Main { 
    public static void main (String[] args) {
        ArrayList<String> argList = new ArrayList<String>();
        argList.add("fully.qualified.ClassName");
        for (String s : args) {
            argList.add(s);
        }
        MainGenericRunner.main(argList.toArray(new String[0]));
    }
}

Now you can use Eclipse's Export Runnable JAR command to package up all your classes and libraries into a JAR file. Set the JAR's main class to the Java entry point. You can also save the Eclipse-generated output settings as an ANT build file so you can make adjustments. Using ANT to create the JAR with a Java entry point yielded best results. You can also package up other JAR dependancies this way which makes it a whole lot simpler when trying to run the JAR on a different host. As a minimum you will need the Scala library and the Scala tools JAR.

<zipfileset excludes="META-INF/*.SF" src="${scala.lib.jar}"/>
<zipfileset excludes="META-INF/*.SF" src="${scala.tools.jar}"/>

If you're using embedded Jetty, as I am, you can run the server as a Daemon process using the following command (source):

nohup java -jar MyJettyServer.jar < /dev/null >> server.log 2>> server_error.log &

This runs the program as a background process which is independent of the current user session so the process will continue after you logout of the host.

这篇关于如何从Eclipse部署Scala项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆