I have been struggling with this for hours now.
I am trying to run a Java class with maven and am getting the following error
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:418)
at java.util.Properties.load0(Properties.java:337)
at java.util.Properties.load(Properties.java:325)
at com.services.utils.EnvHandler.getProperty(EnvHandler.java:26)
at com.services.agentsMonitor.MonitorAgentsTrigger.main(MonitorAgentsTrigger.java:77)
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project SupportUtilities:
An exception occured while executing the Java class. null:
InvocationTargetException: NullPointerException
The thing is I have been able to execute the project successfully when running from eclipse but not from the command prompt
This is my pom.xml where I have configured exec-maven-plugin v1.5.0
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.services</groupId>
<artifactId>SupportUtilities</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mockito.version>1.9.0</mockito.version>
<platform.messaging-jms-client.version>3.6.2.2</platform.messaging-jms-client.version>
<tibco.jms.client.version>7.0.1</tibco.jms.client.version>
<omslite.version>0.0.1-SNAPSHOT</omslite.version>
<logmon-parent-pom>2.2.2</logmon-parent-pom>
<fasterxml.jackson.jsonSchema>2.4.0</fasterxml.jackson.jsonSchema>
<fasterxml.jackson.databind>2.4.0</fasterxml.jackson.databind>
<fasterxml.jackson.core>2.4.0</fasterxml.jackson.core>
<ojdbc6.version>12.1.0.2.0</ojdbc6.version>
<commons-lang.version>2.1</commons-lang.version>
<log4j.version>1.2.16</log4j.version>
<json-simple.version>1.1</json-simple.version>
<apache.commons.io.version>1.4.0</apache.commons.io.version>
<netty.version>3.2.10.Final</netty.version>
<javax.jms.version>1.1</javax.jms.version>
<org.slf4j.version>1.6.2</org.slf4j.version>
<joda-time.version>2.9</joda-time.version>
<sling.commons.json.version>2.0.12</sling.commons.json.version>
<jsch.version>0.1.51</jsch.version>
<xercesImpl.version>2.8.0</xercesImpl.version>
<httpclient.version>4.5.1</httpclient.version>
<javax.mail.version>1.5.0-b01</javax.mail.version>
<poi-ooxml.version>3.9</poi-ooxml.version>
<JSON4J.version>1.1.0</JSON4J.version>
<exec-maven-plugin.version>3.1</exec-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>${json-simple.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.io</artifactId>
<version>${apache.commons.io.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>tibco.jms</groupId>
<artifactId>tibco_jms</artifactId>
<version>${tibco.jms.client.version}</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>${javax.jms.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.walmart.platform.messaging</groupId>
<artifactId>messaging-jms-client</artifactId>
<version>${platform.messaging-jms-client.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.json</artifactId>
<version>${sling.commons.json.version}</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>${jsch.version}</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xercesImpl.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${javax.mail.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi-ooxml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>JSON4J</artifactId>
<version>${JSON4J.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${fasterxml.jackson.core}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${fasterxml.jackson.databind}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
<version>${fasterxml.jackson.jsonSchema}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin> -->
</plugins>
</build>
</project>
The problem is that my code is not able to load a file that is located in my resources folder.
Below is the code for the EnvHandler Class that is there in my com.services.utils package
public Properties getProperty(String env, String mgmtSystem) throws IOException {
Properties prop = new Properties();
InputStream propFile = null;
/*
* Loading based on OMS/IMS
*/
if("OMS".equalsIgnoreCase(mgmtSystem)) {
/*
* Loading the properties file based on environment qa/qa2/prod
*/
if("qa".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/OMS/Credentials_qa.properties"); //I have error here
System.out.println("PropFile->" + propFile.toString());
prop.load(propFile);
return prop;
}
else if("qa2".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/OMS/Credentials_qa2.properties");
prop.load(propFile);
return prop;
}else if("prod".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/OMS/Credentials_prod.properties");
prop.load(propFile);
return prop;
}
} else if("IMS".equalsIgnoreCase(mgmtSystem)) {
/*
* Loading the properties file based on environment qa/qa2/prod
*/
if("qa".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/IMS/Credentials_qa.properties");
prop.load(propFile);
return prop;
}
else if("qa2".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/IMS/Credentials_qa2.properties");
prop.load(propFile);
return prop;
}else if("prod".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/IMS/Credentials_prod.properties");
prop.load(propFile);
return prop;
}
}
return null;
}
Any help is highly appreciated.
Please comment if you need any more information
Update: Below is my project structure
--src/main/java
--com.services.agentsMonitor
--MonitorAgentsForTrigger.java
--com.services.logsMonitor
--MonitorLogsForConnectionIssues.java
--com.services.utils
--EnvHandler.java
--src/main/resources
--com.services.agentsMonitor
--OMS
--Credentials_qa.properties
--Credentials_qa2.properties
--Credentials_prod.properties
--IMS
--Credentials_qa.properties
--Credentials_qa2.properties
--Credentials_prod.properties