Flyway Ant tries to open .sql file as a zip, fails with ZipException - ant

I am trying to use Flyway in my Ant project to run DDL scripts. I managed to configure the classpath so that Flyway sees the migration scripts. When I run the flyway:migrate task, I get this exception:
Unable to obtain resource from (...)/src/ddl/V1__create_tables_logging.sql: java.util.zip.ZipException: error in opening zip file
[flyway:migrate] Unable to obtain resource from (...)/src/ddl/V1__create_tables_logging.sql:
[flyway:migrate] java.util.zip.ZipException: error in opening zip file
There is a suggestion at the end:
[flyway:migrate] Possible solution: run the Ant javac and copy tasks first so Flyway can find the migrations
But my project is not a Java application, I have no java sources to be compiled with javac. Does Flyway need to have the migration scripts packed in a jar? Can't it simply run some text files with SQL statements?

Unfortunately, you didn't provide a configuration you have, without it it's hard to tell, what exactly causes this issue.
But it seems odd to me, that you are not using location property of the task, but classpath. Try to specify the directory with you migration scripts as follows:
<flyway:migrate>
<locations>
<location path="path/to/migrations"/>
</locations>
...
</flyway:migrate>

Related

updateapplicationserver ant task always fail with "WAR file is not currently deployed"

I used a very basic build file taken from the sample configure-was-derby.xml:
<property name="worklight.server.install.dir" value="C:/Worklight70"/>
<property name="config.migration.tool.enable" value="true"/>
<target name="minimal-update">
<updateapplicationserver id="" contextroot="/AreaClienti">
<project warfile="C:/temp/AreaClienti.war"/>
<applicationserver>
<websphereapplicationserver installdir="C:/WebSphere85/AppServer"/" profile="AppSrv01" user="wasuser" password="xxxxx">
<server name="server1"/>
</websphereapplicationserver>
</applicationserver>
</updateapplicationserver>
</target>
Recently I was able to reproduce the issue on my laptop installation and I believe I found the cause: please review the following analysis and confirm the results.
I originally installed the war file manually from WAS admin console, and when I run the Ant minimal-update with the above build file it failed with the mentioned error
The MobileFirst Project WAR file is not currently deployed in the WAS
profile at ...
Then I removed the manually installed war file and reinstalled it using Ant install target.
At this point the minimal-update run successfully.
I found out that the Ant installation created into WAS config structure
profile_root/config/cells/cell_name/nodes/node_name/servers/server1
a new Worklight directory containing the worklight-jee-library.jar file and a derby subdir with the derby driver jar.
Apparently the minimal-update Ant task makes a preliminary check on the existence of the Worklight directory and it fails if it's missing.
Can you please confirm that this is true ?
Of course the Worklight directory is not created by the standard WAS installation process.
So, after a console installation of the runtime war the Ant minimal-update always fails!
If I manually add the Worklight dir in WAS config, then the Ant minimal-update starts running just fine.
IMHO, altering in such way the standard WAS config structure is not very clean.
Said that, is it a valid workaround in case we initially install the runtime war with standard WAS admin procedures ?
Furthemore, also the returned error message could have been a bit more clear: please let me know if there is any debug option to make the Ant tasks more verbose.
At last, let me ask one further question.
I noticed that the Ant execution writes log files in the directory
user_root/.mobilefirst_platform_server
Is there any way to redirect those logs into a different dir to avoid the risk of filling up the user root ?
Apparently the minimal-update Ant task makes a preliminary check on the existence of the Worklight directory and it fails if it's missing. Can you please confirm that this is true ?
That's correct.
Is there any way to redirect those logs into a different dir to avoid the risk of filling up the user root ?
Unfortunately not.

java.util.zip.ZipException when running Ant script for Groovy project

I have this old Grails (1.3.1) project. It contains some Java, some Groovy, has an Ant script and Ivy dependency management. I've managed to open it in Eclipse and resolved some initial build errors, and now it looks fine. The Ant script has some targets (clean, compile, deploy etc), but for each of them, I run into the following:
(Ivy first retrieves a lot of dependencies)
C:\[SOMECLASSPATH]\SomeClass.class: java.util.zip.ZipException: error in opening zip file
[grailsTask] Unable to obtain resource from C:\[SOMECLASSPATH]\SomeClass.class:
[grailsTask] java.util.zip.ZipException: error in opening zip file
Where [SOMECLASSPATH]\SomeClass varies, it is repeted for an seemlingy endless number of classes, and eventually I stop the process.

executable jar from groovy sources

I could not find a proper answer to the following question : while creating an executable jar from groovy compiled sources, I cannot simply include groovy-all-version.jar in a lib directory (as I would do in java) but I need to extract all the classes from the jar and package them with my own classes as otherwise I get an exception. This actually is the case with all libraries I may want to use.
Not clear ? Let's see an example.
toto.groovy belonging to package titi is compiled in a build directory which looks like this :
build
lib
groovy-all-1.8.4.jar
titi
toto.class
and a MANIFEST.MF that will be included in the jar contains the lines:
Main-Class: titi.toto
Class-Path: lib/groovy-all-1.8.4.jar
Executable jar creation is done with the following ant target in build.xml:
<jar destfile="${build.exe.dir}/${exe.name}"
basedir="${build.dir}"
manifest="${src.conf.dir}/MANIFEST.MF"
/>
Now if I try to execute the jar, I get
$ java -jar target/toto.jar
Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/Script
(I've checked that the groovy.lang.Script class exists.)
On the other hand, if I unjar groovy-all-version.jar in build by adding an unjar task before the jar, execution goes fine. OK, it works, but it slows down the compilation process and I'd like to understand...
Any feedback is highly appreciated.

xjc with annox running from command prompt

I have tried to run a example from the website http://confluence.highsource.org/display/J2B/Annotate+Plugin#AnnotatePlugin-Activation. The very first schema provided in the webpage and I saved it as schema.xsd under c:\jaxb folder. Then, I ran the command 'xjc -extension schema.xsd' from command prompt and I get the similar error. Apparently xjc doesn't seem to understand this url http://annox.dev.java.net. How do I solve this?
You have to add the annotate plugin with all the dependencies to the classpath. See this Ant build file for what dependencies are
You have to activate the plugin using -Xannotate switch
Here's a sample Ant project. I'll assemble a command-line example for the next version.

"JUnitTask was not found" error (Hudson, Ant, JUnit)

I tried several ways to install ant and junit on the same server as hudson. I eventually downloaded the Ant source, installed the optional dependencies by using the included fetch.xml file, built the source code, and dropped junit-4.8.1.jar into the lib directory where the compiled ant code [that I just built] is. Then I set ANT_HOME to the ant root directory by using the "export ANT_HOME=/usr/share/ant" command. I also set a Hudson configuration variable of "ANT_HOME" with the same value (/usr/share/ant) and I also put a new file into the /etc/profile.d directory with the export ANT_HOME command as well. At this point I'm not sure what else to try, but Hudson still gives me the error:
BUILD FAILED /var/lib/hudson/jobs/MyProject/build.xml:31: Problem:
failed to create task or type junit Cause: the class
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.
This looks like one of Ant's optional components. Action: Check that the appropriate optional JAR exists in
-/usr/share/ant/lib
-/var/lib/hudson/.ant/lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem. The commonest cause is a
missing JAR.
This is not a bug; it is a configuration problem
I did, in fact, check /usr/share/ant/lib and the class "org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.class" is located in the ant-junit jar file as I confirmed by running the command: jar tfv ant-junit.jar | grep org.apache.tools.ant.taskdefs.optional.junit.JUnitTask
Can someone please tell me what to try, I am not sure where to go from here.
If you are on Ubuntu you can simply apt-get ant; I did that and linked to the junit jar within my project.
Cheers,
Neil
It turns out that hudson itself installs some version of Ant in one of its own libraries. I suppose that somehow caused a conflict because when I got rid of it, things worked. I think it is in /var/hudson or /var/hudson/lib. That path is added to the PATH environment variable during hudson installation. So your choice is either to add your own Ant install to the BEGINNING of the path, to delete hudson's version of Ant, or to delete that part of the PATH.

Resources