Slava
Slava

Reputation: 300

Jetty: unpack .war to specific folder

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!

Upvotes: 5

Views: 5252

Answers (2)

Slava
Slava

Reputation: 300

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.

Upvotes: 5

Jayan
Jayan

Reputation: 18458

(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);

Upvotes: 1

Related Questions