External jar available to all Jetty web services - web-services

I have added the external jar I want to {jetty.home}/lib/ext but when I rebuild my war file without this jar, deploy it, and restart the web service, it isn't able to find the jar and I'm getting:
java.lang.NoClassDefFoundError
I'm not sure I'm headed down the right path, but essentially I would like to remove a jar from the war file of multiple web services, and have them all reference the jar via classpath (so that it can be easily updated without rebuilding and deploying the war file.
I've tried in /lib/ext, /lib/, and /resources.
[root]$ java -jar start.jar --version
Active Options: [Server, jmx, resources, websocket]
Version Information on 15 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
changes to the OPTIONS=[option,option,...] command line option will be reflected here.
0: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-xml-7.0.1.v20091125.jar
1: 2.5.0.v200806031605 | ${jetty.home}/lib/servlet-api-2.5.jar
2: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-http-7.0.1.v20091125.jar
3: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-continuation-7.0.1.v20091125.jar
4: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-server-7.0.1.v20091125.jar
5: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-security-7.0.1.v20091125.jar
6: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-servlet-7.0.1.v20091125.jar
7: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-webapp-7.0.1.v20091125.jar
8: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-deploy-7.0.1.v20091125.jar
9: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-servlets-7.0.1.v20091125.jar
10: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-jmx-7.0.1.v20091125.jar
11: (dir) | ${jetty.home}/resources
12: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-websocket-7.0.1.v20091125.jar
13: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-util-7.0.1.v20091125.jar
14: 7.0.1.v20091125 | ${jetty.home}/lib/jetty-io-7.0.1.v20091125.jar

Jetty 7.0.1 is very old now. Consider upgrading. (9.2.5.v20141112 is the current stable version)
Alright, back to your issue. You don't have the ext option enabled.
Edit your ${jetty.home}/start.ini and add ext to the end of the line that starts with OPTIONS=
Know that all this does is makes any jars that you put there present on the server classpath, suitable for the server to use for things like JNDI resources (such as database DataSource references).
The mere existence of a jar in ${jetty.home}/lib/ext does not mean its accessible by your webapps. The WebApp ClassLoader isolation (a servlet spec requirement) prevents this.
But all is not lost, Jetty provides means to configure the WebApp ClassLoader to "poke holes" into this isolation layer, allowing for control over individual classes and/or entire package namespaces behavior.
This is done by setting up and configuring the WebAppContext in a Jetty Context XML in your ${jetty.home}/webapps/ directory.
You'll have 2 things you can configure.
addSystemClass(String)
This is a class (or package) that cannot be replaced by the web application, and they are always loaded via the system classloader
addServerClass(String)
These are classes that are hidden from being loaded by the web application using the system classloader, so if a webapplication needs to load any of such classes, it has to include them in its distribution.
So, lets say you add a file called ${jetty.home}/lib/ext/corpcommon.jar, and it has a package namespace of com.corp.common, your resulting XML files will contain following snippets
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
...
<!-- webapp cannot override these, use the server version always,
even if the webapp has its own copy -->
<Call name="addSystemClass">
<Arg>com.corp.common.</Arg>
</Call>
<!-- expose com.corp.common to webapp -->
<Call name="addServerClass">
<Arg>-com.corp.common.</Arg>
</Call>

Related

ColdFusion 2016 / Coldbox 4.3 - Running multiple applications on a single server

We are using ColdBox 4.3 and are deploying multiple ColdBox applications.
Each application is developed separately with its own Coldbox.cfc config file and its own handlers, models, and views. While they do share some common features, they can not (currently) be run as a single big application run out of the root level of the website.
Our webroot directory looks something like this:
/
/coldbox
/app_1
| Application.cfc
| /coldbox
| /config
| | /Coldbox.cfc
| /handlers
| /models
| {etc}
|
/app_2
| Application.cfc
| /coldbox
| /config
| | /Coldbox.cfc
| /handlers
| /models
| {etc}
|
/app_3
| Application.cfc
{etc}
We have a copy of /coldbox at the root level and a duplicate copy of /coldbox inside each application folder.
If I delete either the root level /coldbox -or- the copy of coldbox inside each application, the application will crash.
How do other developers handle the case of multiple Coldbox applications running on the same webserver???
You need to create a CF mapping that maps /coldbox for each app to wherever ColdBox lives. If all your apps use the same version of ColdBox, then I'd just point them all at the same place. And it doesn't even need to be in the web root. As long as /coldbox resolves to the framework, you'll be fine.
And no another note, if you're on Adobe ColdFusion and hosting more than one app on the same server, you'll want to turn off "Component Cache" in the CF administrator. It will really mess you up.

Mulitple war deployment on AWS Tomcat 8

I am new to AWS and we are trying to deploy multiple war files on a single instance of AWS Elastic Beanstalk with Tomcat 8. We have multiple services actually and we want to ensure that they are available mostly. So that ways even if there is a change in one, code changes and deployment do not affect the others. We've tried zipping the multiple wars and it works but then it again means other services won't be available in case of a change in any one of the services. Is there a way to implement this without zipping the multiple wars together and then deploying it?
If Every War file refers a different web Application then you can deploy these war files using a source bundle .
Make a Source Bundle and add each war file with in it .
Exp : MyApplication.zip
->app1.war
->app2.war
->app3.war
->ROOT.war
When Elastic Beanstalk sees that you’ve deployed a file like this it treats it differently than a normal bundle. It takes the WAR file called ROOT.war and deploys that as the root application. The rest of the WAR files are deployed in directories derived from their file names. For example, application1.war would be accessed through the /application1 path.
Now change the extraction script provided by HostManager . find the script in given file :
/opt/elasticbeanstalk/srv/hostmanager/lib/elasticbeanstalk/hostmanager/utils/tomcatutil.rb
OR You can find the script by given command :
grep -i -r ROOT.war /opt/elasticbeanstalk/srv/hostmanager/lib/:

Load properties file external to webapp in Jetty

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

How do I upload a webpage to Bluemix using the cf CLI?

I'm trying to upload an index.html page to Bluemix using the cf CLI. I'm not sure if I'm approaching this with the right mentality. I'm thinking of uploading this HTML file as we usually do with normal hosting services, through FTP. With Bluemix I assume I should be using the push command in cf and treat this index.html as an app. Is this right?
If this is right, I'm not getting how to use this command. Can you give me an example of full command to push/upload this page?
The cf push command would be the one to use to 'upload' your application to the Bluemix server. However, it does more than just upload. In Bluemix there is a concept of a runtime or buildpack, the idea being this will be the runtime to run your application. So if you uploaded a Java application you would pair it with the Java Liberty Buildpack/runtime. If you uploaded a PHP application then you would pair it with the PHP buildpack.
If you pushed just a HTML file with no buildpack then you would likely get an error indicating the buildpack could not be determined. Bluemix tries to guess the type of buildpack you want based on the type of files uploaded, and then pull the buildpack from an internal cache. The cf push command allows you to explicitly state the buildpack to use -b so there is no guess work and no need to rely on only the buildpack that Bluemix currently knows about.
In your case, for a static HTML file you would need some type of http server like nginx as the 'runtime'. Notice that Bluemix currently does not have a built-in buildpack for this, so you'd have to get it from somewhere else. There are a few buildpacks available already, but the best one to use would be this one: https://github.com/cloudfoundry-community/staticfile-buildpack . To use it simply supply that url with the -b option on the cf push command from the root directory of your application i.e.
cf push yourappname -b https://github.com/cloudfoundry-community/staticfile-buildpack
Be sure you are issuing this command from your app directory.
The yourappname will be part of the URL for your website/app
For an actual example, we will upload your index.html which exist in folder C:\Users\XYZ\Documents\projects\ProjectHelloWorld and we will call this app HelloWorld. Here is what we would do:
C:\> cd C:\Users\XYZ\Documents\projects\ProjectHelloWorld
C:\Users\XYZ\Documents\projects\ProjectHelloWorld> cf push HelloWorld -b https://git
hub.com/cloudfoundry-community/staticfile-buildpack
Bluemix will then upload everything in that local directory to the server and also grab the buildpack from the URL location and stage your application code with the buildpack, Bluemix will then attempt to start the application. This is an example Bluemix output when the push command succeed:
Creating app HelloWorld in org xyz#gmail.com / space test as xyz#gmail.com...
OK
Creating route HelloWorld.mybluemix.net...
OK
Binding HelloWorld.mybluemix.net to HelloWorld...
OK
Uploading HelloWorld...
Uploading app files from: C:\Users\XYZ\Documents\projects\ProjectHelloWorld
Uploading 1M, 21 files
Done uploading
OK
Starting app HelloWorld in org xyz#gmail.com / space test as xyz#gmail.com...
-----> Downloaded app package (960K)
Cloning into '/tmp/buildpacks/staticfile-buildpack'...
grep: Staticfile: No such file or directory
-----> Using root folder
-----> Copying project files into public/
-----> Setting up nginx
grep: Staticfile: No such file or directory
-----> Uploading droplet (3.4M)
1 of 1 instances running
App started
OK
Showing health and status for app HelloWorld in org xyz#gmail.com / space
test as xyz#gmail.com...
OK
requested state: started
instances: 1/1
usage: 1G x 1 instances
urls: HelloWorld.mybluemix.net
last uploaded: Tue Nov 25 14:50:44 +0000 2014
For more details:
See the github page for the buildpack on how to structure your application (public folder etc)
See Bluemix Docs website. It has a lot of demos and examples.
See Takehiko Amano's Bluemix demo. Is a good and easy to understand demo.
you can either deploy your app directly using "cf push ..." or via creating a manifest.yml file.if you create manifest.yml file inside you app code path,only cf push is sufficient.
below is the reference link for this:
http://clouds-with-carl.blogspot.in/2014/02/deploy-minimal-nodejs-application-to.html
Hope it clears your doubt!!
Yeah as whitfiea mentioned its pretty simple. You need to use the cf push command. For example if you had a static website with an index.html file.
For example the following.
[02:30 PM] jsloyer#jeffs-mbp [friendme]>ls
index.html
To push that app to Bluemix run the following.
cf push yourappname -b https://github.com/cloudfoundry-community/staticfile-buildpack.git
https://www.ng.bluemix.net/docs/#starters/index.html
In this browse Creating Web Apps->Building a web app-> Uploading an app
It says;-
You can use a sample Java™ web application to get started. This sample application displays the list of environment variables that are available. You can download the sample Java web application from the community sample site. The sample application contains a single JSP and the WEB-INF/web.xml file.
Extract the downloaded file, and a new directory that contains the application is created. From the newly created application directory, issue the cf push command. In the following example, you can use a unique name testEnv for the application and 512M for memory allocation. The name must be unique in the whole Bluemix environment.
$ cf push testEnv -m 512m
->So as per your requirement, you can add your html file along with the JSP file before uploading the application.
Hopefully this help...

CloudFoundry nodeJS tutorial is out of date?

I'm following the nodeJS tutorial and as I get the point of pushing the application to Cloudfoundry.com the push flow in the tutorial and the one I see are very different.
I use vmc 0.999 and this is what I see:
Name> hello-node
Instances> 1
1: node 2: other Framework> node
1: node 2: node06 3: node08 4: other Runtime> 3
1: 64M 2: 128M 3: 256M 4: 512M 5: 1G 6: 2G Memory Limit> 64M
Creating ido-hello-node... OK
1: ido-hello-node.cloudfoundry.com 2: none URL>
ido-hello-node.cloudfoundry.com
Updating ido-hello-node... OK
Create services for application?> n
Save configuration?> y
Saving to manifest.yml... OK Uploading ido-hello-node... OK Using
manifest file manifest.yml
Starting ido-hello-node... OK Checking ido-hello-node
Am I doing something wrong or is the tutorial simply out-dated?
There is no vmc 0.999 so I am not sure what version you actually have - the latest version as of now (obtained by typing 'gem install vmc --pre') is vmc-0.5.0-rc1. You can check which version you have using 'vmc --version'
Yes, the tutorials at http://docs.cloudfoundry.com are outdated and we are busy working on updated versions at http://cloudfoundry.github.com.
You can find the latest Node tutorial here: http://cloudfoundry.github.com/docs/using/deploying-apps/javascript/
If you find any mistakes or would like to suggest additions please feel free to contribute by sending a Github pull request.
It looks like your application pushed successfully. Was there a problem running it?
The vmc command is changing, and the docs you reference may be getting out of date. New docs are being created and published here: http://cloudfoundry.github.com/docs/using/deploying-apps/javascript/. These docs are a work-in-progress, but are more up to date.