I am working on a shell script where i will call a jar file.
When i execute the shell script the i get a return code 1 from call to java. Also console output jar file is not printed in the terminal
javaArgs="-jar $baseRoot/lib/preprocess.jar"
javaCmd="java $javaArgs \"$filePath1\" \"$filePath2\"";
echo $javaCmd
$javaCmd
recode=$?
echo $recode
output
When i directly run the jar file in terminal i got the expected output and also do not get warnings.
java -jar /shelldir/lib/preprocess.jar "/shelldir/data/file1.txt" "/shelldir/data/file1.xml"
How to get the console output of jar file when running from shell script ?
Addtional Info: I am executing the shell script from putty bash terminal. EDIT: I use log4j in jar and build my jar using maven-shade-plugin and maven-jar-plugin to specify classpath. The conf folder mentioned in the below pom has the log4j.properties file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.file.PreProcessor</mainClass>
</transformer>
</transformers>
<minimizeJar>false</minimizeJar>
<outputFile>lib/preprocess.jar</outputFile>
<!-- <outputDirectory>target\maven-shade</outputDirectory> -->
</configuration>
</execution>
</executions>
</plugin>
<!-- Command: mvn jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifestEntries>
<Class-Path>../conf/</Class-Path>
</manifestEntries>
<manifest>
<addDefaultEntries>true</addDefaultEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
<!-- <outputDirectory>lib</outputDirectory> -->
</configuration>
</plugin>
log4j.properties
#define the console appender
log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender
# now define the layout for the appender
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-4r [%t] %-5p %c{1} %x - %m%n
log4j.appender.traceLog=org.apache.log4j.RollingFileAppender
log4j.appender.traceLog.MaxFileSize=30MB
log4j.appender.traceLog.MaxBackupIndex=20
log4j.appender.traceLog.layout = org.apache.log4j.PatternLayout
log4j.appender.traceLog.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-4r [%t] %-5p %c{1} %x - %m%n
log4j.appender.infoLog=org.apache.log4j.RollingFileAppender
log4j.appender.infoLog.MaxFileSize=30MB
log4j.appender.infoLog.MaxBackupIndex=20
log4j.appender.infoLog.Threshold=INFO
log4j.appender.infoLog.layout = org.apache.log4j.PatternLayout
log4j.appender.infoLog.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-4r [%t] %-5p %c{1} %x - %m%n
# now map our console appender as a root logger, means all log messages will go to this appender
log4j.rootLogger = TRACE, infoLog,traceLog