我们如何在 apache tomcat 服务器上运行 java 应用程序?我试过编辑 xml 文件,还尝试制作一个 war 文件并将其放在 tomcats webapp 目录中。
方法测试和测试 2 是我制作的一个简单 Java 应用程序中的方法。 我有以下类(class)
@Path("/hello")
public class HelloWorldService {
RemoteEV3 ev3;
static RMIRegulatedMotor motorA;
static boolean stop=false;
@Path("{f}")
@GET
@Produces("application/json")
public Response DeployRobot(@PathParam("f") String f) throws JSONException, NotBoundException, IOException {
String r="run";
if(f.equals(r)) {
test();
} else {
test2();
}
return Response.status(200).entity("").build();
}
public static void test() throws IOException, IOException, NotBoundException {
RemoteEV3 ev3=new RemoteEV3("10.0.1.1");
ev3.isLocal();
// Open Ports
ev3.getPort("A");
//create motors
if(motorA==null){motorA=ev3.createRegulatedMotor("A", 'L');}
//move motors, grab,suppress
while (!stop){
motorA.forward();
grab();
motorA.stop(true);
Sound.twoBeeps();
stop=true;
System.out.println("Robot is moving!");
}
if (stop){
motorA.close();
}
}
public static void test2(){
System.out.println("|*** Move Robot ****|");
}
public static void grab(){
try{
Thread.sleep(5000);
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
最佳答案
要在 Apache tomcat 上运行应用程序,您可以转到:
http://localhost:8080/manager
并管理您的网络应用程序,部署它们并添加您的 .war 文件
关于java - 在tomcat上运行java应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34503797/