You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Sundberg Jukka <Ju...@aldata.fi> on 2001/12/13 13:26:47 UTC

compiler feature

Running a following target causes ant to create two instances of the java
class:

	<!--
============================================================================
= -->
	<!-- for testing
-->
	<!-- USAGE: BUILD test -Dname=my.package.Test -Darg1=120
-Darg2=huhuu etc -->
	<!--
============================================================================
= -->
	<target name="test">
		<java classname="${name}">
			<arg value="${arg1}"/> 
			<arg value="${arg2}"/> 
			<arg value="${arg3}"/> 
			<arg value="${arg4}"/> 
			<arg value="${arg5}"/> 
			<arg value="${arg6}"/> 
			<arg value="${arg7}"/> 
			<arg value="${arg8}"/> 
			<classpath refid="my.classpath"/>
		</java>
	</target>

In here BUILD is .bat file with a following call:

         call ant %1 %2 %3 %4 %5 %6 %7 %8 %9 -buildfile c:/myBuild/build.xml

Here is the my.package.Test class:

package my.package;
public class Test{
	public Test(){
      	System.out.println("Should be here only once");
	}
	public void testing(){
		System.out.println("Testing, testing");
	}
    	public static void main(String[] args){
		Test ts = new Test();
		ts.testing();	
	}
}

And surprise here is the result:
	Should be here only once
	Should be here only once
	Testing, testing

I didn't find any fix in nightly builds, and I didn't find it in bugdb. Has
anyone encountered this feature? How do I get aroung it?

Thanks,

Jukka Sundberg






--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compiler feature

Posted by Nico Seessle <ni...@apache.org>.
----- Original Message -----
From: "Sundberg Jukka" <Ju...@aldata.fi>
To: <an...@jakarta.apache.org>
Sent: Thursday, December 13, 2001 1:26 PM
Subject: compiler feature


> Running a following target causes ant to create two instances of the java
> class:
>
This is probably caused by the AntClassLoader:

--- cut ---
    /**
     * Force initialization of a class in a JDK 1.1 compatible, albeit hacky
     * way
     */
    public static void initializeClass(Class theClass) {
        // ***HACK*** We try to create an instance to force the VM to run
the
        // class' static initializer. We don't care if the instance can't
        // be created - we are just interested in the side effect.
        try {
            theClass.newInstance();
        }
        catch (Throwable t) {
            //ignore - our work is done
        }
    }
--- cut ---

Sorry, no idea how to fix this.

Nico



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compiler feature

Posted by Diane Holt <ho...@yahoo.com>.
I can't say why it's doing this, but hopefully the following info might
give someone who knows Java better a pointer to figuring it out.

I tried reproducing it and found that if I don't include the <classpath>
element (ie., if I put the classfile in a jar and put that jar in
$ANT_HOME/lib), it doesn't do the duplication. But if I put the jar in
some other directory and include the <classpath>, then it does the
duplication. However, if I include the <classpath> element and also set
fork="true", then it doesn't do the duplication.

Debug output from the duplicating run shows:
     [java] Running in same VM Test ${arg1} ${arg2} ${arg3} ${arg4}
${arg5} ${arg6} ${arg7} ${arg8}
force loading Test
Finding class Test
Class java.lang.Object loaded from parent loader
Class java.lang.System loaded from parent loader
Class java.io.PrintStream loaded from parent loader
     [java] Should be here only once
Class java.lang.String loaded from parent loader
     [java] Should be here only once
     [java] Testing, testing

Diane

--- Sundberg Jukka <Ju...@aldata.fi> wrote:
> Running a following target causes ant to create two instances of the
> java
> class:
> 
> 	<!--
>
============================================================================
> = -->
> 	<!-- for testing
> -->
> 	<!-- USAGE: BUILD test -Dname=my.package.Test -Darg1=120
> -Darg2=huhuu etc -->
> 	<!--
>
============================================================================
> = -->
> 	<target name="test">
> 		<java classname="${name}">
> 			<arg value="${arg1}"/> 
> 			<arg value="${arg2}"/> 
> 			<arg value="${arg3}"/> 
> 			<arg value="${arg4}"/> 
> 			<arg value="${arg5}"/> 
> 			<arg value="${arg6}"/> 
> 			<arg value="${arg7}"/> 
> 			<arg value="${arg8}"/> 
> 			<classpath refid="my.classpath"/>
> 		</java>
> 	</target>
> 
> In here BUILD is .bat file with a following call:
> 
>          call ant %1 %2 %3 %4 %5 %6 %7 %8 %9 -buildfile
> c:/myBuild/build.xml
> 
> Here is the my.package.Test class:
> 
> package my.package;
> public class Test{
> 	public Test(){
>       	System.out.println("Should be here only once");
> 	}
> 	public void testing(){
> 		System.out.println("Testing, testing");
> 	}
>     	public static void main(String[] args){
> 		Test ts = new Test();
> 		ts.testing();	
> 	}
> }
> 
> And surprise here is the result:
> 	Should be here only once
> 	Should be here only once
> 	Testing, testing
> 
> I didn't find any fix in nightly builds, and I didn't find it in bugdb.
> Has
> anyone encountered this feature? How do I get aroung it?
> 
> Thanks,
> 
> Jukka Sundberg
> 
> 
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>