You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Paolo <pa...@wci.ath.cx> on 2008/04/15 17:35:19 UTC

NullPointerException with ant Javac() api

Hello,
I'm new to ant api. i would like to compile a source from my
application, and i wrote the method below.

When i execute it, i get a NullPointerException at
org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:807)

where it says: File srcDir = getProject().resolveFile(list[i]);
(it's on the last instruction of this snippet, task.execute())

so i guess i screwed up with all the Path stuff..
But how to create and set up a Path object to feed Javac object?
thanks in advance,
Paolo



	public void subsystemCreate(String id, String poolSize) {
	
		String beanName = "BpsAgent"+id;
		String jbossHome =
System.getProperty("jboss.home.dir"+"/"); String serverHome =
System.getProperty("jboss.server.home.dir"+"/"); String tmpDir =
System.getProperty("jboss.server.home.dir")+"/deploy/"+appName+".ear/tmp/src/com/mersy/batch/mdb/";
String appDir =
System.getProperty("jboss.server.home.dir")+"/deploy/"+appName+".ear/";
String src =
System.getProperty("jboss.server.home.dir")+"/deploy/"+appName+".ear/tmp/src/";
String dst =
System.getProperty("jboss.server.home.dir")+"/deploy/"+appName+".ear/tmp/bin/";
System.out.println(beanName); System.out.println(jbossHome);
System.out.println(serverHome); System.out.println(tmpDir);
		System.out.println(appDir);
		System.out.println(src);
		System.out.println(dst);
		
		
		boolean success = (new File(tmpDir)).mkdirs();
	    if (!success) {
	        System.out.println("Megaerrore1");
	        return ;
	    }
	    
		File dstPath=new File(dst);
		success = (dstPath.mkdirs());
	    if (!success) {
	        System.out.println("Megaerrore2");
	        return ;
	    }
	    
	    createMdb(id,poolSize,tmpDir);
	    
	    
		Project project = new Project();
		Path path = new Path(project);
		path.setPath(jbossHome+"/lib/hibernate3.jar;" +
				serverHome+"/lib/ejb3-persistence.jar;"
+ serverHome+"/lib/hibernate-annotations.jar;"+
				serverHome+"/lib/jboss-remoting.jar;"+
				serverHome+"/deploy/ejb3.deployer/jboss-ejb3.jar;"+
				serverHome+"/deploy/ejb3.deployer/jboss-ejb3x.jar;"+
				serverHome+"/deploy/ejb3.deployer/jboss-annotations-ejb3.jar;"+
				appDir+"/locallib/javaee.jar;"+
				appDir+"/locallib/a001llayer.jar;"+
				serverHome+"/lib/log4j.jar");
		
		Path srcPath=new Path(project);
		srcPath.setPath(src);
		

		
		Javac task = new Javac();
		
		task.setSrcdir(srcPath);
		task.setDestdir(dstPath);
		task.setClasspath(path);
		
		task.execute();




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: NullPointerException with ant Javac() api

Posted by Paolo <pa...@wci.ath.cx>.
Thank you very much! that did the trick!

And thanks for the link!
Paolo

On Wed, 16 Apr 2008 07:24:36 +0200
<Ja...@rzf.fin-nrw.de> wrote:

> Your task doesnt have a reference to your project, therefore 
>     task.getProject() returns null
> 
> Try setting the project reference
>     task.setProject(project);
>     task.execute();
> 
> 
> Maybe you want to have a look at Leafcutter
> https://leafcutter.dev.java.net/
> 
> 
> Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: NullPointerException with ant Javac() api

Posted by Ja...@rzf.fin-nrw.de.
Your task doesnt have a reference to your project, therefore 
    task.getProject() returns null

Try setting the project reference
    task.setProject(project);
    task.execute();


Maybe you want to have a look at Leafcutter
https://leafcutter.dev.java.net/


Jan


> -----Ursprüngliche Nachricht-----
> Von: Paolo [mailto:paolo@wci.ath.cx] 
> Gesendet: Dienstag, 15. April 2008 17:35
> An: user@ant.apache.org
> Betreff: NullPointerException with ant Javac() api
> 
> Hello,
> I'm new to ant api. i would like to compile a source from my
> application, and i wrote the method below.
> 
> When i execute it, i get a NullPointerException at
> org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:807)
> 
> where it says: File srcDir = getProject().resolveFile(list[i]);
> (it's on the last instruction of this snippet, task.execute())
> 
> so i guess i screwed up with all the Path stuff..
> But how to create and set up a Path object to feed Javac object?
> thanks in advance,
> Paolo
> 
> 
> 
> 	public void subsystemCreate(String id, String poolSize) {
> 	
> 		String beanName = "BpsAgent"+id;
> 		String jbossHome =
> System.getProperty("jboss.home.dir"+"/"); String serverHome =
> System.getProperty("jboss.server.home.dir"+"/"); String tmpDir =
> System.getProperty("jboss.server.home.dir")+"/deploy/"+appName
> +".ear/tmp/src/com/mersy/batch/mdb/";
> String appDir =
> System.getProperty("jboss.server.home.dir")+"/deploy/"+appName
> +".ear/";
> String src =
> System.getProperty("jboss.server.home.dir")+"/deploy/"+appName
> +".ear/tmp/src/";
> String dst =
> System.getProperty("jboss.server.home.dir")+"/deploy/"+appName
> +".ear/tmp/bin/";
> System.out.println(beanName); System.out.println(jbossHome);
> System.out.println(serverHome); System.out.println(tmpDir);
> 		System.out.println(appDir);
> 		System.out.println(src);
> 		System.out.println(dst);
> 		
> 		
> 		boolean success = (new File(tmpDir)).mkdirs();
> 	    if (!success) {
> 	        System.out.println("Megaerrore1");
> 	        return ;
> 	    }
> 	    
> 		File dstPath=new File(dst);
> 		success = (dstPath.mkdirs());
> 	    if (!success) {
> 	        System.out.println("Megaerrore2");
> 	        return ;
> 	    }
> 	    
> 	    createMdb(id,poolSize,tmpDir);
> 	    
> 	    
> 		Project project = new Project();
> 		Path path = new Path(project);
> 		path.setPath(jbossHome+"/lib/hibernate3.jar;" +
> 				serverHome+"/lib/ejb3-persistence.jar;"
> + serverHome+"/lib/hibernate-annotations.jar;"+
> 				serverHome+"/lib/jboss-remoting.jar;"+
> 				
> serverHome+"/deploy/ejb3.deployer/jboss-ejb3.jar;"+
> 				
> serverHome+"/deploy/ejb3.deployer/jboss-ejb3x.jar;"+
> 				
> serverHome+"/deploy/ejb3.deployer/jboss-annotations-ejb3.jar;"+
> 				appDir+"/locallib/javaee.jar;"+
> 				appDir+"/locallib/a001llayer.jar;"+
> 				serverHome+"/lib/log4j.jar");
> 		
> 		Path srcPath=new Path(project);
> 		srcPath.setPath(src);
> 		
> 
> 		
> 		Javac task = new Javac();
> 		
> 		task.setSrcdir(srcPath);
> 		task.setDestdir(dstPath);
> 		task.setClasspath(path);
> 		
> 		task.execute();
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org