<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jetty &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/jetty/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 17:23:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Jetty &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Maven + Jetty: Enabling SSL on Jetty Maven Plugin</title>
		<link>https://myshittycode.com/2014/06/03/maven-jetty-enabling-ssl-on-jetty-maven-plugin/</link>
					<comments>https://myshittycode.com/2014/06/03/maven-jetty-enabling-ssl-on-jetty-maven-plugin/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Wed, 04 Jun 2014 02:05:19 +0000</pubDate>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Jetty]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[SSL]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=501</guid>

					<description><![CDATA[<p>PROBLEM In order to run our web application using HTTPS, we need to enable SSL first on Jetty. SOLUTION #1: Generating Certificate on the Fly One clean solution by @PascalThivent is to recreate the certificate whenever Jetty starts. Not to steal any credits from him, but here&#8217;s a slightly modified configuration using more recent plugin [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/06/03/maven-jetty-enabling-ssl-on-jetty-maven-plugin/">Maven + Jetty: Enabling SSL on Jetty Maven Plugin</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>In order to run our web application using HTTPS, we need to enable SSL first on Jetty.</p>



<h3 class="wp-block-heading">SOLUTION #1: Generating Certificate on the Fly</h3>



<p><a href="http://stackoverflow.com/questions/3794892/howto-use-https-ssl-with-maven-mortbay-jetty-plugin" target="_blank" rel="noopener">One clean solution by @PascalThivent</a> is to recreate the certificate whenever Jetty starts. Not to steal any credits from him, but here&#8217;s a slightly modified configuration using more recent plugin versions:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;keytool-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.5&lt;/version&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;phase&gt;generate-resources&lt;/phase&gt;
            &lt;id&gt;clean&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;clean&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
        &lt;execution&gt;
            &lt;phase&gt;generate-resources&lt;/phase&gt;
            &lt;id&gt;generateKeyPair&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;generateKeyPair&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;configuration&gt;
        &lt;keystore&gt;${project.build.directory}/jetty-ssl.keystore&lt;/keystore&gt;
        &lt;dname&gt;cn=localhost&lt;/dname&gt;
        &lt;!--Both `keypass` and `storepass` must be at least 6 characters long. --&gt;
        &lt;keypass&gt;jetty8&lt;/keypass&gt;
        &lt;storepass&gt;jetty8&lt;/storepass&gt;
        &lt;alias&gt;jetty8&lt;/alias&gt;
        &lt;keyalg&gt;RSA&lt;/keyalg&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;

&lt;plugin&gt;
    &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
    &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;8.1.14.v20131031&lt;/version&gt;
    ...
    &lt;configuration&gt;
        &lt;connectors&gt;
            &lt;connector implementation=&quot;org.eclipse.jetty.server.bio.SocketConnector&quot;&gt;
                &lt;port&gt;7777&lt;/port&gt;
            &lt;/connector&gt;
            &lt;connector implementation=&quot;org.eclipse.jetty.server.ssl.SslSocketConnector&quot;&gt;
                &lt;port&gt;7443&lt;/port&gt;
                &lt;keystore&gt;${project.build.directory}/jetty-ssl.keystore&lt;/keystore&gt;
                &lt;keyPassword&gt;jetty8&lt;/keyPassword&gt;
                &lt;password&gt;jetty8&lt;/password&gt;
            &lt;/connector&gt;
        &lt;/connectors&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;
</pre></div>


<p>In this case, the generated certificate is stored under the project&#8217;s build directory (&#8220;target&#8221; directory) every time we run <strong>mvn clean jetty:run</strong>. This is a great solution because it allows me to easily pass my project to my peers without the need to worry about the generated certificate.</p>



<p>However, a downside to this approach is because the certificate is regenerated again and again, my browser keeps prompting me to add an exception whenever I refresh the web link.</p>



<figure class="wp-block-image aligncenter"><img fetchpriority="high" decoding="async" width="602" height="426" src="https://myshittycode.com/wp-content/uploads/2014/06/screen-shot-2014-06-03-at-8-15-03-am-1.png?x45560" alt="" class="wp-image-505" srcset="https://myshittycode.com/wp-content/uploads/2014/06/screen-shot-2014-06-03-at-8-15-03-am-1.png 602w, https://myshittycode.com/wp-content/uploads/2014/06/screen-shot-2014-06-03-at-8-15-03-am-1-300x212.png 300w" sizes="(max-width: 602px) 100vw, 602px" /></figure>



<p>&#8230; and after adding the exception for like 5 times, it begins to get very annoying.</p>



<h3 class="wp-block-heading">SOLUTION #2: Generating Certificate Once and Reuse it</h3>



<p>Instead of regenerating the certificate again and again, I decided to generate the certificate that will last for 99999 days and store it under <strong>src/main/config</strong> directory.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; highlight: [6,13,29]; title: ; notranslate">
&lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;keytool-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.5&lt;/version&gt;
    &lt;configuration&gt;
        &lt;keystore&gt;${project.basedir}/src/main/config/jetty-ssl.keystore&lt;/keystore&gt;
        &lt;dname&gt;cn=localhost&lt;/dname&gt;
        &lt;!--Both `keypass` and `storepass` must be at least 6 characters long. --&gt;
        &lt;keypass&gt;jetty8&lt;/keypass&gt;
        &lt;storepass&gt;jetty8&lt;/storepass&gt;
        &lt;alias&gt;jetty8&lt;/alias&gt;
        &lt;keyalg&gt;RSA&lt;/keyalg&gt;
        &lt;validity&gt;99999&lt;/validity&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;


&lt;plugin&gt;
    &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
    &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;8.1.14.v20131031&lt;/version&gt;
    ...
    &lt;configuration&gt;
        &lt;connectors&gt;
            &lt;connector implementation=&quot;org.eclipse.jetty.server.bio.SocketConnector&quot;&gt;
                &lt;port&gt;7777&lt;/port&gt;
            &lt;/connector&gt;
            &lt;connector implementation=&quot;org.eclipse.jetty.server.ssl.SslSocketConnector&quot;&gt;
                &lt;port&gt;7443&lt;/port&gt;
                &lt;keystore&gt;${project.basedir}/src/main/config/jetty-ssl.keystore&lt;/keystore&gt;
                &lt;keyPassword&gt;jetty8&lt;/keyPassword&gt;
                &lt;password&gt;jetty8&lt;/password&gt;
            &lt;/connector&gt;
        &lt;/connectors&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;
</pre></div>


<p>To generate (or regenerate) the certificate, run <strong>mvn keytool:clean keytool:generateKeyPair</strong>.</p>



<p>With this approach, I just need to add an exception ONCE in my browser regardless of the number of times I restart Jetty&#8230; or when I&#8217;m still actively working on this project after 99999 days.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/06/03/maven-jetty-enabling-ssl-on-jetty-maven-plugin/">Maven + Jetty: Enabling SSL on Jetty Maven Plugin</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2014/06/03/maven-jetty-enabling-ssl-on-jetty-maven-plugin/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">501</post-id>	</item>
		<item>
		<title>Managing Log4j Configuration for Both Development and Production Environments</title>
		<link>https://myshittycode.com/2013/09/04/managing-log4j-configuration-for-both-development-and-production-environments/</link>
					<comments>https://myshittycode.com/2013/09/04/managing-log4j-configuration-for-both-development-and-production-environments/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Wed, 04 Sep 2013 13:25:19 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Jetty]]></category>
		<category><![CDATA[Log4j]]></category>
		<category><![CDATA[Maven]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=25</guid>

					<description><![CDATA[<p>PROBLEM Most of the time, we set the Log4j&#8217;s log levels to something lower (debug or info) during our local development. Once it is ready for production, we normally set the Log4j&#8217;s log levels to something higher (warn or even error) to prevent meaningless information from flooding the server log. One way to do this [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/09/04/managing-log4j-configuration-for-both-development-and-production-environments/">Managing Log4j Configuration for Both Development and Production Environments</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>Most of the time, we set the Log4j&#8217;s log levels to something lower (<b>debug</b> or <b>info</b>) during our local development. Once it is ready for production, we normally set the Log4j&#8217;s log levels to something higher (<b>warn</b> or even <b>error</b>) to prevent meaningless information from flooding the server log.</p>



<p>One way to do this is to manually adjust the log level(s) in <b>log4.xml</b> during our local development, for example:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?--&gt;

&lt;log4j:configuration&gt;
    &lt;!-- This appender logs to the console --&gt;
    &lt;appender name=&quot;consoleAppender&quot; class=&quot;org.apache.log4j.ConsoleAppender&quot;&gt;
        &lt;param name=&quot;Target&quot; value=&quot;System.out&quot;&gt;
        &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
            &lt;param name=&quot;ConversionPattern&quot; value=&quot;&#x5B;%-5p] &#x5B;%c{1}] &#x5B;%M:%L] - %m%n&quot;&gt;
        &lt;/layout&gt;
    &lt;/appender&gt;

	&lt;!-- Set &quot;debug&quot; log level for project code  --&gt;
    &lt;logger name=&quot;com.choonchernlim.myproject&quot;&gt;
        &lt;level value=&quot;debug&quot;&gt;
    &lt;/level&gt;&lt;/logger&gt;

	&lt;!-- Set &quot;info&quot; log level for Spring framework  --&gt;
    &lt;logger name=&quot;org.springframework&quot;&gt;
        &lt;level value=&quot;info&quot;&gt;
    &lt;/level&gt;&lt;/logger&gt;

	&lt;!-- Set &quot;debug&quot; log level for Hibernate framework  --&gt;
    &lt;logger name=&quot;org.hibernate&quot;&gt;
        &lt;level value=&quot;debug&quot;&gt;
    &lt;/level&gt;&lt;/logger&gt;

    &lt;root&gt;
    	&lt;!-- The default log level is &quot;warn&quot; --&gt;
        &lt;priority value=&quot;warn&quot;&gt;
        &lt;appender-ref ref=&quot;consoleAppender&quot;&gt;
    &lt;/appender-ref&gt;&lt;/priority&gt;&lt;/root&gt;
&lt;/log4j:configuration&gt;
</pre></div>


<p>Once we are ready for production, we will manually change the package specific log levels back to <b>warn</b> or comment them out, for example:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?--&gt;

&lt;log4j:configuration&gt;
    &lt;!-- this appender logs to the console --&gt;
    &lt;appender name=&quot;consoleAppender&quot; class=&quot;org.apache.log4j.ConsoleAppender&quot;&gt;
        &lt;param name=&quot;Target&quot; value=&quot;System.out&quot;&gt;
        &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
            &lt;param name=&quot;ConversionPattern&quot; value=&quot;&#x5B;%-5p] &#x5B;%c{1}] &#x5B;%M:%L] - %m%n&quot;&gt;
        &lt;/layout&gt;
    &lt;/appender&gt;

	&lt;!-- Comment out package specific log levels
    &lt;logger name=&quot;com.choonchernlim.myproject&quot;&gt;
        &lt;level value=&quot;debug&quot;/&gt;
    &lt;/logger&gt;

    &lt;logger name=&quot;org.springframework&quot;&gt;
        &lt;level value=&quot;info&quot;/&gt;
    &lt;/logger&gt;

    &lt;logger name=&quot;org.hibernate&quot;&gt;
        &lt;level value=&quot;debug&quot;/&gt;
    &lt;/logger&gt;
	--&gt;

    &lt;root&gt;
		&lt;!-- The default log level is &quot;warn&quot; --&gt;
        &lt;priority value=&quot;warn&quot;&gt;
        &lt;appender-ref ref=&quot;consoleAppender&quot;&gt;
    &lt;/appender-ref&gt;&lt;/priority&gt;&lt;/root&gt;
&lt;/log4j:configuration&gt;
</pre></div>


<p>The problem with this approach is I <strong>always forget</strong> to make necessary changes in <b>log4j.xml</b> when I&#8217;m ready to package my project to be deployed in production.</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>The solution that I come up with is rather simple. We will have two Log4j XML files under <b>src/main/resources</b>:-</p>



<ul class="wp-block-list">
<li><b>log4j.xml</b></li>



<li><b>log4j-dev.xml</b></li>
</ul>



<p>By default, assuming there&#8217;s no further Log4j configuration, <b>log4j.xml</b> will always get picked up by Log4j due to the default filename and its location. <b>log4j-dev.xml</b> will always be ignored by Log4j.</p>



<p>To ensure our local development picks up the configuration from <b>log4j-dev.xml</b>, we will need to make a minor tweak to the Jetty configuration in <b>pom.xml</b>:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; highlight: [16,17,18,19]; title: ; notranslate">
&lt;project ...=&quot;&quot;&gt;
	...
    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupid&gt;org.mortbay.jetty&lt;/groupid&gt;
                &lt;artifactid&gt;jetty-maven-plugin&lt;/artifactid&gt;
                &lt;version&gt;8.1.8.v20121106&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;systemproperties&gt;
                        &lt;!--
                        When Jetty runs, &quot;log4j-dev.xml&quot; will be used instead of
						&quot;log4j.xml&quot; because the latter is reserved for production
						usage.
                        --&gt;
                        &lt;systemproperty&gt;
                            &lt;name&gt;log4j.configuration&lt;/name&gt;
                            &lt;value&gt;log4j-dev.xml&lt;/value&gt;
                        &lt;/systemproperty&gt;
                    &lt;/systemproperties&gt;
					...
                &lt;/configuration&gt;
                &lt;dependencies&gt;
					...
                &lt;/dependencies&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;
&lt;/project&gt;
</pre></div>


<p>This way, when we run our local development on Jetty, <b>log4j-dev.xml</b> will be used. When we deploy the project in production, <b>log4j.xml</b> will be used instead.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/09/04/managing-log4j-configuration-for-both-development-and-production-environments/">Managing Log4j Configuration for Both Development and Production Environments</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2013/09/04/managing-log4j-configuration-for-both-development-and-production-environments/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">25</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-20 15:02:34 by W3 Total Cache
-->