File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes javac command is too long to type in DOS window.  Solution? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javac command is too long to type in DOS window.  Solution?" Watch "javac command is too long to type in DOS window.  Solution?" New topic
Author

javac command is too long to type in DOS window. Solution?

sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
I think I need to enter this javac command to compile a servlet:

javac -classpath C:\jakart-tomcat-5.5.9\common\lib\servlet-api.jar;C:\servlets+jsp\beerV1\src -d classes src\com\example\web\BeerSelect.java


but the DOS window cuts off the command at

...src\com\example\web\Bee

What can I do? Do I have to add the -classpath directories to my CLASSPATH environment variable to shorten the command?
Cm Ananth
Ranch Hand

Joined: Oct 20, 2005
Posts: 44
I will suggest to make a .BAT file and put the commands in it, and if you need to compile the servlet, just call the .BAT file..


By Ananth, Bangalore
abhijit Ohal
Ranch Hand

Joined: Mar 10, 2006
Posts: 64
Use ant for compiling building your webapplication

http://www.roseindia.net/jboss/10_minutes_guide_to_ant.shtml
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Moving to Java In General where javac and classpath issues are discussed.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by abhijit Ohal:
Use ant for compiling building your webapplication


Well, of course, Ant is pretty good. But sometimes it's not a bad idea to do stuff from scratch, so you know what a build tool is doing. And other times, using a build tool might be overkill.

The command line quoted does not look particularly long. Are you sure you can't just keep typing, when the cursor gets to the end of the first line? That works fine for me. I have had problems when my Jam-generated build command line reached several thousand characters, but yours is only tens of characters.

Your command line is a bit long to keep typing in, however. So the suggestion of using a batch file is not a bad one. You can do something like this (untested):


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
The command line quoted does not look particularly long.

Your command line is a bit long to keep typing in, however.

Huh?

My DOS window won't accept more than this:

javac -classpath C:\jakart-tomcat-5.5.9\common\lib\servlet-api.jar;C:\servlets+jsp\beerV1\src -d classes src\com\example\web\Bee


The cursor is frozen after that.

I'm not sure what this does:
REM Use SETLOCAL so the calling command-line does not see changes
SETLOCAL

SET CLASSPATH=%CLASSPATH%;mypath\myjar.jar;anotherpath\anotherjar.jar;mydir
javac -d classes MyClass.java

ENDLOCAL


1) Does that permanently change the CLASSPATH environment variable? (Nope. Temporarily changes the CLASSPATH variable until ENDLOCAL is encountered.)

2) The last part of the SET line doesn't fit the pattern: all the other parts between semi-colons are directories. How does putting a javac command in the CLASSPATH environment variable work?

3)
if you need to compile the servlet, just call the .BAT file..

How do I call the .bat file?
[ October 03, 2006: Message edited by: sven studde ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Which OS are you using? Win9x? To get the DOS prompt, do you type command.com or cmd.exe? command.com allows a shorter line than cmd.exe.

To use a bat file, you type the commands, one per line. So
SET CLASSPATH=%CLASSPATH%;mypath\myjar.jar;anotherpath\anotherjar.jar;mydir
javac -d classes MyClass.java
is two commands -- one to set the classpath and the other to run the javac command. You would save the file that you put this in as myBat.bat and you would call it by typing
myBat
on the command line.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
Originally posted by Marilyn de Queiroz:
Which OS are you using? Win9x?

win98

To get the DOS prompt, do you type command.com or cmd.exe?

I click on Start\Programs\MS-DOS Prompt. Looking at the properties of that link it says:

Program tab
----------
Cmd line: C:\WINDOWS\COMMAND.COM

It looks like there are some settings I could change for the DOS window.

To use a bat file, you type the commands, one per line. So
SET CLASSPATH=%CLASSPATH%;mypath\myjar.jar;anotherpath\anotherjar.jar;mydir
javac -d classes MyClass.java
is two commands -- one to set the classpath and the other to run the javac command.

I'm not sure I understand. If you're supposed to type one command per line, shouldn't it be:

SETLOCAL

SET CLASSPATH=%CLASSPATH%;mypath\myjar.jar;anotherpath\anotherjar.jar

mydir javac -d classes MyClass.java

ENDLOCAL

And, what is mydir? (Ah. Is mydir another classpath?)
[ October 04, 2006: Message edited by: sven studde ]
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
I tried running this file(compile.bat):

REM this is a batch file to run a long javac command that wouldn't fit in a DOS window

SETLOCAL

SET CLASSPATH=%CLASSPATH%;C:\jakart-tomcat-5.5.9\common\lib\servlet-api.jar;C:\servlets+jsp\beerV1\src
javac -d classes src\com\example\web\BeerSelect.java

ENDLOCAL


Here is the DOS window output:

C:\servlets+jsp\beerV1>compile.bat

C:\servlets+jsp\beerV1>REM this is a batch file to run a long javac command that
wouldn't fit in a DOS window

C:\servlets+jsp\beerV1>
C:\servlets+jsp\beerV1>SETLOCAL
Bad command or file name

C:\servlets+jsp\beerV1>
C:\servlets+jsp\beerV1>SET CLASSPATH=.;C:\javaPrograms;C:\servlets+jsp;C:\jakart
a-tomcat-5.5.9\common\lib\servlet-api.jar;C:\jakarta-tomcat-5.5.9\common\lib\jsp
-api.jar;C:\servlets+jsp\beerV1\src;C:\jakart-tomcat-5.5.9\common\lib\servlet-ap
i.jar;C:\servlets+jsp\beerV1\src
Out of environment space

C:\servlets+jsp\beerV1>javac -d classes src\com\example\web\BeerSelect.java

C:\servlets+jsp\beerV1>
C:\servlets+jsp\beerV1>ENDLOCAL
Bad command or file name

C:\servlets+jsp\beerV1>

[ October 04, 2006: Message edited by: sven studde ]
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
If you're using as brain-dead an OS as Win 9x, then sorry there's no SETLOCAL or ENDLOCAL.
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
Is there a workaround? Can I save %CLASSPATH% in a variable and then reset the CLASSPATH after compiling?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javac command is too long to type in DOS window. Solution?
 
Similar Threads
package does not exist error
Compiling servlets in DOS (over Tomcat)
ERRATA - O'Reilly's Head First Servlets and JSP
SimpleTagSupport compile error
Compile error