NumberFormat Exception in Batch File but not Eclipse



Hello,

I'm not sure how to solve this issue.  The code in Eclipse is running but the batch file throws a number format exception: null

The issue is at the Integer.parseInt.

missingValue = getMissingValueInteger();

 private static int getMissingValueInteger()
    {
        String missingValueProperty = System.getProperty("missingValue");
        int parseIntegerMissingValue = Integer.parseInt(missingValueProperty);
        missingValue = parseIntegerMissingValue;
        return missingValue;
    }

Open in new window

AndyC1000Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
>>same problem as I fixed for you earier

You didn't unfortunately, since LOGFILE was still in the wrong place
0
 
objectsCommented:
looks like the system property is not being set
0
 
for_yanCommented:

Add
System.out.println("miissinvalue: " + missingValueProperty);
just before
 int parseIntegerMissingValue = Integer.parseInt(missingValueProperty);
       
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
AndyC1000Author Commented:
I debugged the code and it displayed the correct info in Eclipse.

I added an echo in the batch file it returned -DmissingValue=-1 which is the value I passed in using:
SET MISSING_VALUE=-DmissingValue=-1

then:

java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib <package name>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %MISSING_VALUE% %LOGFILE%

0
 
AndyC1000Author Commented:
I meant to write it displayed the correct value.
0
 
AndyC1000Author Commented:
Could it be a missing library to do with number parsing?
0
 
for_yanCommented:

But you are saying that when you run it

java -DmissingValue="-1"  class_name

it actually works? That seems reasonable looking at the code.
Then what is the issue?
0
 
objectsCommented:
try this:

java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib %MISSING_VALUE% <package name>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME%  %LOGFILE%
0
 
AndyC1000Author Commented:
The batch file throws a number format exception at:

missingValue = getMissingValueInteger();

 private static int getMissingValueInteger()
    {
        String missingValueProperty = System.getProperty("missingValue");
        int parseIntegerMissingValue = Integer.parseInt(missingValueProperty); <---- here
        missingValue = parseIntegerMissingValue;
        return missingValue;
    }

Open in new window


The strange thing is it works in Eclipse, and I've debugged the method and the correct value is returned.
0
 
Sathish David Kumar NArchitectCommented:
I think its comes with sepace! jsut trim that !!
0
 
AndyC1000Author Commented:
objects and dravidnsr I used both your suggestions and it worked - there are no errors and the output file is created.

The logging component isn't working when running the batch file.  I've checked the classpath and the jar exists. -classpath bin;lib/log4j-1.2.14.jar;  Any suggestions?

I'm using org.apache.log4j.Logger;

::// Batch File 

@ECHO ON
ECHO STARTED Batch..

if not "%JAVA_HOME%" == "" goto javaHomeAlreadySet
for %%P in (%PATH%) do if exist %%P\java.exe set JAVA_HOME=%%P..\
:javaHomeAlreadySet

:: Directory and file locations
SET INPUT_DIR=data/adaptor/input/State
SET OUTPUT_DIR=data/adaptor/output
SET OUTPUT_FILENAME=output
SET MISSING_VALUE=-DmissingValue=-1 
SET LOGFILE=-DlogFile_var=data\adaptor\logger

:: Date for log file
FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
FOR /F "tokens=5 delims= " %%A in ('echo ^| time ^| find "current" ') DO FOR %%B IN (%%A) DO SET Now=%%B
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
    SET Day=%%A
    SET Month=%%B
    SET Year=%%C
)
FOR /F "tokens=1-3 delims=:.-" %%A IN ("%Now%") DO (
    SET Hour=%%A
    SET Min=%%B
    SET Sec=%%C
)
:: Log file prefix
SET LOGDIR=%Year%-%Month%-%Day%_%Hour%%Min%%Sec%
:: Read and convert output

@ECHO ON

ECHO STARTING 


:: How to run program here-->
java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib %MISSING_VALUE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %LOGFILE%


ECHO FINISHED READING and converting output
::ECHO File %OUTPUTDIR%%OUTPUT_FILENAME%.xml has been created.

pause

:END
ECHO ...End Batch
@ECHO ON

Open in new window





0
 
CEHJCommented:
>>
:: How to run program here-->
java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib %MISSING_VALUE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %LOGFILE%
>>



You're not passing the variables to java properly. You specify them as jvm args but use them as normal program args. You need
java  %MISSING_VALUE% %LOGFILE% -classpath etcetera

Open in new window

0
 
CEHJCommented:
btw, your batch file also seems to reverse the intended meanings of LOGFILE and LOGDIR
0
 
gordon_vt02Commented:
Where is your log4j.properties/xml file located, or are you configuring log4j programmatically based on the LOGFILE parameter to your app?  Check your config file too.  If it uses relative paths for the log file, it may be showing up somewhere unexpected based on the working directory when you run the batch file.

Also, if you're using JDK 1.6, you can clean up your classpath a little by using wildcards:

java -classpath bin;lib/* ...

That will load any .jar files in the lib directory into the classpath.
0
 
AndyC1000Author Commented:
I forgot to add the log4j.properties file.

I've inserted log4j.properties into the lib folder and updated the classpath:

java  -classpath bin;lib\*;lib\log4j.properties;.\lib %MISSING_VALUE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %LOGFILE%

Open in new window


Although it still doesn't work.

In my properties file I have:
log4j.appender.rollingFile.File = ${logFile_var}/mylog.log

Notice I set the below in the batch:
SET LOGFILE=-DlogFile_var=data\adaptor\logger

Could this be the problem?  The logging worked in the eclipse project.


0
 
CEHJCommented:
In that case

>>log4j.appender.rollingFile.File = ${logFile_var}/mylog.log

should be more like

>>log4j.appender.rollingFile.File = ${LOGFILE}/mylog.log

(but see my comments above about your log paths)
0
 
objectsCommented:
same problem as I fixed for you earier

command line sjhould be:


java  -classpath bin;lib\*;lib\log4j.properties;.\lib %MISSING_VALUE%  %LOGFILE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME%

only put args for your app after the class, args for the vm (like system properties) go before the class
0
 
AndyC1000Author Commented:
Thanks that worked!

The only problem with my batch is specifying the name of the log file.

:: Date for log file
FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
FOR /F "tokens=5 delims= " %%A in ('echo ^| time ^| find "current" ') DO FOR %%B IN (%%A) DO SET Now=%%B
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
    SET Day=%%A
    SET Month=%%B
    SET Year=%%C
)
FOR /F "tokens=1-3 delims=:.-" %%A IN ("%Now%") DO (
    SET Hour=%%A
    SET Min=%%B
    SET Sec=%%C
)
:: Log file prefix
SET LOG_FILENAME=%Year%-%Month%-%Day%_%Hour%%Min%%Sec%

Then I'm adding to the log4j.properties:
log4j.appender.rollingFile.File = ${LOGDIR}/${LOG_FILENAME}.log

Do I need to insert the argument into eclipse and build/ export again?

Open in new window

0
 
AndyC1000Author Commented:
Do I need to insert the argument into eclipse and build/ export again?
0
 
objectsConnect With a Mentor Commented:
> log4j.appender.rollingFile.File = ${LOGDIR}/${LOG_FILENAME}.log

why did you change the log4j config? What you had before was fine

log4j.appender.rollingFile.File = ${logFile_var}/mylog.log

> Do I need to insert the argument into eclipse and build/ export again?

SHouldn't need to. the only problem was with your batch file
0
 
objectsCommented:
> SET LOG_FILENAME=%Year%-%Month%-%Day%_%Hour%%Min%%Sec%

the rolling file appender will handle naming the file for you.
what you originally had is all you need
0
 
CEHJCommented:
>>Thanks that worked!

Good - glad i could help. (Posted at http:#35016001 )
0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.