Explanation:
I currently have a Java Web Project in Netbeans and I'm using Maven. Recently I changed the pom in the project in order to generate 2 war files when building: one for development (which I want Netbeans to deploy when selecting "Run Project") and another one for production.
To maintain a certain standard with a previous deployment, I kept the production WAR with the same (default) name of ReportsPortal.war and the development version with a -dev appended.
Reference:
This is the section of my pom file that I changed:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<webResources>
<resource>
<directory>src/main/env/prod</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<webResources>
<resource>
<directory>src/main/env/dev</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
It generates both files (ReportsPortal.war and ReportsPortal-dev.war). Each one with its environment variables (and different between them).
When right clicking the ReportsPortal project and selecting Run, Netbeans starts the Tomcat and the application deployed has the correct values, so I guess it is using ReportsPortal-dev.war but I can't be sure.
My question:
How can I know or change the war file Netbeans is using to deploy in Tomcat?
You should create a separate maven build profile for each of the war files. You can then invoke the development profile while you are doing your dev work and leave the production profile to be called only when you want to make a release. This will allow you to control exactly what is getting built.
Related
There are two different javafx applications using javafx-maven-plugin to generate native windows installer. In both applications the installers are generated and can be seen at target\jfx\native .
When the first app installer setup installation process is started, setup shows files are copied in C:\Users\Yunus\AppData\Local\CooperativeERP.
The problem is when the second application installation process is started it goes to the same folder and updates some files which makes first app installed unusable.
Plugin Maven XML is as follows:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.6.0</version>
<configuration>
<mainClass>re.iprocu.coperativeerp.MainApp</mainClass>
<bundleArguments>
<licenseFile>termsOfService.rtf</licenseFile>
</bundleArguments>
<additionalAppResources>src/main/additionalAppResources</additionalAppResources><!-- name does not matter, it's just some folder :D -->
<!-- DO SHOW DEBUG-OUTPUT -->
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<!-- required before build-native -->
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
<execution>
<id>create-native</id>
<phase>package</phase>
<goals>
<goal>build-native</goal>
</goals>
</execution>
</executions>
</plugin>
What should i do to make the two setup install as different application and not to get to each others way.
Found out that zen java maven plugin uses a Main class package as unique identifier for application, and in this particular case both application had the same package name.
Changing package for one application solved my problem.
Last week our team decided to move from Netbeans to Eclipse, cause we develop some new plugins that can run only on Eclipse.
At first the project start using my maven plugin from pom <build> tag. But the stop doesn't work. In netbeans I used exec-maven-plugin to exec, java -jar Project.jar from the target folder. Here is the code:
<build>
<sourceDirectory>src/java</sourceDirectory>
<resources>
<resource>
<directory>src/cp</directory>
<targetPath>src/cp</targetPath>
</resource>
<resource>
<directory>src/rpt</directory>
<targetPath>src/rpt</targetPath>
</resource>
<resource>
<directory>src/sql</directory>
<targetPath>src/sql</targetPath>
</resource>
<resource>
<directory>etc</directory>
<targetPath>etc</targetPath>
</resource>
<resource>
<directory>www</directory>
<targetPath>www</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
<configuration>
<connectionType>connection</connectionType>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>setVersion</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>./etc/changeVersion.sh</argument>
</arguments>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
</execution>
<execution>
<id>debugJar</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cd target/</executable>
<executable>java</executable>
<arguments>
<argument>-Xdebug</argument>
<argument>-Xnoagent</argument>
<argument>-Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</argument>
<argument>-jar </argument>
<argument>${project.artifactId}-${project.version}.jar</argument>
</arguments>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</execution>
<execution>
<id>runJar</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cd target/</executable>
<executable>java</executable>
<arguments>
<argument>-jar </argument>
<argument>${project.artifactId}-${project.version}.jar</argument>
</arguments>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</execution></executions>
</plugin><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Project-Name>${project.artifactId}</Project-Name>
<!-- Uncomment if you want to make changes and/or debug in Entuito-->
<!--<Class-Path>${local.OurFramework.dir}${OurFramework.jar}</Class-Path>-->
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<mainClass>${project.groupId}.Mammut</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<extensions>
<!-- Enabling the use of SSH -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>2.10</version>
</extension>
</extensions>
In Netbeans, when we used this build the project had no problem for Debug and Run using Netbeans controls buttons. But in Eclipse the project run and stop button doesn't stop the project. The proccess java -jar Project.jar is still running and we must use htop or other methods to kill it.
Cause of the copying for all of the libs and packaging, are slow proccess and used many read/write operation, we want to Run and Debug the projects using the Java Application run, and to exclude the need of rebuild the whole project for every minor change. But the problem occurs here too. Every project have dependency that is our java framework and all of the framework resource files are inside the jar archive (some conf.xml files, images and etc.) At most of the time when need to fix our to change something we have both project open in one Workspace. Netbeans and Eclipse automatically detect the dependency location and change it from .m2 folder to the workspace project that is open at the moment.
The problem here is that when I use maven clean install for the framework and then run the main project using JavaApp the project doesn't run cause can't find the resource files from the framework. At this time if I close the frameWork from the workspace and run the main project Eclipse change the dependency path to .m2 folder and everything is fine, but this is very slowly proccess and makes the debug unpossible.
Can anyone share a pom build that can help me for even one of the problem or any advices and guide "how to" done it properly if my methods are wrong.
We handled the problem with missing resources when the project and it dependancy is open. Their was a bug in our code for loading the resoure files when they aren't in .jar archive.
The only thing now that left is this little problem with the Manifest file. There is no manifest file inside project/target/classes/ is there a way to create the same Manifest file like that one from inside the packaged jar.
I have a web application with spring and maven. The application is divided into maven modules. I have an "application-web" module that generates war. Another "application-ear" module that generates an ear. And another "application-static" with css, js and images that generates a zip file.
This would be the outline of my application:
application
application-web (java code)
application-ear
application-static (css, js and images)
application-resources (language properties)
I want to deploy the eclipse use files of "static" module, instead of using the files in the "application/src/main/webapp" directory. How can I do this? It is possible?
Don't waste your time with unpacking resources, everything works out of the box:
Resource bundles: the are always loaded from the classpath, regardlessly it is exploded (WEB-INF/classes) or compressed (WEB-INF/lib)
Serving static resources: bundle them up in a JAR and use either Tomcat (Servlet 3.0) feature to serve from META-INF/resources, see here or use Spring's built in mvc:resources element.
Simply add the dependency snippets in your WAR POM and your are done.
You can use the maven dependency plugin to unpack your static resources included in the zip file using the following:
In your application-web.pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-resources</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>resources</outputDirectory>
<includeArtifactIds>application-static</includeArtifactIds>
<includeGroupIds>your group id</includeGroupIds>
<includes>**/*.js,**/*.css</includes>
</configuration>
</execution>
</executions>
</plugin
This work:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTypes>pom</excludeTypes>
<includeArtifactIds>application-static</includeArtifactIds>
<includeGroupIds>com.foo.foo.application</includeGroupIds>
<outputDirectory>src/main/webapp</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}</finalName>
</build>
But I have another problem, with this solution only copy the static files when I execute clean package. If I run the application-web with eclipse and I do changes in a js file in application-static, the changes have no effect until I execute clean package. Any solution for this?
I'm trying to setup my project to use gwt maven plugin. Its compiling properly but I'm not able to use either the dev mode or super dev mode for development.
My settings are as follows:
Maven configurations in order
mvn clean install
mvn tomcat7:run-war-only
mvn gwt:run-codeserver
GWT Version: 2.6.1
IDE: Intellij 14 Community Edition
When I make changes to client java files and click the "compile" button on the code server page, they're not reflected on the webpage. I suspect the code server is not looking at the same sources I'm changing. Specifically i think its looking for sources to compile in target/{project-name}/*
Following is the snippet of the POM file I'm using.
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<!--compilerArgument>-proc:none</compilerArgument-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>${tomcat.context}</path>
<port>${tomcat.webport}</port>
<ajpPort>${tomcat.ajpport}</ajpPort>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${maven.gwt.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<draftCompile>true</draftCompile>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<noServer>true</noServer>
<port>${tomcat.webport}</port>
<runTarget>${tomcat.context}/index.html</runTarget>
<!--codeServerWorkDir>${webappDirectory}</codeServerWorkDir-->
<copyWebapp>true</copyWebapp>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
Any help would be appreciated!!
Because you list src/main/java as a <resource>, its files are copied to the ${project.build.outputDirectory}, and that one comes first in the classpath because you could filter files from <resource> and have <source> and <resource> intersect (which is the case here). See http://jira.codehaus.org/browse/MGWT-290
So either:
remove src/main/java from project resources
remove *.java files from project resources (so at least they're not copied over to the output directory and don't shadow src/main/java)
or run mvn resources:resources each time you change files in src/main/java (like you have to do with files in src/main/resources, because of possible filtering); this can be automated by your IDE or some other tool (e.g. watchman) though.
I would upgrade the project to use gwt-2.7.0 and gwt-maven-2.7.0, then nothing special is needed to run superdev mode among your app in a servlet container, just run mvn gwt:run and point your browser to http://localhost:8888, then each time you change your code just hit refresh in your browser to recompile the app.
As you can see it's pretty simpler, and you would take advance of recompiling in 2.7.0 is a lot faster.
Having tried all possible forums' advice and diverse codeServer launch parameters unsuccessfully, the only means I have found to trigger a refresh without restarting any server is to click again on the bookmark 'Dev Mode Off' followed by 'Dev Mode On' then 'Compile'button ... and the code Server recompiles the changed java source incrementally! (the Dev Mode shortcuts are those you should have dragged from the code server home page like http://localhost:9876 into the browser bookmarks).
A page refresh was enough with "Google Plugin for Eclipse" ( ==GPE, deprecated Jan2018) and -as it seems- no longer with "GWT Eclipse Plugin" (replacing GPE) (appreciate the subtle difference in wordings!)
How do I do something after Maven copies the webapp resources to the war directory inside of the package goal? I want to do something just after it copies the webapp resources to the target's war directory, but just before it finally archives everything into a WAR file.
The reason you're having problems is because the copying of webapp resources is done by the war plugin in the same breath that it builds the war. It's not a different lifecycle phase or even two different actions in the same phase. It's all part of the war:war goal.
There's a workaround, though. If you bind war:exploded to an earlier phase, like prepare-package, then it will build your exploded webapp, and then you can put something after that to modify the files that were built to the exploded directory. Then war:war will package up the modified exploded directory. (With newer versions of the war plugin, I believe you'll need to set the useCache property to get the desired behavior, though that doesn't seem to really be what it's for, be wary.)
I've just had to do the same thing so here's an example for egervari to show what Ryan Stewart is saying.
(This uses the YUI Compressor Maven Mojo to automatically minify js files.)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<warName>${warName}</warName>
<useCache>true</useCache>
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/*.properties</exclude>
</excludes>
<nosuffix>true</nosuffix>
</configuration>
</plugin>
</plugins>
</build>
As documented in the build lifecycle
prepare-package perform any operations necessary to prepare a package
before the actual packaging. This often results in an unpacked,
processed version of the package. (Maven 2.1 and above)
package take the compiled code and package it in its distributable format, such as
a JAR.
You would want to bind your goal which does something to one of these goals, depending on how your pom executes.
I haven't tried this and hence can't say which one with authority.