Home arrow static arrow Java Programming [Archive] - How to change current directory?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - How to change current directory?
10 Duke Stars available
This topic has 5 replies on 1 page.

Posts:5
Registered: 11/19/03
How to change current directory?  
Dec 19, 2003 7:36 AM



 
Hello all,
I want to write a program that can compile , run , and make jar file. So I do the following:
/** for compile **/
String[] ja =
{getJavaHome() + "javac.exe",
"-g", "-sourcepath", src + CheckName.SLASH,
"-d", out,
fileCompile.getAbsolutePath()
};

/** for run **/
String[] ja = {
getJavaHome() + "javaw.exe",
"-classpath", classpath,
className
};

/** for jar file **/
String[] ja = {
getJavaHome() + "jar.exe",
"cvf", jarFile, "-C" , inputDir ,
"."};

My errors are:
FOR COMPILE: I can compile and get the error, but if the compiled file relate to another file,

both will be compile to 2 .class files ( I check the output directory), but my application seem to

be dead.

FOR RUN:
I can run, but if the running file throw some Exception, my application seem to be dead too.

FOR JAR:
If I used the above approach, I encounter:
java.util.zip.ZipException: attempt to write past end of STORED entry at

java.util.zip.ZipOutputStream.write(ZipOutputStream.java:266) at

sun.tools.jar.Main.addFile(Main.java:615) at sun.tools.jar.Main.create(Main.java:413)

at sun.tools.jar.Main.run(Main.java:143) at sun.tools.jar.Main.main(Main.java:904)
added manifestadding: xmgrid/(in = 0) (out= 0)(stored 0%)adding: xmgrid/xmatrixes.class(in =

5572) (out= 3109)(deflated 44%)adding: xmgrid/XMVector1.class(in = 376) (out= 275)(deflated

26%)adding: test.jar

****So I used another approach:
System.setProperty("user.dir" , inputDir );
String[] ja = {
getJavaHome() + "jar.exe",
"cvf" , jarFile , "*"
};

Where [ inputDir ] is the directory that contains all files I want to add to the JAR file.(e.g:

inputDir="C:
Input")
I run my application at the directory [ C:\\myapplication\class ], the application can create a JAR

archive but it add all the file at the current direcry --> [ C:\\myapplication\class ] ,
So how can I do if I want to change the current directory? I've tried to create a new properties

and set it but ...
I run all the commands above using Runtime.exec( String[] )
Any helps or suggestions on any errors , PLEASE???


 

Posts:3,055
Registered: 18/06/98
Re: How to change current directory?  
Dec 19, 2003 7:41 AM (reply 1 of 5)



 
Instead of doing that, why do not download and use the Ant program? ( http://ant.apache.org/ )
It does it all (compiles Java files, make jar files, changes the directory etc.)
Learn to write Ant scripts, and use your time for writing applications.
 

Posts:90
Registered: 7/29/97
Re: How to change current directory?  
Jul 8, 2004 7:09 PM (reply 2 of 5)



 
You can be interested in much smaller tool but more powerfull than ant with <100KB footprint. Check it out at: http://www.gena.crocodile.org/bee/index-bee.html
It does directory changing as you request, and since sources availalbe you can borrow the idea.
 

Posts:24,036
Registered: 2/3/03
Re: How to change current directory?  
Jul 8, 2004 7:13 PM (reply 3 of 5)



 
You can be interested in much smaller tool but more powerfull than ant

:o)
 

Posts:90
Registered: 7/29/97
Re: How to change current directory?  
Jul 9, 2004 11:18 AM (reply 4 of 5)



 
:o)
I had the same emotions when compared Microsoft's and Borland's Pascal compilers in 1986
 

Posts:90
Registered: 7/29/97
Re: How to change current directory?  
Jul 9, 2004 11:25 AM (reply 5 of 5)



 
I noticed a Bug ID: 4117557 which in progress. When it will be fixed, the problem will be solved in a simple way. Check the bug description and status.
 
This topic has 5 replies on 1 page.