<?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>Jimmy&#039;s Blog &#187; run file</title>
	<atom:link href="http://jimmod.com/blog/tag/run-file/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimmod.com/blog</link>
	<description>My name is Jimmy, and this is my story... ;)</description>
	<lastBuildDate>Wed, 14 Mar 2012 03:19:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Change junit &amp; run file (main class) working directory at Netbeans 5.5 Web Project</title>
		<link>http://jimmod.com/blog/2007/11/change-junit-run-file-main-class-working-directory-at-netbeans-55-web-project/</link>
		<comments>http://jimmod.com/blog/2007/11/change-junit-run-file-main-class-working-directory-at-netbeans-55-web-project/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 08:47:50 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[run file]]></category>
		<category><![CDATA[web project]]></category>
		<category><![CDATA[working directory]]></category>

		<guid isPermaLink="false">http://jimlife.wordpress.com/2007/11/13/change-junit-run-file-main-class-working-directory-at-netbeans-55-web-project/</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		If you create a new project with Netbeans and select to create &#8220;web application&#8221;.
You&#8217;ll notice that at &#8216;project properties&#8217; &#8211; &#8216;Run&#8217; there&#8217;s no &#8216;Working Directory&#8217; configuration, unlike General Java Project.
But what if you want to create some console application (with main method) in that project with Netbeans. You run it with [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2007/11/netbeans-6-configure-which-editor-representative-class-for-new-type-extension/' rel='bookmark' title='Permanent Link: Netbeans 6 &#8211; Configure which editor (representative class) for new type extension'>Netbeans 6 &#8211; Configure which editor (representative class) for new type extension</a></li><li><a href='http://jimmod.com/blog/2007/12/netbeans-6-bug-configurationexception-class-in-apache-common-configuration-is-not-throwable/' rel='bookmark' title='Permanent Link: NetBeans 6 Bug &#8211; ConfigurationException Class in Apache Common Configuration is not Throwable?'>NetBeans 6 Bug &#8211; ConfigurationException Class in Apache Common Configuration is not Throwable?</a></li><li><a href='http://jimmod.com/blog/2007/11/using-svnssh-with-netbeans-55-windows/' rel='bookmark' title='Permanent Link: Using svn+ssh with Netbeans 5.5 + Windows'>Using svn+ssh with Netbeans 5.5 + Windows</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2007%2F11%2Fchange-junit-run-file-main-class-working-directory-at-netbeans-55-web-project%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2007/11/change-junit-run-file-main-class-working-directory-at-netbeans-55-web-project/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Change junit &amp; run file (main class) working directory at Netbeans 5.5 Web Project" data-url="http://jimmod.com/blog/2007/11/change-junit-run-file-main-class-working-directory-at-netbeans-55-web-project/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>If you create a new project with Netbeans and select to create &#8220;web application&#8221;.<br />
You&#8217;ll notice that at &#8216;project properties&#8217; &#8211; &#8216;Run&#8217; there&#8217;s no &#8216;Working Directory&#8217; configuration, unlike General Java Project.</p>
<p>But what if you want to create some console application (with main method) in that project with Netbeans. You run it with Netbeans shortcut shift+F6 (run file) and realize that Netbeans set the working directory to project base path.<br />
Then you also try to run your unit testing (junit) and realize the same thing.<br />
You put some configuration file to specific directory in your source folder, and of course your console app &amp; unit testing can&#8217;t find it.</p>
<p>I&#8217;m not very familiar with Netbeans, but after some googling I found out that Netbeans using ant : file build-impl.xml in nbproject folder. If we change the project properties configuration Netbeans will re-generate the build-impl.xml.<br />
Netbeans also provider file build.xml in project base folder for customizing project build &amp; run.</p>
<p>So i add at build.xml (copy from build-impl.xml and modify the tag &#8216;dir&#8217; value)</p>
<blockquote><p><em> &lt;target name=&#8221;-init-macrodef-junit&#8221;&gt;<br />
&lt;macrodef name=&#8221;junit&#8221; uri=&#8221;http://www.netbeans.org/ns/web-project/2&#8243;&gt;<br />
&lt;attribute name=&#8221;includes&#8221; default=&#8221;**/*Test.java&#8221;/&gt;<br />
&lt;sequential&gt;<br />
&lt;junit showoutput=&#8221;true&#8221; fork=&#8221;true&#8221; dir=&#8221;${basedir}/build/web/WEB-INF/classes&#8221; failureproperty=&#8221;tests.failed&#8221; errorproperty=&#8221;tests.failed&#8221;&gt;<br />
&lt;batchtest todir=&#8221;${build.test.results.dir}&#8221;&gt;<br />
&lt;fileset dir=&#8221;${test.src.dir}&#8221; includes=&#8221;@{includes}&#8221;/&gt;<br />
&lt;/batchtest&gt;<br />
&lt;classpath&gt;<br />
&lt;path path=&#8221;${run.test.classpath}&#8221;/&gt;<br />
&lt;/classpath&gt;<br />
&lt;syspropertyset&gt;<br />
&lt;propertyref prefix=&#8221;test-sys-prop.&#8221;/&gt;<br />
&lt;mapper type=&#8221;glob&#8221; from=&#8221;test-sys-prop.*&#8221; to=&#8221;*&#8221;/&gt;<br />
&lt;/syspropertyset&gt;<br />
&lt;formatter type=&#8221;brief&#8221; usefile=&#8221;false&#8221;/&gt;<br />
&lt;formatter type=&#8221;xml&#8221;/&gt;<br />
&lt;/junit&gt;<br />
&lt;/sequential&gt;<br />
&lt;/macrodef&gt;<br />
&lt;/target&gt;</p>
<p>&lt;target name=&#8221;-init-macrodef-java&#8221;&gt;<br />
&lt;macrodef name=&#8221;java&#8221; uri=&#8221;http://www.netbeans.org/ns/web-project/1&#8243;&gt;<br />
&lt;attribute name=&#8221;classname&#8221; default=&#8221;${main.class}&#8221;/&gt;<br />
&lt;element name=&#8221;customize&#8221; optional=&#8221;true&#8221;/&gt;<br />
&lt;sequential&gt;<br />
&lt;java fork=&#8221;true&#8221; classname=&#8221;@{classname}&#8221; dir=&#8221;${basedir}/build/web/WEB-INF/classes&#8221;&gt;<br />
&lt;jvmarg line=&#8221;${runmain.jvmargs}&#8221;/&gt;<br />
&lt;classpath&gt;<br />
&lt;path path=&#8221;${build.classes.dir.real}:${javac.classpath}:${j2ee.platform.classpath}&#8221;/&gt;<br />
&lt;/classpath&gt;<br />
&lt;syspropertyset&gt;<br />
&lt;propertyref prefix=&#8221;run-sys-prop.&#8221;/&gt;<br />
&lt;mapper type=&#8221;glob&#8221; from=&#8221;run-sys-prop.*&#8221; to=&#8221;*&#8221;/&gt;<br />
&lt;/syspropertyset&gt;<br />
&lt;customize/&gt;<br />
&lt;/java&gt;<br />
&lt;/sequential&gt;<br />
&lt;/macrodef&gt;<br />
&lt;/target&gt;</em></p></blockquote>
<p>So every unit test &amp; run-file at Netbeans will have working directory to <em>{project basedir}/build/web/WEB-INF/classes</em></p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2007/11/netbeans-6-configure-which-editor-representative-class-for-new-type-extension/' rel='bookmark' title='Permanent Link: Netbeans 6 &#8211; Configure which editor (representative class) for new type extension'>Netbeans 6 &#8211; Configure which editor (representative class) for new type extension</a></li><li><a href='http://jimmod.com/blog/2007/12/netbeans-6-bug-configurationexception-class-in-apache-common-configuration-is-not-throwable/' rel='bookmark' title='Permanent Link: NetBeans 6 Bug &#8211; ConfigurationException Class in Apache Common Configuration is not Throwable?'>NetBeans 6 Bug &#8211; ConfigurationException Class in Apache Common Configuration is not Throwable?</a></li><li><a href='http://jimmod.com/blog/2007/11/using-svnssh-with-netbeans-55-windows/' rel='bookmark' title='Permanent Link: Using svn+ssh with Netbeans 5.5 + Windows'>Using svn+ssh with Netbeans 5.5 + Windows</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2007/11/change-junit-run-file-main-class-working-directory-at-netbeans-55-web-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

