How to launch browser automatically after war deployment? - eclipse

I have a war maven project and I want that when I deploy it on the server the default browser (Mozilla in my case) is launched automatically with the default url for access to the main page.
Of course with JBoss EAP6 I have just to run the Maven command clean install jboss-as:deploy to generate the war file and deploy it on the server.
Do I have to add something to the pom.xml or make any configurations in Eclipse?

Use maven's exec plug-in. More information here.

I used this and it works good but juste for the maven phase : install but for the deploy no:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>Run URL in system browser.</id>
<phase>install</phase>
<configuration>
<target>
<exec executable="start" vmlauncher="false">
<arg line="http://localhost:8080/mywarApp" />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I use eclipse and i made for goals "clean install jboss-as:deploy" into the run configurations. and when in click in , once the install phase is runing the browser is runing too but i want that it will happen when the deploy phase is end of runing , have you any idea

Related

How to redeploy artifact with liberty-maven-plugin?

I have IBM Liberty server running on my machine and want to redeploy my WAR using corresponding maven plugin.
The documentation says that there are goals like deploy , undeploy , install-apps . Currently I am using
<plugin>
<groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>install-apps</id>
<phase>install</phase>
<goals>
<goal>install-apps</goal>
</goals>
</execution>
</executions>
<configuration>
<serverHome>c:/my-liberty-instance</serverHome>
<serverName>myServerName</serverName>
</configuration>
</plugin>
But it's not good for me because it requires the server instance to be stopped before. If it's running - a new WAR is deployed (it replaces the old one) but no new changes are caught up.
I've tried to use deploy goal but once it copies WAR to the dropins directory - it starts searching some console.log file for some line that should indicate if app is started and FAILS.
Example for undeploy goal : CWWKM2022E: Failed to undeploy application app-1.0-SNAPSHOT.war. The Stop application message cannot be found in console.log.
But the same message appears for deploy , stop-server .
Is there a convenient way to redeploy WAR using liberty-maven-plugin where I don't need to restart the server ?
I just want to build a new WAR - deploy it; want the server to catch up the changes and that's it.
You can use the install-apps goal to install the project war file without your liberty server instance stopped. But you need to use liberty-maven-plugin version 1.3 or above, and also include <installAppPackages>project</installAppPackages> to the plugin configuration.
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>install-apps</id>
<phase>install</phase>
<goals>
<goal>install-apps</goal>
</goals>
</execution>
</executions>
<configuration>
<installDirectory>c:/my-liberty-instance</installDirectory>
<serverName>myServerName</serverName>
<installAppPackages>project</installAppPackages>
</configuration>
</plugin>

Maven archetype for glassfish runtime

How can I create j2ee project with maven having glassfish 4 as target runtime?
I use eclipse Mars. I follow the 'Dynamic web project' wizard, I select glassfish 4 as 'Target runtime'. When wizard ends I open the project and under the nodes 'Java resources->Libraries' I can see the glassfish system library bundle.
Now I would create the same project using maven. I've searched for an archetype giving me the same library bundle to avoid problem on deploy but I haven't found a definitive one.
The more close appears to be the jersey-quickstart-webapp but when I look the dependencies these are just a bunch respect to glassfish runtime. It's possible? It sounds strange to me, maybe I am making mistakes, am I following the right approach?
Thanks.
The best I could come up with was this:
mvn archetype:generate -DgroupId=mygroup -DartifactId=myapp -Dversion=1.0-SNAPSHOT
-DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=webapp-javaee7
Where mygroup and myapp are yours to determine.
Then, in the generated pom.xml, add this property (in the properties element):
<glassfish.version>4.1.1</glassfish.version>
Set the final name in the build element (we're going to refer to it shortly):
<finalName>myapp</finalName>
Then add this plugin to configure the Glassfish embedded runtime, in the plugins element:
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>${glassfish.version}</version>
<configuration>
<autoDelete>true</autoDelete>
<ports>
<http-listener>8080</http-listener>
<https-listener>8181</https-listener>
</ports>
</configuration>
<executions>
<execution>
<id>deploy</id>
<goals>
<goal>deploy</goal>
</goals>
<phase>none</phase>
<configuration>
<app>target/${project.build.finalName}.war</app>
<contextRoot>/${project.build.finalName}</contextRoot>
</configuration>
</execution>
<execution>
<id>admin</id>
<goals>
<goal>admin</goal>
</goals>
<phase>none</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>${glassfish.version}</version>
</dependency>
</dependencies>
</plugin>
I then use mvn clean install embedded-glassfish:run to run the server with a freshly built application.
Hope you like it.

How to change jar output directory when running as maven install in Eclipse?

I am making a Minecraft plugin for Bukkit 1.8, and everything works fine. I right click on the project name > Run As > Maven install. It outputs the .jar file to the target directory. I then copy the file to the plugins folder of my Minecraft server.
I would like to have it output the jar directly into my plugins folder.
A simple way to do that would be to bind an execution of the maven-antrun-plugin to the install phase. This execution would copy the main artifact to the Minecraft server folder.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.jar"
todir="/path/to/server/plugins" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
(This snippet must be placed inside the <build><plugins> element).
Running mvn clean install (or "Run As... > Maven Install" in Eclipse), Maven will do what you want. ${project.build.directory}/${project.build.finalName}.jar refers to the main artifact present in the build directory (which is target by default). You'll need to update the path to the server in the snippet above.

maven goals, compiling and deploying to a server

I'm using eclipse to manage a maven project.
In the pom of this project I have a special plugin, which create a file during the generate-ressources phase :
<plugin>
<groupId>org.eclipse.acceleo</groupId>
<artifactId>maven</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>acceleo-compile</goal>
</goals>
</execution>
</executions>
</plugin>
I have linked this plugin goal to eclipse lifecycle to execute it during eclipse compilation :
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.acceleo</groupId>
<artifactId>maven</artifactId>
<versionRange>[3.2.1,)</versionRange>
<goals>
<goal>acceleo-compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
When I do a clean project with eclipse, the project compile again and the file is well generated during the eclipse compilation (I can find it in the target directory).
Now, I want to deploy my webapp on a tomcat server. I create a tomcat server using the server view of eclipse and I drag and drop the project into this server to synchronize and publish it.
The project is well deployed and I can launch the server and test my app.
BUT, the file which needs to be generated by the maven plugin is not copied during the publish operation...
So my question is : why the file generated by a maven plugin is well generated during the eclipse compilation but is not deployed on the server during the publish/synchronize operation of the automatic server management by eclipse ?
The answer is in your question, cause you configured the plugin to run only during the eclipse Life cylce, but you've missed to add the exection to your build life cycle.
As far as I know the publishing of your webapp is done by eclipse wtp tools.
To configure this (what gets deployed to the server) check out this question and the according answers.
In short: I think you need to configure that the generated file (from your target dir) is also copied when wtp deploys your app.

Only copy modified files in maven-war-plugin

I'm currently using maven 3.x with the maven-war-plugin. For developer builds I would like to be able to use the war:exploaded goal, but only copy resources that have changed. Is there a way to do this?
I've been looking through the docs and have not been able to find a way to do this in the current versions, but there used to be (in the old maven 1.x version) a property maven.war.resources.overwrite that would allow this.
Thanks.
I'm not aware of a way to do this using the maven-war-plugin, but if your IDE supports it, you could have the IDE auto-deploy changes. For example, the Web Tools Platform for Eclipse supports this feature for Tomcat. However, if your build process is complex or does something weird before invoking the maven-war-plugin, this may not work for you.
A second option: if you're running Linux, set up rsync to copy recently modified files to your servlet container. A co-worker did this by having the servlet container's web app directory sync with the Eclipse project's output directory, and it worked well (just modify your code, Eclipse will build it automatically, and rsync will copy your changes).
For this purpose I use maven-antrun-plugin
Example:
<project xmlns="http://maven.apache.org/POM/4.0.0"
....
....
<!--DJ: Settings for deploy only-->
<!--DJ: Dir to where copy files-->
<!--DJ: And date when build have been started, to select only modified files in the future-->
<properties>
<tomcat.dir.rootDir>C:\apache-tomcat-6.0.35\webapps\ROOT1</tomcat.dir.rootDir>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
</properties>
.....
<!--Ohter dependensies here-->
.....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copyModifiedFilesFrom_ExplodedWAR_Dir</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo message="Upload new files to dir ${tomcat.dir.rootDir} modified after date ${maven.build.timestamp} "/>
<copy todir="${tomcat.dir.rootDir}">
<fileset dir="${project.build.directory}/${project.build.finalName}" includes="**/*">
<!-- Include only recompiled files -->
<date datetime="${maven.build.timestamp}" pattern="yyyy-MM-dd HH:mm:ss" when="after"/>
<!-- and only *.class files -->
<filename name="**/*.class"/>
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
.....
.....
</plugins>
</build>
</project>
Then run maven with params:
mvn pom.xml compile install org.apache.maven.plugins:maven-war-plugin:2.1-alpha-1:exploded
As result only changed files will be recompiled and only recompiled filed will be replaced in tomcat webapp dir.