I have created a Jersey project from the Maven archetype jersey-quickstart-webapp on NetBeans. And I'm using ActiveJDBC for data persistence. In its documentation it's possible to reference an external file for database connection properties: http://javalite.io/database_connection_management#location-of-property-file
I have followed the instructions and I have this activejdbc.properties
(located at project-ws/src/main/) file content:
env.connections.file=C:\dev\database.properties
And the database.properties
file:
development.driver=com.mysql.jdbc.Driver
development.username=user_db
development.password=*****
development.url=jdbc:mysql://192.168.0.19/customersdb
test.driver=com.mysql.jdbc.Driver
test.username=user_db
test.password=*****
test.url=jdbc:mysql://192.168.0.19/customersdb
production.jndi=java:comp/env/jdbc/acme
Also, I have this web service:
@Path("telephone")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class TelephoneResource {
@GET
public Response get() {
try {
Base.open();
LazyList<Telephone> tels= Telephone.findAll();
String telsJson = tels.toJson(true);
Base.close();
return Response.ok().entity(telsJson).build();
} catch (Exception ex) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\": \"" + ex.getMessage() + "\"}").build();
}
}
}
But when I try to execute that GET resource, I receive this error message:
{
"error": "Could not find configuration in a property file for environment: development. Are you sure you have a database.properties file configured?"
}
I also have tried this other configurations:
- http://javalite.io/database_connection_management#environment-variables-override
- http://javalite.io/database_connection_management#system-properties-override
By adding them to the pom.xml
file using the maven-surefire-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<systemPropertyVariables>
<activejdbc.url>jdbc:mysql://192.168.0.19/customersdb</activejdbc.url>
<activejdbc.user>user_db</activejdbc.user>
<activejdbc.password>*****</activejdbc.password>
<activejdbc.driver>com.mysql.jdbc.Driver</activejdbc.driver>
</systemPropertyVariables>
<environmentVariables>
<ACTIVEJDBC.URL>jdbc:mysql://192.168.0.19/customersdb</ACTIVEJDBC.URL>
<ACTIVEJDBC.USER>user_db</ACTIVEJDBC.USER>
<ACTIVEJDBC.PASSWORD>*****</ACTIVEJDBC.PASSWORD>
<ACTIVEJDBC.DRIVER>com.mysql.jdbc.Driver</ACTIVEJDBC.DRIVER>
</environmentVariables>
</configuration>
</plugin>
But they also did not work.