I'm running a war file a.war with jetty using such code:
WebAppContext context = new WebAppContext();
context.setWar("a.war");
context.setContextPath("/controller");
handlers.addHandler(context);
I need to add a system-wide directory with keystore to classpath. When I just copy it inside WAR/classes it works. But when I specify it using:
-Djetty.class.path=...\security
(dir with keystores) - it fails with because keystore is not available on classpath. Is it possible in jetty to use war + additional classpath lib?
Thanks!
Related
I'm trying to build a docker image with my war file and jetty, and the tutorials seem pretty straght forward except for one thing.
FROM jetty
ADD mysample.war /var/lib/jetty/webapps/root.war
EXPOSE 8080
but I don't have /var/lib/jetty/webapps/root.war on my system. Brew installed jetty into /usr/local/Cellar/jetty/9.4.8.v20171121 but there isn't a root.war under the path.
I'm running macOS 10.12.6 if that matters.
If you are using the official docker image ...
https://hub.docker.com/_/jetty/
.. the /var/lib/jetty path is the ${jetty.base} directory.
When your Dockerfile uses:
ADD mysample.war /var/lib/jetty/webapps/root.war
It is taking your mysample.war and putting it in ${jetty.base}/webapps/ with the special reserved name root.war that uses contextPath = "/".
The locally installed path /usr/local/Cellar/jetty/9.4.8.v20171121 has nothing to do with your docker image, and its likely not a ${jetty.base} directory (it looks like a ${jetty.home} directory path)
If you had used the following instead ...
ADD mysample.war /var/lib/jetty/webapps/hello.war
Then that war would have been deployed to contextPath = "/hello", meaning you would access that via the general url ...
<scheme>://<host:port>/<contextPath>/<resourceInWar>
Examples:
http://localhost:8080/hello/
https://machine.com/hello/main.css
Reference: https://www.eclipse.org/jetty/documentation/9.4.x/automatic-webapp-deployment.html
I am trying to create an atlassian's bamboo plugin in clojure. The jar must contains a file called atlassian-plugin.xml at top level. How can I do so with leiningen. I expect to create my jar using lein jar.
cheers!
didier
You could put atlassian-plugin.xml in src (not sub folder) or resource folder. It will be on the top level same as project.clj.
I have recently started checking for the security vulnerabilities of our web application through a tool called Zap. After running it I came across that I've to include the robots.txt as well in our webapp.
The tool is looking for the file in the root directory of the webapp (https://localhost:8080) and the file is presented there, but it throws an error saying "file not found".
The webserver I am running is Jetty-9.3.8 and following is the tree structure of the webapp
etc
- webdefault.xml
webapps
- myapp
- web.xml
- generated-web.xml
robots.txt
We're using embedded jetty to start the server. Like this:
WebAppContext context = new WebAppContext();
context.setContextPath("/myapp");
context.setWar(jettyHome + "/webapps/myapp/");
context.setDefaultsDescriptor(jettyHome + "/etc/webdefault.xml");
File overrideFile = new File(jettyHome
+ "/webapps/myapp/WEB-INF/generated-web.xml");
if (overrideFile.exists()) {
context.setOverrideDescriptor(jettyHome
+ "/webapps/myapp/WEB-INF/generated-web.xml");
}
server.setHandler(context);
server.start();
So, how to place the file in the root directory isn't what I am getting.
Anybody has any idea about this?
You'll need a something serving static content from the contextPath of / for that to work.
Add another WebAppContext or ServletContextPath or ResourceHandler to serve the file. Make sure that you have ...
context.setContextPath("/") set
context.setBaseResource(Resource.newResource("uri/path/to/my/static/content")
I am trying to upload files to my bluemix app and I am having problems using and understanding the file system. After I have succesfully uploaded files I want to give their path on my configuration files.
Specifically, I want to upload a jar file to the server and later use it as javaagent.
I have tried approaching this isuue from several directions.
I see that I can create a folder in the liberty_buildpack and place the files inside I can later access it on the compilation-release phases from the tmp folder:
/tmp/buildpacks/ibm-websphere-liberty-buildpack/lib/liberty_buildpack/my_folder
Also I can see that in the file system that I see when building and deploying the app I can copy only to the folder located in:
/app
So I copied the JAR file to the app file and set it as a javaagent using 2 method:
Manually set enviorment variable JAVA_OPTS with java agent to point to /app/myjar.jar using cf set-env
Deploy a war file of the app using cf push from wlp server and set the java agent inside the server.xml file and attribute genericJvmArguments
Both of those methods didnt work, and either the deploy phase of the application failed or my features simply didnt work.
So I tried searching the application file system using cf files and came up with the app folder, but strangly it didn't have the same file as the folder I deploy and I couldn't find any connection to the deployed folder ot the build pack.
Can someone explain how this should be done correctly? namely, uploading the file and then how should I point to it from the enviorment variable/server file?
I mean should it be /app/something or maybe other path?
I have also seen the use of relative paths like #droplet.sandbox maybe its the way to address those files? and how should I access those folders from cf files
Thanks.
EDIT:
As I have been instructed in the comments I have added the jar file to the system, the problem is that when I add the javaagent variable to the enviorment variable JAVA_OPTS the deploy stage fails with the timeout error:
payload: {... "reason"=>"CRASHED", "exit_status"=>32, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>
1433864527}
The way I am assigning the javaagent is as follows:
cf set-env myApp JAVA_OPTS "path/agent.jar"
I have tried adding several location:
1. I have found that if I add the jar files to my WebContent folder I can find it in: /app/wlp/usr/servers/defaultServer/apps/myapp.war/resources/
2. I have copied the jar file from the /tmp location in the compilation phase to /home/vcap/app/agent.jar
3. I have located the jar file in /app/.java/jre/lib
none of those 3 paths worked.
I found out that if I give a wrong path the system behaves the same so it may be a path problem.
Any ideas?
Try this:
Put your agent jars in a folder called ".profile.d" inside your WAR package;
cf se your-app JAVA_OPTS -javaagent:/home/vcap/app/.profile.d/your.jar ;
Push the war to Bluemix.
Not sure if this is exactly the right answer, but I am using additional jar files in my Liberty application, so maybe this will help.
I push up a myapp.war file to bluemix. Within the war file, inside the WEB-INF folder, I have a lib folder that contains a number of jar files. The classes in those jar files are then used within the java code of my application.
myapp.war/WEB-INF/lib/myPlugin.jar
You could try doing something like that with the jar file(s) you need, building them into the war file.
Other than that, you could try the section Overlaying the JRE from the bluemix liberty documentation to add jars to the JRE.
I have a webapp which I deploy on a Jetty server through jetty runner. I inject properties read through a properties file using Spring. As of now, I have kept the properties file within the webapp itself (in WEB-INF/classes) directory. I want to keep this properties file external to the webapp and then inject them using Spring. Is there any configuration in the jetty.xml file I can do so I can achieve this?
I managed to solve this by adding the properties file as a command line parameter while starting jetty. Something like:
java -Dexternal.properties.file=myfile.properties -jar jetty.jar
In java code, I read it by getting system property and then using FileUtils to get file.
String externalPropertiesFile = System.getProperty("extern.properties.file");
File file = FileUtils.getFile(externalPropertiesFile);