How to rename a file for a specific maven build profile - maven-3

I've got changes to my web.xml config file that need to stay local-only since Google-App-Engine chokes on them when we try to use them, and they're really only needed for development purposes.
How can I make maven copy my src/main/webapp/WEB-INF/web_local.xml to be web.xml in the target WEB-INF directory?
I looked into maven-assembly-plugin, but that didn't provide a way to give a name to the ouput file (plus it seemed specifically for building .jar files).

You can use webXml property of the maven-war-plugin plugin configuration to point to custom web.xml

Related

How to exclude grails plugin jar from war file

Grails 3.2.5. Build.gradle has mail plugin:
compile "org.grails.plugins:mail:2.0.0.RC6"
In deploying a war to production I need to remove javax.mail-1.5.6.jar from WEB-INF/lib since that jar must be in the Tomcat lib when using a JNDI mail resource. So how do I keep the mail plugin but remove the offending jar file from the war? I knew how to do this in Grails 2.x. Via the gradle war task in build.gradle I have tried to exclude the file (doesn't work - the jar drifts in from a plugin somehow), and have tried to filter the file out. When I build the war I get two files - "app-0.1.war" and "app-0.1.war.original". The "original" file has the WEB-INF/lib/javax.mail jar filtered out, but the real, complete war still has it.
So how do I prevent that plugin jar from getting into the war file? Thanks.
One way to do it is with something like this:
war {
rootSpec.exclude '**/javax.mail*.jar'
}
(you may need to adjust depending on whether or not you want to also exclude the javax.mail-api jar file along with the javax.mail jar)
See https://github.com/jeffbrown/excludejar/blob/67734ac0c65cdbead468f1e65bcfc29041cd2279/build.gradle#L70-L72

Building a non-uberjar Docker image with leiningen

I have a clojure project that depends on a Java library, that does not work, when it gets included in an uberjar. (It needs different XML descriptors using the same filename in different JAR files.)
Everything I find on using Docker with leiningen depends on building and packaging a uberjar. That's also how I built all clojure Docker images so far.
Is there any leiningen plugin out there, that understands to package a Docker image using several jar files like io.fabric8/docker-maven-plugin does?
Whenever packaging (uberjar, war) the big file that is created contains .class files and a directory structure. Where are these XML files supposed to be (class)loaded from? You can experiment with packing manually. After all it (whether uberjar, war or jar) is just a zip file.
When you know exactly the layout you need SBT is flexible enough to insure you can package from the many input jar files. Unfortunately lein plugins will do things like always overwrite duplicates, and you can't control the packaging behaviour. I can't remember exactly the inflexibilities, but I couldn't control how the packaging process went, what decisions were made.
For doing it manually I use a Linux something called Archive Manager, which I found to be much better than what I used when on Windows. Doing it manually may be all you need. The downside of SBT of course being that you have to learn it, which includes a bit of Scala.
It needs different XML descriptors using the same filename in different JAR files.
Just thinking about this, is it that you need to append the contents of each file that is in a different jar into the one file that is in the uberjar? You can try it out. If it works and you need to package up often enough that manually creating and renaming a zip file every time becomes a pain, then I believe that SBT will be your best bet.
I have to package my container with the original jar file and then reference this jar in the classpath when starting the application
The classloader loads classes rather than jars. It is the container's job to unpackage all the things you give it, such as .class files, (uber)jars, wars. Any program that dynamically loads from the classpath is loading either classes or resources (things like .xml files). I suppose a .jar file could be a resource, in which case you would put the jar file in the uberjar. So it is still possible to package it up.

Create war without manifest

I need to create a war file through ant build without a manifest file. I want the war to me created without the manifest file.
I am using tag in build.xml to create the war.
you can use <zip/> task with .war extension for destfile attribute to achieve the same result as the <war/> task (without manifest.mf).
<zip destfile="..\...\WarFile.war"basedir="..\basedir" update="true"/>
in case WarFile.war already exists, although you've written I need to create a war file , the attribute update="true" will be of use (by only updating and not overwriting the file).
All a war file is is a zip file in a specific format. That is libraries go in a particular place, class files go elsewhere, etc. The <war> task has sub-entities like <classes/> and <lib> that make configuring a war file correctly without knowing exactly where everything has to go.
However, you can correctly format the war yourself, and use <zip/>.
Why don't you want a manifest file? A manifest, if you don't specify anything, will contain nothing but the Java version used for the build, and the Ant version and won't affect the execution of your war at all.
What you can do is put useful information into the manifest. For example, we use Jenkins for our builds, and we put in the Jenkins project name and the build number which helps us understand what was included in the war.
There's no reason not to use a manifest file. And, a manifest file can contain useful information (which is accessible to the Java program too).

Deployment of Jar using Ant and OJDeploy for packaging ADF

I'm trying to Deploy a Jar File from an ANT script (with OjDeploy), which compiles successfully. But when I run the main project (Which has the Jar dependency), I get a huge incident, when I analysed the incident log, it says
"Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist"
I analysed both the jar files (One generated by the ANT script and the other generated from Jdev). I couldn't find any difference b/w Manifest of those two jars. The other folders are also the same, In other words, both are almost the same, or I'm not able to figure out the difference between the two jar files generated.
I know, I'm missing something, config of build.xml or something, but not able to figure out the exact problem.
Thanks,
Shiva Shankar
My guess is that the problem is not in the JAR file but rather in the project that consumes it.
Seems like the DB connection in that project is different than the one in your JAR project - which causes one of the tables that is needed in the DB not be found.
I figured out a way to solve the problem. Not sure what was the cause of this issue, but a couple of changes made both to JAR/EAR build scripts set the things right
While building JAR files:
Uncheck "Make this the project build file" while creating the ANT build file, while the "Include Packaging Tasks (uses OjDeploy)" must be checked.
Remove "nocompile" parameter from tag in the OjDeploy.
While Building EAR files:
Create EAR in the view controller project.
Go to the View Controller Project Properties-> Project Source Path -> Resources, remove the newly created build file dependency, which specifies that the build file is for the whole project and not for the individual project.
Remove "Project" parameter from tag in the OjDeploy. (Ensures to build for the whole application)
Remove "nocompile" parameter from tag in the OjDeploy.
These are the exhaustive set of changes, which I made to ensure the ANT files are building correctly, if you get any other errors after this EAR is deployed, then its definitely due to code, EO/VO or DB related.
Thanks for all the help!!
Shiva Shankar

Convert grails app to plugin

I started a grails application by grails create-app. For modularity, I feel like it would be better that component be a plugin. Can I convert this application into a grails plugin?
thanks,
Babu.
I never created a plugin based on an application written before but looking at the documentation for grails plugins you can read the following statement:
The structure of a Grails plugin is exactly the same as a regular Grails project's directory structure, except that in the root of the plugin directory you will find a plugin Groovy file called the "plugin descriptor".
So I would suggest to create a new plugin with grails create-plugin *your-plugin-name* and copy all files from your application into the plugin.
In case anyone else is looking, this should be exactly what you need: http://burtbeckwith.com/blog/?p=1973
Excerpt:
So to convert an application to a plugin, the general workflow would
be something like
Create the plugin descriptor, FooGrailsPlugin.groovy. The easiest way to do this is to rungrails create-plugin pluginname and copy the
generated file from there
delete everything from application.properties except the app.grails.version property
if you have jars in the lib directory that are available in a Maven repo, delete them and replace with BuildConfig.groovy dependencies
change any plugin and jar dependencies that are needed for development and testing but not when the plugin is installed to not be
exported, by adding export = false
If you need the _Install.groovy, _Uninstall.groovy, or _Upgrade.groovy scripts (you probably don’t) grab those from the dummy plugin from step 1 (but delete any you don’t need, they’re all
optional)
delete ApplicationResources.groovy if you aren’t using it and don’t depend on resources plugin
move code from BootStrap.groovy init() toFooGrailsPlugin.doWithApplicationContext
and/orFooGrailsPlugin.doWithDynamicMethods and destroy() to
FooGrailsPlugin.onShutdown, and delete BootStrap.groovy
add a dependency for the release plugin in BuildConfig.groovy
delete everything but the log4j configuration from Config.groovy
delete UrlMappings.groovy unless you have exported mappings; only keep the added ones
move bean definitions from resources.groovy to FooGrailsPlugin.doWithSpring and delete resources.groovy
delete grails-app/i18n message bundle files unless you added messages; only keep the added ones
delete everything from grails-app/views that you don’t use (in particular error.gsp,index.gsp, and layouts/main.gsp)
delete everything from web-app that you don’t use (including WEB-INF xml and tld files)
now would be a great time to write those tests you’ve been meaning to get to
create one or more test applications to install the plugin into to ensure that it works as a plugin; consider scripting this
write documentation for how to use the plugin; at a minimum a README file, but Grails gdoc files would be much better (run grails doc
--init to get started)

Resources