I've a web application that runs with jetty. I include a client.jar in this web application for a functionality. client.jar needs a system property -Dconfig with location to the properties file. How do I pass this to when I start my application using jetty-runner ? I could only find setting it through jetty.xml but I'm trying to find if there is a way through command line.
This is not a solution to pass property through command line. I fixed this by passing below file jetty.xml to command line as below. I'm posting it here as it may help someone.
nohup $JAVA_HOME/bin/java -Denv=$1 -jar $LIB_PATH/jetty-runner-*.jar --config $CONF_PATH/jetty.xml $DIST_PATH/my-app*.war &
jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call class="java.lang.System" name="setProperties">
<Arg>
<New class="java.util.Properties">
<Call name="putAll">
<Arg>
<Call class="java.lang.System" name="getProperties" />
</Arg>
</Call>
<Call name="setProperty">
<Arg>iamconfig</Arg>
<Arg>iamclient.properties</Arg>
</Call>
</New>
</Arg>
</Call>
</Configure>
In our project, we have used below set of code to set system property while doing jetty:run
clean compile -Dcurrent.region=AIR jetty:run
Related
I managed to configure a custom implementation of the CommonJ − JSR 237 Timer & WorkManager API (http://commonj.myfoo.de) as a JNDI resource on Jetty 6 and 8, but it only works in a global scope.
With this solution JNDI name of the resource is wm/WorkManager, I need it to be java:comp/env/wm/WorkManager, but due to restrictions, I cannot use java:comp/env in a global JNDI name because it's reserved to application scoped resources.
I've created a new configuration file called {jetty.home}/etc/jetty-wtm.xml and added to {jetty.home}/start.ini.
Here is jetty-wtm.xmlcontent for Jetty 6, for greater versions it's a bit different, but works too:
<!-- =============================================================== -->
<!-- Configure Server Time and Work Managers -->
<!-- =============================================================== -->
<Configure id="Server" class="org.mortbay.jetty.Server">
<New id="WorkManager" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>wm/WorkManager</Arg>
<Arg>
<New class="de.myfoo.commonj.work.FooWorkManager">
<Arg>
<New id="threadPool" class="de.myfoo.commonj.util.ThreadPool">
<Arg type="int">0</Arg>
<Arg type="int">10</Arg>
<Arg type="int">2</Arg>
</New>
</Arg>
</New>
</Arg>
</New>
<New id="TimeManager" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>tm/TimeManager</Arg>
<Arg>
<New class="de.myfoo.commonj.timers.FooTimerManager">
<Arg>
<New id="threadPool" class="de.myfoo.commonj.util.ThreadPool">
<Arg type="int">0</Arg>
<Arg type="int">10</Arg>
<Arg type="int">2</Arg>
</New>
</Arg>
</New>
</Arg>
</New>
</Configure>
I need to mantain standard JNDI naming java:comp/env/{RESOURCE} specifically java:comp/env/wm/MyWorkManageracross servers, but standard WEB-INF\jetty-env.xml configuration file doesn't work.
Any ideas?
UPDATE:
I've tested the jetty-env.xml local configuration file in Jetty 9 and it works as expected. It seems in versions under 9 JNDI it's not fully supported. Here is the configuration file contents:
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="WorkManager" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref id="wac"/></Arg>
<Arg>wm/MyWorkManager</Arg>
<Arg>
<New class="de.myfoo.commonj.work.FooWorkManager">
<Arg>
<New id="threadPool" class="de.myfoo.commonj.util.ThreadPool">
<Arg type="int">0</Arg>
<Arg type="int">10</Arg>
<Arg type="int">2</Arg>
</New>
</Arg>
</New>
</Arg>
</New>
</Configure>
Did you check this,
Sometimes it is useful to pass configuration information to a web app at runtime that you either cannot or cannot conveniently code into
a web.xml . In such cases, you can use
org.eclipse.jetty.plus.jndi.EnvEntry, and even override an entry of
the same name in web.xml.
<New class="org.eclipse.jetty.plus.jndi.EnvEntry">
<Arg></Arg>
<Arg>mySpecialValue</Arg>
<Arg type="java.lang.Integer">4000</Arg>
<Arg type="boolean">true</Arg>
</New>
This example defines a virtual env-entry called mySpecialValue with
value 4000 that is unique within the whole JVM. It is put into JNDI at
java:comp/env/mySpecialValue for every web app deployed. Moreover,
the boolean argument indicates that this value overrides an env-entry
of the same name in web.xml. If you don't want to override, then omit
this argument, or set it to false.
For Resource in custom files inside etc, the documentation states that
Assume the following naming entry is in
$JETTY_HOME/etc/jetty-myjndi.xml:
<New id="jdbc/myds" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/myds</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/chat</Set>
<Set name="User">root</Set>
<Set name="Password">sillyness</Set>
</New>
</Arg>
</New>
Then you can link jdbc/myds into your webapp's namespace as
java:comp/env/jdbc/myfoo by using a WEB-INF/jetty-env.xml file:
<Call class="org.eclipse.jetty.plus.jndi.NamingEntryUtil" name="bindToENC">
<Arg></Arg> <!-- scope of naming entry, ie same as first argument to your naming entry definition, in this case, null -->
<Arg>jdbc/myfoo</Arg>
<Arg>jdbc/myds</Arg>
</Call>
Note that you must use a WEB-INF/jetty-env.xml file to call the
"bindToENC" method and not a context xml file, as the latter is not
interpreted at the correct phase of the webapp's deployment to have
the java:comp/env namespace created.
So, I am starting up Jetty using the Spring Context, in a standalone java application.
The deployment environment however uses an Apache server for load balancing Web requests to different instances of this application.
Unfortunately, I don't know much about Apache Load Balancing, however things are made simpler for me, and all I have to do is define a 'worker name' for the Jetty instance, probably in the Spring Context file; can anyone help me do this ?
I am shown the below configuration where I should probably be matching the 'jetty2' worker name in my Jetty configuration found in the spring context xml file:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="sessionHandler">
<Get name="sessionManager">
<Call name="setIdManager">
<Arg>
<New class="org.eclipse.jetty.server.session.HashSessionIdManager">
<Set name="WorkerName">jetty2</Set>
</New>
</Arg>
</Call>
</Get>
</Get>
</Configure>
readI'm trying to configure CGI (for perl scripts) on Jetty 9.1.5.v20140505, Windows 7. When trying solutions from the inet always getting errors that those functions/methods wouldn't be exist.
Example: http://67-23-9-112.static.slicehost.net/faq?s=900-Content&t=CGI
Adding what they are telling me, getting:
2014-05-22 13:08:09.137:WARN:oejx.XmlConfiguration:main: Config error at <Call name="addContext"><Ar
g>C:\jetty\webapps\app1\cgi-bin\*</Arg><Set name="ResourceBase">C:\jetty\webapps\app1</Set><Set name
="ServingDynamicServlets">TRUE</Set><Call name="addServlet"><Arg>Common Gateway Interface</Arg><Arg>
/</Arg><Arg>com.mortbay.Servlet.CGI</Arg><Put name="Path">/usr/local/bin:/usr/ucb:/bin:/usr/bin</Put
></Call></Call> java.lang.IllegalStateException: No Method: <Call name="addContext"><Arg>C:\jetty\we
bapps\app1\cgi-bin\*</Arg><Set name="ResourceBase">C:\jetty\webapps\app1</Set><Set name="ServingDyna
micServlets">TRUE</Set><Call name="addServlet"><Arg>Common Gateway Interface</Arg><Arg>/</Arg><Arg>c
om.mortbay.Servlet.CGI</Arg><Put name="Path">/usr/local/bin:/usr/ucb:/bin:/usr/bin</Put></Call></Cal
l> on class org.eclipse.jetty.server.Server in file:/C:/jetty/etc/jetty.x
I read an article where a guy said this would be the way for jetty 5 but not for 9. I'm researching for 9 and even in the documentation of jetty 9 I cant find anything about it. http://www.eclipse.org/jetty/documentation/9.1.5.v20140505/cgi-servlet.html doesnt tell me how to configure this jetty ...
Can you guys please help me out :(
Thanks in advice
I able to run Perl scripts like:
print "Content-type: text/html\n\n";
foreach $key (keys %ENV) {
print "$key --> $ENV{$key}<br>";
}
with this perl.xml in my webapps folder:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.servlet.ServletContextHandler">
<Set name="contextPath">/perl</Set>
<Set name="resourceBase">F:\perl_scripts</Set>
<Call name="addServlet">
<Arg>org.eclipse.jetty.servlets.CGI</Arg>
<Arg>*.pl</Arg>
<Call name="setInitParameter">
<Arg>commandPrefix</Arg>
<Arg>C:\Perl64\bin\perl.exe</Arg>
</Call>
<Call name="setInitParameter">
<Arg>Path</Arg>
<Arg>F:\perl_scripts</Arg>
</Call>
</Call>
</Configure>
Hope this helps.
I have a web-app that i run through Maven Jetty plugin.
I configure it using a jetty.xml file. My problem comes when i want to set a custom authenticator that i have created in the WebAppContext. The XML config looks like below:
<New id="webAppContext" class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="copyWebDir">true</Set>
<Set name="extractWAR">false</Set>
</Set>
<Get name="securityHandler">
<Set name="authenticator">
<New class="MY_CUSTOM_AUTHENTICATOR">
</New>
</Set>
</Get>
</New>
When i run the above i get a ClassNotFoundException for "MY_CUSTOM_AUTHENTICATOR" class. I have to add that the class exists in the same maven project that i launch Jetty from.
Is there an "import" statement that i have to do in order for Jetty to load my class?
Thank you.
You most likely need to have your authenticator in an artifact that is then declared as a dependency of the jetty maven plugin itself. With classloader isolation in play the authenticator is probably in your webapp where the security handler does not have visibility.
Two questions on configuring the jetty ant task
to get jetty to listen on a different port, I'm doing this in the jetty.xml:
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="port"><SystemProperty name="jetty.port" default="9080"/></Set>
</New>
</Arg>
</Call>
and referencing this in the ant script, e.g.
<jetty tempDirectory="..." jettyXml="...jetty.xml">
Unfortunately this simply gets jetty to load both 9080 and 8080. How do I get jetty to not require 8080?
Second question - does the jetty task support forking the jetty process, or do I have to do that with a direct ant exec instead of using the jetty plugin?
Nevermind. For anyone stuck with the same issue, it can be solved like this:
<jetty tempDirectory="...">
<connectors>
<selectChannelConnector port="9999" />
</connectors>
</jetty>
The jetty.xml is removed, calling that adds the referenced port rather than replacing. Similar to the syntax
< systemProperties>
<systemProperty name="jetty.port" value="9181"/>
</systemProperties>
which replaces the port referenced in the jetty xml but adds to instead of overwriting the default port.