<?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>classpath &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/classpath/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Sun, 17 Oct 2021 16:10:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to print current project classpath</title>
		<link>https://codepills.com/how-to-print-current-project-classpath/</link>
					<comments>https://codepills.com/how-to-print-current-project-classpath/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Sun, 03 Oct 2021 13:44:55 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[classpath]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1259</guid>

					<description><![CDATA[This article is a short explanation of a classpath and a single line of Java code that will help you print out your classpath. <a href="https://codepills.com/how-to-print-current-project-classpath/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Imagine you want to figure out what is the path to your Java compiled classes. For that, you will need to print the classpath. This article is a short explanation of what a classpath is and a single line of Java code that will help you print out your classpath.</p>
<p><span id="more-1259"></span></p>
<h2>What is Java classpath?</h2>
<p>If we want to be wordy, <b>classpath</b> is the path where the Java Virtual Machine looks for user-defined classes, packages, and resources in Java programs. However, plain and straightforward, <b>classpath</b> is the route where the Java Virtual Machine will know where to find your compiled class.</p>
<p>Think of classpath as Java&#8217;s version of PATH environment variables &#8211; OSes search for executable files on the system environment PATH, Java searches for classes and packages on the classpath.</p>
<p>It would generally be impractical to have the JVM look through every folder on your machine. So you have to provide the JVM with a list of places where to look. Then, when we place folders and jar files on the classpath, we can automatically look up classes.</p>
<h2>How to print classpath?</h2>
<p>In Java, we can use a single line of code to print out the current project classpath. The only issue is with the system based classpath separator. On Unix based systems (Mac OS, CentOS, etc.), the colon character <code>:</code> is the classpath separator. However, on Windows, the separator is the semicolon <code>;</code>.</p>
<p>To print classpath at Unix based systems use:</p>
<pre><code class="language-java">System.out.println(System.getProperty("java.class.path").replace(':', '\n'));</code></pre>
<p>To print classpath at Windows use:</p>
<pre><code class="language-java">System.out.println(System.getProperty("java.class.path").replace(';', '\n'));</code></pre>
<p><b>Output</b></p>
<p>The code will work like a charm in new versions of Java (8, 11, &#8230;). However, the Java code snippet will also print library dependencies.</p>
<p>On Windows, the output can look something like the following example:</p>
<pre><code class="language-bash">
C:\DEV\programming\interview-preparation\trees\target\test-classes
C:\DEV\programming\interview-preparation\trees\target\classes
C:\Users\computer_user\.m2\repository\junit\junit\4.13.1\junit-4.13.1.jar
C:\Users\computer_user\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
C:\Users\computer_user\.m2\repository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar
...
</code></pre>
<p><b>Note</b>: If you have a better idea for printing classpath, let us know in the comments below.</p>
<h2>Conclusion</h2>
<p>Concisely, this article summarized what the classpath is and how to print classpath in your current Java project.</p>
<p>Did you find printing classpath easy? Do you have your trick or know another way how to print classpath? Let us know in the comments below the article. We would like to hear your ideas and stories.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-print-current-project-classpath/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
