Is there a way to remotely deploy EAR to Oracle AS using maven? - oracle

Is there a way to remotely deploy an EAR after building it to Oracle AS? Remote deployment functionality exists for Eclipse, and I'm looking for something similar for maven2:
http://download.oracle.com/docs/cd/E14545_01/help/oracle.eclipse.tools.weblogic.doc/html/conFeatureOverview.html#remoteDep

Verified on Oc4j 10
http://chadthedeveloper.blogspot.com/2008/05/automated-deployment-to-oc4j-in-maven2.html

Have you tried the Weblogic Maven plugin? The weblogic:deploy goal seems to do exactly what you want. I've not used it myself so can't confirm if it actually works or not.
Update:
Found this blog that describes deploying to 10.1.3, though not using the weblogic plugin.

This is not a complete answer your question; is's just a checklist for things to look up while solving this:
what to do with generated sources, when to generate them?
do you need custom information in META-INF?
how to manage jars?
you can have them installed in an external repository, local repository, or specify them with system, on a project relative path, or a system absolute path
if specified with system, you can keep compile time jars in any location, and those that you want inside wars inside webapp/WEB-INF
If your project has a maven friendly architecture, then ok. Otherwise you can specify custom paths like this:
<packaging>ear</packaging>
<build>
<finalName>ear-name</finalName>
<!-- you can have only one source path-->
<sourceDirectory>src-dir-path</sourceDirectory>
<!-- you can have only one test path-->
<testSourceDirectory>test-dir-path</testSourceDirectory>
<!-- you can have several resource paths -->
<resources>
<resource>
<directory>src-resources-path</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<!-- you can have several test resource paths -->
<testResources>
<testResource>
<directory>test-resources-path</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
Other tips:
study Eclipse generated ear, and maven generated ear, check for differences
you can find missing jars with mvn compile, don't use an IDE for this, you want to make sure that maven has all the jars it needs
you can have ant scripts inside maven, use maven-antrun-plugin, i can provide examples if requested

Related

Is It Possible to Set the user.agent Property from the Command Line Using the GWT-Maven-Plugin?

I know that in my *.gwt.xml file I can specify the browsers I want the GWT compiler to compile my app for by adding this to it:
<set-property name="user.agent" value="opera,ie8, gecko1_8, safari, ie9"/>
Is it possible for me to set this property on the command line when I build my project through maven? I'd like to be able to do something like this when I'm developing locally on my machine:
mvn clean install -Duser.agent="opera,ie8"
EDIT: Starting with GWT 2.7, you can now pass a -setProperty user.agent=… on the command line; no need to tweak gwt.xml files any more. I'm not sure Mojo Plugin for GWT let you use that though, but the net.ltgt.gwt.maven Maven Plugin for GWT can.
You can use filtering of your resources, but then it might make it harder to work from within your IDE.
In your gwt.xml:
<set-property name="user.agent" value="${user.agent}" />
Then in your pom.xml:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
and the default value for the property when you don't give it on the command-line:
<properties>
<user.agent>opera,ie8,gecko1_8,safari,ie9</user.agent>
</properties>
Note however that this goes against The Maven Way™.

How to edit the directory structure in Maven?

I am using Maven project, when i create the Maven module of jar packaging, maven auto generates directory structue as src/main/java, src/main/resources, src/test/java and src/test/resources. Can I edit the above names as per my wish? Can I add new folders to the same parent? Also when i googled, I came to know abt super POM, can anybody suggest how to edit the same with the custom directory structure. I have configured sonatype maven to my eclipse from the link http://m2eclipse.sonatype.org/sites/m2e
Assuming you have a good reason to do this, you can rename the folders and indicate to maven what is the edited one by specifying the appropriate properties/sections in pom.xml of your project. I suppose m2e will pick up the changes once made to the pom.
The relevant section in your case would be (from the superpom)
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
If you want to add additional source folders or resources (not subfolders), then you can use build helper maven plugin. Again, not sure what m2e will do.

Maven project.build.directory

In Maven, what does the project.build.directory refer to? I am a bit confused, does it reference the source code directory or the target directory in the Maven project?
You can find those maven properties in the super pom.
You find the jar here:
${M2_HOME}/lib/maven-model-builder-3.0.3.jar
Open the jar with 7-zip or some other archiver (or use the jar tool).
Navigate to
org/apache/maven/model
There you'll find the pom-4.0.0.xml.
It contains all those "short cuts":
<project>
...
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
...
</build>
...
</project>
Update
After some lobbying I am adding a link to the pom-4.0.0.xml. This allows you to see the properties without opening up the local jar file.
It points to your top level output directory (which by default is target):
https://web.archive.org/web/20150527103929/http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide
EDIT: As has been pointed out, Codehaus is now sadly defunct. You can find details about these properties from Sonatype here:
http://books.sonatype.com/mvnref-book/reference/resource-filtering-sect-properties.html#resource-filtering-sect-project-properties
If you are ever trying to reference output directories in Maven, you should never use a literal value like target/classes. Instead you should use property references to refer to these directories.
project.build.sourceDirectory
project.build.scriptSourceDirectory
project.build.testSourceDirectory
project.build.outputDirectory
project.build.testOutputDirectory
project.build.directory
sourceDirectory, scriptSourceDirectory, and testSourceDirectory provide access to the source directories for the project. outputDirectory and testOutputDirectory provide access to the directories where Maven is going to put bytecode or other build output. directory refers to the directory which contains all of these output directories.
You can find the most up to date answer for the value in your project just execute the
mvn3 help:effective-pom
command and find the <build> ... <directory> tag's value in the result aka in the effective-pom. It will show the value of the Super POM unless you have overwritten.
Aside from #Verhás István answer (which I like), I was expecting a one-liner for the question:
${project.reporting.outputDirectory} resolves to target/site in your project.

How does IntelliJ's Maven filtering support work?

I have noticed when you configure a Maven project to use property filtering the property filtering seems to also work during a non-maven IntelliJ "make". This means the IntelliJ run configurations for Jetty/Tomcat/GWT/Glassfish will still honour your maven resource filtering.
So if I add this to my pom.xml:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
<include>**/persistence.xml</include>
</includes>
</resource> ....
It should filter any properties in my properties and peristence.xml files before any intellij run configurations start. This is very usefull for swapping in JDBC references or filesystem parameters.
The only problem I am having is that IntelliJ only seems to honour filtering in src/main/resources even if I change pom.xml to have a second entry for other directories (ie:src/integrationtest/resources).
This all seems to be "automagical". So how does it work and where (if anywhere) can I configure it?
IntelliJ IDEA's Make features are capable of filtering Maven resources. However, IntelliJ IDEA yet does not support filtering web resources.
source: http://www.jetbrains.com/idea/webhelp/maven.html#compile
No further details about this support in whole intellij webhelp though, so I guess it should work just like maven's process-resources phase does.
The problems you are having can be caused by the fact that directory src/integrationtest/resources doesn't follow maven conventions.
Maybe it will work if you:
make it src/test/resources/integrationtest/
or
configure maven to respect src/integrationtest as test sources (but if integrationtest isn't well-known convention it will be violation of maven's COC rule)
or
make it another maven (sub)module, if you want to emphasize isolation of integrationtest
As for filtering directories different that src/main/resources: filtering src/main/webapp/META-INF worked out-of-a-box for me.
(Maven 3.0.4, Intellij 12.1.4)
Good news, looks like the issue will be fixed in 13.1
http://youtrack.jetbrains.com/issue/IDEA-25934
EDIT: Sorry if not clear enough, the bug case is just marked as "fixed" with no further explanation...
But I tested in 13.1 EAP version (build 134.1445) and while previously IntelliJ would overwrite the resources, it now preserves the web resources filtered by Maven.
Intellij (I'm using 14.1) does allow you to define custom Ant tasks as pre-/post-processing during artifact build.
Go to Project Structure -> Artifacts -> {select artifact} -> {Pre-processing|Post-processing} tabs.
So, for example, I can use the following simple task to simulate resource filtering in cases where it doesn't work out of the box:
<target name="filter" depends="clean">
<copy todir="${maven.build.dir}/${maven.build.finalName}">
<fileset dir="${maven.build.resourceDir.0}"/>
<filterset begintoken="${" endtoken="}">
<filter token="project.version" value="${project.version}"/>
</filterset>
</copy>
</target>
Don't forget to define a default profile
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
...
</properties>
</profile>
</profiles>

How to filter resources when using maven jetty plugin?

I have an XML file (urlrewrite.xml) that needs a property placeholder resolved. I enable Maven filtering to achieve this. This works fine for the assembled WAR file.
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
The problem is when trying to run the application in development mode using the maven-jetty-plugin (Maven Jetty Plugin), as maven jetty:run .
The file in question, urlrewrite.xml, is located in the src/main/resources directory, and therefore should (and does) ends up in /WEB-INF/classes (or target/classes for maven jetty:run).
The URLRewriteFilter config specifies the location of the config file as follows:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confPath</param-name>
<param-value>/WEB-INF/classes/urlrewrite.xml</param-value>
</init-param>
</filter>
This will work at deployment time. However, Using the jetty maven plugin, URLRewrite will die with a NullPointerException because it uses context.getResourceAsString("/WEB-INF/classes/urlrewrite.xml") in order to load the config file. Jetty returns null for this because when running the application from workspace it resolves /WEB-INF/classes/... to src/main/webapp/WEB-INF/... . The file does not exist there because the WAR has not yet been assembled. It should instead pull the resource from target/classes/urlrewrite.xml.
If that is obscure to you, then you probably won't be able to answer this question because I suspect you will need to be a Jetty guru to figure out a workaround (hint: that's a challenge!).
Does anyone know a way around this? I have also tried the following workarounds to know avail:
Put urlrewrite.xml under a new directory, src/main/webResources and add it to the maven war plugin <webReources> and enable filtering. That will copy it's contents in the appropriate location when the WAR is packaged, but will not make it available for jetty:run
Some other hacks I can't even remember ... (will update if I do)
In summary, maven-jetty-plugin needs the file to be under src/main/resources/webapp/insert path and filename in order to be available for the maven jetty:run command ...
Thanks for you help ...
Sincerely,
Lloyd Force
Answered my own question.
Upgrade maven-jetty-plugin to at least 6.1.12
See this wiki page on 'Configuring Multiple WebApp Source Directory' (available since jetty-6.1.12.rc2 and jetty-7.0.0pre3)
Add some magic to pom.xml:
First, add a new directory (src/main/webResources) for your filtered web resources and add a <resource> element:
<resource>
<directory>src/main/webResources</directory>
<filtering>true</filtering>
<targetPath>../jettyFilteredResources</targetPath>
</resource>
That will copy the files to target/jettyFilteredResources (we will reference this later). This directory will NOT get copied to your packaged WAR file, it is for jetty only!
Add the following element to your maven-war-plugin <configuration> element:
<webResources>
<resource>
<directory>src/main/webResources</directory>
<filtering>true</filtering>
</resource>
</webResources>
That will ensure everything is packaged up for your real WAR file.
Finally, tell jetty to use the resources your copied especially for it, by added the following snippet to your <baseResource> element:
<baseResource implementation="org.mortbay.resource.ResourceCollection">
<resourcesAsCSV>src/main/webapp,target/jettyFilteredResources</resourcesAsCSV>
</baseResource>
Now everything will worketh! (Well, technically I haven't tested the production WAR yet, but ... blah ... it should work too).
If anyone has a better answer, I will accept it provided the answer is provided in a reasonable amount of time (say 1 day).
I think the answer in this other question is better:
Running resource filters when using jetty:run
Basically, instead of running 'mvn jetty:run' you have to use 'mvn jetty:run-exploded'.
The only drawback is that it needs to build the WAR file, which might be expensive in some cases. If that's not an issue for you, then I guess it's better.
add this to pom.xml:
<resources>
<resource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>../jettyFilteredResources</targetPath>
</resource>
</resources>
and this is how embedded Jetty server should look like:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.3.v20140225</version>
<configuration>
<webAppConfig>
<descriptor>target/jettyFilteredResources/web.xml</descriptor>
</webAppConfig>
<scanIntervalSeconds>3</scanIntervalSeconds>
</configuration>
</plugin>
woila! thanks #les2 for inspiration ;-)
I found another way.
build the project and add the target folder as extra classpath.
<webAppConfig>
....
<extraClasspath>${basedir}/target/mywebapp</extraClasspath>
....
</webAppConfig>

Resources