Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to echo class path variable to a file

Tags:

I'm trying to get all the contents on my main classpath to get written to a file by my Ant buildscript:

<path id="main.class.path">     <fileset dir="${lib.main.dir}">         <include name="**/*.*"/>     </fileset> </path> 

When I hover over main.class.path, Ant/Eclipse launches a tooltip that shows the items on that classpath:

C:\Users\myUser\workbench\eclipse\workspace\myProj\lib\main\ant-junit-1.6.5.jar

etc. (The actual list has about 30 JARs on it.)

I want this list written to a file called deps.txt under my dist/ directory.

I'm stuck because I can't figure out how to make main.class.path an Ant variable, or how to at least access it in the <echo> task:

<echo file="${dist.dir}/deps.txt" message="${???}"/> 

Am I way-off base here, or even remotely close?!?

And for those of you out there that, instead of answering this question, would just comment Why would you want to do this?, my answer is simple: I just want a small text file in my JAR that serves as a visual reminder (for my future me) for what its dependencies are.

like image 490
IAmYourFaja Avatar asked Mar 15 '12 16:03

IAmYourFaja


People also ask

How do you find the class path?

To check our CLASSPATH on Windows we can open a command prompt and type echo %CLASSPATH%. To check it on a Mac you need to open a terminal and type echo $CLASSPATH.

What is Classpath environment variable?

Classpath is an environment variable that is used by the application ClassLoader or system to locate and load the compiled Java bytecodes stored in the . class file. To set CLASSPATH. the CLASSPATH can be overridden by adding classpath in the manifest file and by using a command like set -classpath.


1 Answers

Try this:

  <pathconvert property="expanded.main.class.path" refid="main.class.path"/>    <target name="everything">     <echo message="${expanded.main.class.path}"           file="${dist.dir}/deps.txt"/>   </target> 
like image 88
hmjd Avatar answered Oct 27 '22 04:10

hmjd