I am having some problems developing a Maven project
with Eclipse
. I tried to search on the net, but there is nothing similar.
To sum up, I am using the WFSDataStore (geotools) to get the collection of features from an XML and then adding to a Database.
There are two different behaviours:
Run As > Java Application
everything is correct and the code is working.When I do Run As > Maven
(clean install tomcat:run-war
). There is an error on line dataStoreBD = DataStoreFinder.getDataStore(params);, where dataStore is null:
(If you want to check the getCapabilities parameter)
public static void dataAccess(String getCapabilities, WFSDataStoreFactory dsf) throws Exception {
// Variables
// WFS Connection
Map connectionParameters = new HashMap();
connectionParameters.put(WFSDataStoreFactory.URL.key, getCapabilities);
connectionParameters.put(WFSDataStoreFactory.PROTOCOL.key, false);
connectionParameters.put(WFSDataStoreFactory.LENIENT.key, true);
connectionParameters.put(WFSDataStoreFactory.MAXFEATURES.key, "5");
connectionParameters.put(WFSDataStoreFactory.TIMEOUT.key, 600000);
// Database Connection
DataStore dataStoreBD = null;
Transaction transaction = null;
Filter filter = null;
Map<String, String> params = new HashMap<String, String>();
params.put("dbtype", configTypeDatabase);
params.put("host", configIp);
params.put("port", configPort);
params.put("schema", configUser);
params.put("database", configDatabase);
params.put("user", configUser);
params.put("passwd", configPassword);
params.put("accessToUnderlyingConnectionAllowed", true);
dataStoreBD = DataStoreFinder.getDataStore(params);
// Etc. }
The parameters are correct. I am getting them from a configuration file stored in my computer and I debugged like a thousand times to know what is really happening, but maybe there is a problem that I cannot see. After this code I have another piece:
SimpleFeatureSource initialBDFeatureSource = dataStoreBD.getFeatureSource(configDatesTable);
FeatureIterator<SimpleFeature> ifs = initialBDFeatureSource.getFeatures().features();
The first line ends the program with this error:
java.lang.NullPointerException at com.sitep.imi.acefat.server.daemon.InsertarBBDDDaemon.dataAccess(InsertarBBD DDaemon.java:972)
First of all, I deployed the project to try something else (using tomcat7
and adding the information of tomcat.xml
(project path from Eclipse's workspace
) to context.xml (tomcat7
path: C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf
).
Then I was studying the connections (pool
, jndi
and jdbc
) because I was not able to connect properly to my database. That is why I endeded up changing the jdbc
(a general-purpose interface to relational databases) connection to jndi
(a general-purpose interface to naming systems) connection, like the following:
Map<String, String> params = new HashMap<String, String>();
params.put("dbtype", configTypeDatabase);
params.put("jndiReferenceName", "java:comp/env/jdbc/DBName");
params.put("accessToUnderlyingConnectionAllowed", true);
params.put("schema", configUser);
I omit some parameters because they are not significant nor irrelevant for jndi
connection. The reason why is a little bit tricky because after resolving it I can't even explain it. For ever reason when I tried to run the Java Application
or option 1
locally it always worked, but I defined the connection as a lookup (<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/DBName"/>
) so it only works with jndi
when you have to run or deploy it with maven
.
If I find more information I will update my answer to clear my it or improve it.