ant execute java class

    In the use of ant a few days ago, I think it is easier to automate it. It is very troublesome to open eclipse to generate files every time. It is better to execute ant directly. Wouldn't it be nice to have a cup of tea in comfort?

    So let's get started.

ant is actually very simple to execute java, the following words can be done

<target name="run" depends="compile,build">
   <java fork="true" classname="com.XXX.Testmain">
     <classpath >
        <pathelement path="classes"/>      
      </claspath>
     <arg value="arg1"/>
   </java>
 </target>

 But what if you want to reference other projects, or add jar packages?

<target name="gen" description="Execute java program to generate dto">
		<java
		<java classname="com.XXX.GenMain">
			 <classpath>
			 	  <pathelement path="classes"/>
			 	  <pathelement path="../Common/classes"/>
			 	</classpath>
			 	<classpath>
			 		<fileset dir="lib" includes="**/*.jar"/>
			 		<fileset dir="../sharedlibs" includes="**/*.jar"/>
			 	</classpath>
		</java>
</target>

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326876560&siteId=291194637