我使用的是Restlet Framework,但现在我想换一个合适的服务器,而不是使用localhost。我已经将我的php文件(它们使用restrongerver URL访问java文件)添加到服务器的文件夹和我的java文件中,但我不确定如何更改代码,以便它识别文件的新位置。
以下是IdentiscopeServer的代码(构造函数为空):
public static void main(String[] args) throws Exception {
//setsup our security manager
if (System.getSecurityManager() == null){
System.setSecurityManager(new SecurityManager());
}
identiscopeServerApp = new IdentiscopeServerApplication();
IdentiscopeServer server = new IdentiscopeServer();
server.getServers().add(Protocol.HTTP,8888);
server.getDefaultHost().attach("", identiscopeServerApp);
server.start();
}
我想,要更改的正确行是带有"Protocol.HTTP8888"的行。如果我的新服务器的地址是http://devweb2013.co.uk/research/Identiscope,我该如何设置?除了将文件移动到服务器中的文件夹之外,它还有其他必要的功能吗?
IdensticopeServerApplication如下所示:
public class IdentiscopeServerApplication extends Application {
public IdentiscopeServerApplication() {
}
public Restlet createInboundRoot() {
Router router = new Router(getContext());
//attaches the /tweet path to the TweetRest class
router.attach("/collectionPublic", CollectionPublicREST.class);
router.attach("/collectionPrivate", CollectionPrivateREST.class);
router.attach("/analysis", AnalysisREST.class);
return router;
}
}
提前谢谢你,这是我第一次使用这个框架。
如果我理解正确,您只想将main()方法作为服务器运行,对吗?在这种情况下,main()的代码需要位于运行时可以在http://devweb2013.co.uk/research/Identiscope.由于您还没有说明您将代码放在哪种服务器上,我无法说明将代码放置在哪里的最佳位置。我认为您在部署服务器上具有超级用户权限,因为您提供的URL意味着端口80将为您的Identiscope web服务提供服务(端口80是大多数操作系统上的特权端口)。因此,作为回答,我只能提供一般信息。
在您的部署服务器上,端口80必须是空闲的(即,在该机器上的端口80上,任何其他东西都不应充当web服务器),并且IdentiscopeApplication必须在端口80上运行。要做到这一点,你只需要更改行:
server.getServers().add(Protocol.HTTP,8888);
至:
server.getServers().add(Protocol.HTTP, 80);
然后以允许在端口80上启动服务器的用户(最好不是超级用户)的身份运行应用程序。如果您还没有,您将需要在部署服务器上运行Java,并确保所有Restlet库都在计划运行应用程序的类路径中。
如果我明白你想做什么,那么这就应该奏效了。