Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty: unpack .war to specific folder

Tags:

java

war

jetty

I need to run Jetty, specify war-file and have it unpacked by Jetty into specific location. The common behavior of Jetty is to take TEMP directory or JETTY_HOME/work directory and unpack war-file into a sub-folder named like this: jetty-HOST-PORT-CONTEXT.war-_-any- This is absolutely inappropriate for our environment because the PORT part is random. War-file must be unpacked by Jetty and the destination must be 100% flexible.

Is it possible? Please advice. Jetty isn’t my area of expertise, forgive me if the question is lame or trivial, however googling didn’t help much.

Thank you very much!

like image 397
Slava Avatar asked Mar 01 '12 15:03

Slava


2 Answers

Thank you everyone. I’ve managed to achieve the requirement extending Jetty with the following code:

int port = 8080;
String context_path = "/";
File tmp_directory = "C:\\some-custom-path\\";
String war_path = "C:\\path-to-a\\file.war";

WebAppContext app = new WebAppContext();
app.setContextPath( context_path );
app.setWar( war_path );
app.setTempDirectory( tmp_directory );

Server server = new Server( port );
server.setHandler( app );
server.start();
server.join();

app.setTempDirectory call makes Jetty unpack war-file into custom folder. I’ve not found any other way but the solution suits me right.

like image 178
Slava Avatar answered Sep 30 '22 00:09

Slava


(not tried it, just reading from the wiki page jetty wiki) You could extract the war to a predefined direcory. And then provide that folder as setWar argument.

    Server server = new Server(8080);
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(jetty_home+"/webapps/testlocation/");
    server.setHandler(webapp);
like image 29
Jayan Avatar answered Sep 30 '22 00:09

Jayan