I am trying to setup flyway for a project with maven and i am unable to make it work. I have the correct configuration (db url, username, password) and i tried connecting to the DB with MySQL Workbench, PhPMyAdmin and also used the flyway command line tool and everything works except maven.
This is the error i am getting:
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:8.5.5:migrate (default-cli) on project flyway-fitinpulse: org.flywaydb.core.api.FlywayException: No database found to handle jdbc:mariadb://placeholderip:3306/db_name -> [Help 1]
And my pom.xml
<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>org.fitinpulse</groupId>
<artifactId>flyway-fitinpulse</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<configuration>
<url>jdbc:mariadb://placeholderip:3306/db_name</url>
<user>user</user>
<password>password</password>
</configuration>
</plugin>
</plugins>
</build>
Does anyone has any insight?
Have you tried adding <driver> </driver>
inside <configuration>?
Because otherwise the driver is auto-detected based on the url and this might lead to a connection problem I guess.
I finally found the problem. In newer version of the flyway for mysql you need to provide another flyway dependency along with the connection driver:
<dependencies>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
<version>8.5.5</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.0.4</version>
</dependency>
</dependencies>
Related
Hello Fellow Developers,
I am new to software development and looking forward to doing transitioning to software development.
I am learning new skills and tools to scale up and I came across DOCKER and KUBERNETES
I have completed my backend with spring boot, java and MYSQL I just wanted to know how to dockerize an image for the spring boot application in an industrial real-time manner just to get a hang of it.
Things to image
Environment: JAVA 17
Dependencies: POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.greatlearning.employeemanagementservice</groupId>
<artifactId>employeemanagementservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>employeemanagementservice</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<!-- spring security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Application-properties:
server.port=8082
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/empdb
spring.datasource.username=root
spring.datasource.password=*s12
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.main.allow-bean-definition-overriding=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
This is an employee management project with simple CRUD operation I have done. It would be helpful if someone can guide me through Docker image settings.
Pardon me, If it is inappropriate to post such questions in a stack overflow.
Try the follwoing Dockerfile. It performs a multi-stage build where in the first stage, your code is compiled to an executable. Then in the next stage, only the parts necessary for running your application are copied so that your Docker image has less size than if you copied all your uncompiled and compiled code in the Docker image. For more infomation about multi-stage builds, consult the official documentation or one of the countless internet tutorials.
FROM maven:3.8-openjdk-17 as maven
WORKDIR /app
COPY ./pom.xml .
RUN mvn dependency:go-offline
COPY ./src ./src
RUN mvn package -DskipTests=true
WORKDIR /app/target/dependency
RUN jar -xf ../employeemanagementservice.jar
FROM ibm-semeru-runtimes:open-17-jre-centos7
ARG DEPENDENCY=/app/target/dependency
COPY --from=maven ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=maven ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=maven ${DEPENDENCY}/BOOT-INF/classes /app
CMD java -server -Xmx1024m -Xss1024k -XX:MaxMetaspaceSize=135m -XX:CompressedClassSpaceSize=28m -XX:ReservedCodeCacheSize=13m -XX:+IdleTuningGcOnIdle -Xtune:virtualized -cp app:app/lib/* com.greatlearning.employeemanagementservice.Application
I made the following assumptions:
Your build artifact is named employeemanagementservice.jar. Check your target directory after your maven build to verify. I always configure it like this in the pom.xml
<build>
<finalName>${project.artifactId}</finalName>
</build>
You run your tests in a CI/CD pipeline and don't want to run them in the Docker image build step. If you wanted to run your tests you'd have to remove the -DskipTests=true from the RUN mvn package -DskipTests=true comannd.
Your main class is called Application and it resides in the com.greatlearning.employeemanagementservice package. If not, change it in the Docker CMD command.
You want your service to use at most 1GB of RAM. If not, change the -Xmx1024m to your desired amount. The other java arguments are for optimization purposes, you can look them up online.
I've 2 maven projects in my Eclipse (v4.7.0) workspace.
The first project contains some utility stuffs and holds the connection to my MySQL database through JDBC driver.
<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.example</groupId>
<artifactId>dbtools</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DBTools</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- JDBC for MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</project>
This first project is built as a jar and it is included in the second project (that contains the main application) as a maven dependency as shown in the pom.xml below:
<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.example</groupId>
<artifactId>mainapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>MainApp</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jersey2.version>2.25.1</jersey2.version>
<jaxrs.version>2.0.1</jaxrs.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<filesets>
<fileset>
<directory>C:/apps/tomcat/webapps/mainapp</directory>
<includes>
<include>**</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-appCtx</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>C:/apps/tomcat/webapps/</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>../mainapp/target</directory>
<includes>
<include>mainapp-0.0.1-SNAPSHOT.war</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JAX-RS -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${jaxrs.version}</version>
</dependency>
<!-- Jersey 2.25.1 -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey2.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey2.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey2.version}</version>
</dependency>
<!-- Local DBTool -->
<dependency>
<groupId>com.example</groupId>
<artifactId>dbtools</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
The 2nd project that is the main application is deployed as a war file.
When I start the Tomcat (with 2nd app's war) I got a SQLException at runtime:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false
at java.sql.DriverManager.getConnection(DriverManager.java:689)
I've read several question here in StackOverflow about this exception but I still haven't found a working solution :(
Inside the lib folder of my Tomcat installation folder I've placed the mysql-connector-java-6.0.6.jar.
I've also noticed that in the JAR file of the first project (opening it as an archive) there isn't the JDBC connector inside. Is it normal?
Inside the first project, I make the connection this way:
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/torre?autoReconnect=true&useSSL=false", "dbuser", "dbpass");
conn has type java.sql.Connection.
I've also tried to put:
Class.forName("com.mysql.jdbc.Driver");
before che "conn = ..." line but I got the same result :(
I'm using Tomcat 8.5 and JDK 1.8.
Any ideas how I can get rid of this problem?
Am I missing something in the Maven or Eclipse build configuration?
Thanks in advance for your help! :)
First of all get familiar with auto-class loading for JDBC 4.0 here.
Now, see contents of META-INF/services/java.sql.Driver which is com.mysql.cj.jdbc.Driver. Thus you are getting the exception.
Please update the mysql connector dependency of project1 to below
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
This will be automatically included in WEB-INF/lib of project2 thro' transitive dependency. Thus you do not need to include it in tomcat lib.
Remove the 6.0.6 mysql connector from the tomcat lib.
If still the issue persist, please try to register it explicitly before acquiring the connection
Class.forName("com.mysql.jdbc.Driver");
Providing input as per my understanding
you mentioned that
I've also noticed that in the JAR file of the first project (opening
it as an archive) there isn't the JDBC connector inside. Is it normal?
when you are building jar unlike war you will not find the dependencies[only one jar without maven-shade-plugin where it will not have its dependencies]
so use maven-shaded-plugin
https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.yourpackage.YourClass</Main-Class>
<X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
in your pom.xml [of project-1 for generating jar]
Now if you see u will be having two jars after maven build (one the original and the other jar with dependencies in pom)
if you extract the one which is having more size[the one with dependencies]
u can find the jdbc jar here
now for project 2
when you include project-1 as a dependency [make sure the one which is bigger is included instead of smaller one(without dependencies) ]
If you are using remote repository when u are pushing , the bigger one will get pushed
so when u mention it in pom [project-1] then the bigger jar will be downloaded
once after building it check the project-1 jar whether it is having its own dependencies
And finally build the war and deploy
Source : Worked on the same kind of Scenario, and it looks similar to the one I worked before
Let me know the result [Mostly it will work, if not mycontact :es12b1005#iith.ac.in will try to help]
Thanks :)
This question is here to give an answer to once i find a solution, I have found documentation on Postgresql and H2 databases from the jboss website and have seen how it is done manually through this website, however I cannot seem to find much information on how to deploy a mysql datasource using the jboss-as-maven-plugin.
What is the minimum configuration properties required to properly register a mysql datasource with jboss-as 7 server through their maven plugin?
I have this dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
And this configuration for the maven plugin
<build>
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<execute-commands/>
<executeCommands/>
<properties>
<enable-welcome-root>false</enable-welcome-root>
</properties>
</configuration>
<executions>
...
<!-- deploy the mysql connectorj -->
<execution>
<id>deploy-mysql-driver</id>
<phase>install</phase>
<goals>
<goal>deploy-artifact</goal>
</goals>
<configuration>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<name>mysql.jar</name>
</configuration>
</execution>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>add-datasource</id>
<phase>deploy</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources</address>
<resources>
<resource>
<address>xa-data-source=java:global/datasources/tncDS</address>
<enable-resource>true</enable-resource>
<properties>
<jndi-name>java:jboss/datasources/tncDS</jndi-name>
<enabled>true</enabled>
<connection-url>jdbc:mysql://localhost:3306/tnc</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-name>mysql.jar</driver-name>
</properties>
</resource>
</resources>
</configuration>
</execution>
</executions>
...
</plugin>
</plugins>
</build>
running the command mvn jboss-as:run causes this error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.241s
[INFO] Finished at: Tue Sep 24 21:37:28 EST 2013
[INFO] Final Memory: 16M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:deploy-artifact (deploy-mysql-driver) on project ear: Could not execute goal deploy-artifact on null. Reason: I/O Error could not execute operation '{
[ERROR] "address" => [],
[ERROR] "operation" => "read-attribute",
[ERROR] "name" => "launch-type"
[ERROR] }': java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
UPDATE:
I have developed a plugin that injects the required file (META-INF/services/java.sql.Driver) into the jar before deployment:
<plugin>
<groupId>com.thenaglecode</groupId>
<artifactId>mysql-jdbc-compliance-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</configuration>
<executions>
<execution>
<goals>
<goal>modify-connector</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
However i'm still getting could not connect to remote message. Is there a step that i'm missing or doing in the wrong sequence as i understand that the run command should start up the server.
UPDATE 2:
After some fiddling and reading of the jboss-as plugin website, I realized that the jboss-as:run goal also invokes the package phase. I was mostly receiving this error when I tried to run any of the deploying goals bound to the package phase.
Anything that needs to be deployed should be bound to the install phase.
I am now getting a seperate error regarding my persistence unit not existing
The problem is the MySQL driver is not JDBC 4 compliant. You need to add a META-INF/services/java.sql.Driver file to the JAR with the fully qualified JDBC driver class name or install it as a module. See https://community.jboss.org/wiki/DataSourceConfigurationInAS7 for more details.
solution here:
conf : jboss as7, maven 3.3.3, mysql java connector 5.1.29 28 27 26...,
starting from mysql java connector 5.1.30, the file Meta-INF/serivces/java.sql.driver contain this line "com.mysql.jdbc.Driver
com.mysql.fabric.jdbc.FabricMySQLDriver", if I change it to "com.mysql.jdbc.Driver" the datasource is created and the project deployed fine.
with mysql java connector 5.1.29 28 27 26 ..., that file contain only "com.mysql.jdbc.Driver", the deployement work fine.
check my pom.xml here
https://github.com/anouarattn/GestionAbsence
Is there any way how to compile maven/flex project which does not contain any *.mxml?
The flex project contains ActionScript classes only (i.e. "src/flex" directory contains *.as files only). My pom.xml is here:
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>test</name>
<packaging>swf</packaging>
<build>
<sourceDirectory>src/main/flex</sourceDirectory>
<testSourceDirectory>src/test/flex</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.8</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>4.5.0.18623</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>4.5.0.18623</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId>
<version>0.85</version>
<type>swc</type>
<scope>test</scope>
</dependency>
</dependencies>
"mvn package -e" throws this error:
[ERROR] Failed to execute goal org.sonatype.flexmojos:flexmojos-maven-plugin:3.8:compile-swf (default-compile-swf) on project test: Source file not expecified and no default found! -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonatype.flexmojos:flexmojos-maven-plugin:3.8:compile-swf (default-compile-swf) on project q-integra-scorecard-ldservice: Source file not expecified and no default found!
Try to add this inside <plugin>, where "Main.as" is your class:
<configuration>
<sourceFile>Main.as</sourceFile>
</configuration>
In my case, I didn't have any primary source files (it was a SWC full of interface classes like ISessionProxy.as).
So I had to do two things to get this working:
1) reference my source directory (under the build tag):
<build>
<sourceDirectory>src/main/flex</sourceDirectory>
2) follow the advice I found on this mail group and the FlexMojos Google Group:
"...just remove all dependencies on your pom, because those dependencies
are already defined on super pom."
So, I deleted all my dependencies and added them back, one by one until I got it to compile. All I needed was:
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>${flex.sdk.version}</version>
<type>pom</type>
</dependency>
I even deleted all the dependencies for the FlexMojos plugin:
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${flexmojos.version}</version>
<configuration>
<targetPlayer>${flash.player.version}</targetPlayer>
</configuration>
</plugin>
This worked for me, producing the SWC I need and I hope it helps someone else, too!
i am trying to use a container managed datasource (via context.xml) in tomcat. The corresponding jar file needs to go in $catalina_home/lib, otherwise tomcat can't find it. (not in webapp/WEB-INF/lib, because it is managed by the webserver, not by the application itself)
the problem is: I am using maven with the maven-tomcat-plugin, so I don't have a $catalina_home (everything is distributed in my .m2 -repository).
So the question is: how can I add the mysql driver jar to the classpath of the tomcat server (mvn tomcat:run)?
thanks a lot,
gerolf.
Did you try to add the JDBC driver as a dependency of the maven-tomcat-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
...
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.5</version>
</dependency>
</dependencies>
</plugin>