How to deploy WAR using Netbeans 7.3.1 + JBoss AS7 - maven

This is an existing project that builds and deploys just fine using Intellij + AS7. I want to build and deploy using Netbeans 7.3.1 so I created a new Maven project in NetBeans, selecting the "import the project using the Maven pom.xml files" option. NetBeans recognized the modules and used Maven to build the project successfully. Very nice.
Webapp assembled in [931 msecs]
Building war: G:\Patrac_Netbeans\Patrac-web\target\Patrac-web-1.0.war
Next, I started JBoss using NetBeans' Services panel. Next, I clicked the Run Project button, expecting deployment to occur, but NetBeans only rebuilt the project again. And then I remembered configuring Intellij to build & deploy using the target directory. I don't see a way to do this in NetBeans. So, how to set up the deployment using NetBeans?
UPDATE 8/20/2013:
The deployment of the EJB- and WAR modules work. Here's the output when deploying the EJB:
cd G:\Patrac_Netbeans\Patrac-ejb; "JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25" "\"G:\Program Files\NetBeans 7.3.1\java\maven\bin\mvn.bat\"" -Dnetbeans.deploy=true package
Scanning for projects...
Building Patrac EJB module 1.0
...
BUILD SUCCESS
Total time: 8.251s
Finished at: Tue Aug 20 14:33:38 EDT 2013
Final Memory: 22M/364M
NetBeans: Deploying on JBoss Application Server
profile mode: false
debug mode: false
force redeploy: true
Distributing G:\Patrac_Netbeans\Patrac-ejb\target\Patrac-ejb.jar to [org.jboss.as.ee.deployment.spi.DeploymentManagerTarget#45fbf23c]
Deploying G:\Patrac_Netbeans\Patrac-ejb\target\Patrac-ejb.jar
However when I attempt to run the whole application NetBeans doesn't deploy:
cd G:\Patrac_Netbeans; "JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25" "\"G:\Program Files\NetBeans 7.3.1\java\maven\bin\mvn.bat\"" -Dnetbeans.deploy=true package
Scanning for projects...
Reactor Build Order:
PATRAC
Patrac EJB module
Patrac Web module
Building PATRAC 1.0-SNAPSHOT
...
Building Patrac EJB module 1.0
...
Building Patrac Web module 1.0
...
[war:war]
Packaging webapp
Assembling webapp [Patrac-web] in [G:\Patrac_Netbeans\Patrac-web\target\Patrac.war]
Processing war project
Copying webapp resources [G:\Patrac_Netbeans\Patrac-web\src\main\webapp]
Webapp assembled in [557 msecs]
Building war: G:\Patrac_Netbeans\Patrac-web\target\Patrac-web-1.0.war
Reactor Summary:
PATRAC - Physician Assistant Tracking ............. SUCCESS [0.043s]
Patrac EJB module ................................. SUCCESS [8.100s]
Patrac Web module ................................. SUCCESS [2.324s]
BUILD SUCCESS
Total time: 10.882s
Finished at: Tue Aug 20 14:17:34 EDT 2013
Final Memory: 25M/366M
Why in the world does NetBeans not deploy? Perhaps the problem is that it doesn't know where the assembled WAR is located? Looking at the output, it runs Maven from G:\Patrac_Netbeans, which is where the root POM is located. However the assembled WAR is located in G:\Patrac_Netbeans\Patrac-web\target\Patrac.war.
UPDATE 8/21/2013:
Fyi the plugin config was as follows:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
</plugin>
As #happymeal correctly pointed out (see his comment, below), by simply looking at Maven's output the plugin was not running. Thanks to #James R. Perkins I realized there were actually two plugins: jboss-maven-plugin and jboss-as-maven-plugin and because I was using the latter plugin I was using the wrong goal: jboss:deploy instead of jboss-as:deploy. Correcting this mistake and rerunning the project in Netbeans the following error occurred:
Caused by: java.io.FileNotFoundException: G:\Patrac_Netbeans\target\Patrac-1.0-SNAPSHOT.maven-project (The system cannot find the path specified)
Next, I added some configuration parameters that ultimately solved the problem:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<configuration>
<force>true</force>
<targetDir>G:\Patrac_Netbeans\Patrac-web\target</targetDir>
<filename>Patrac-web-1.0.war</filename>
</configuration>
</plugin>
Problem solved!

the default maven goal for the "Run Project" button in netbeans is package. this goal builds the project but does not deploy your app.
you can change this by:
right-clicking on your project and go to properties.
under the categories panel, select actions.
select the "Run Project" action and edit the "Execute Goals" textbox (e.g. jboss:start).
note that you will need the jboss maven plugin.

Related

How do I build a runnable JAR from a WebSphere Liberty / Open Liberty Maven WAR project?

I want to build a runnable/executable JAR (to run with java -jar my.jar), using Open Liberty, from my Maven WAR project.
If I run mvn package I get a WAR, but if I then run mvn liberty:package I get something like:
[INFO] CWWKM2001I: Invoke command is ["C:\git\lmparch1\test\target\liberty\wlp\bin\server.bat", package, defaultServer, --archive="C:\git\lmparch1\test\target\test.jar", --include=runnable].
[INFO] CWWKE0005E: The runtime environment could not be launched.
[INFO] CWWKE0031E: Specified defaultServer server does not exist; use the create action to create a new server. serverPath: C:\git\lmparch1\test\target\liberty\wlp\usr\servers\defaultServer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.531 s
[INFO] Finished at: 2021-04-09T15:32:01-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.openliberty.tools:liberty-maven-plugin:3.3.4:package (default-cli) on project test: CWWKM2002E: Failed to invoke ["C:\git\lmparch1\test\target\liberty\wlp\bin\server.bat", package, defaultServer, --archive="C:\git\lmparch1\test\target\test.jar", --include=runnable]. RC= 2 but expected=[0]. -> [Help 1]
What goals am I supposed to configure and bind to which phases, etc. ?
The answer depends on whether you're using the liberty-maven-app-parent to set up your lifecycle (or similarly binding goals to phases on your own), vs. using something closer to the built-in war lifecycle bindings (without all the extra 'liberty' plugin goal bindings).
Using Liberty Maven app parent (or similar)
First, if you're using the io.openliberty.tools:liberty-maven-app-parent, e.g. from generating with the liberty-archetype-webapp_ then you simply need to use this as your liberty-maven-plugin configuration:
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.3.4</version>
<configuration>
<include>minify,runnable</include>
and do mvn package.
You'll see the runnable JAR created as something like: target/xyz.jar
Using generic WAR project interactively
The simplest way to do this is to let dev mode install Liberty and package and deploy the WAR, then Ctrl+C cancel out of it to package the runnable JAR.
Run mvn liberty:dev to launch "dev mode" and wait for the server install and app deploy
Type <Ctrl+C> when dev mode completes startup (either when you see Liberty is running in dev mode or once you see the app started CWWKT0016I application available message).
Run mvn liberty:package -Dinclude=minify,runnable to generate the runnable JAR (something like: target/xyz.jar).
Using generic WAR project in a CI env (e.g. build pipeline)
If you're running non-interactively, where issuing the Ctrl+C isn't easy, you could do
mvn package liberty:create liberty:install-feature liberty:deploy liberty:package -Dinclude=minify,runnable
We have opened this issue to consider improving this use case.

Where is Vaadin 8 built app (WAR file or other artifacts) being stored in IntelliJ 2017?

When creating a Vaadin app via the simple Maven archetype:
mvn -B archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=8.0.6 -DgroupId=org.test -DartifactId=vaadin-app -Dversion=1.0-SNAPSHOT
…and running via the bundled Jetty servlet container, where is my built web app being stored? Is there a WAR file being generated? If so, where?
I am using Java 8 Update 131 on macOS Sierra 10.12.5 with IntelliJ 2017.1.3.
As far as I know and as the docs suggest, when running mvn jetty:run, no artifact is being built. Instead, using its own internal mechanisms, the maven jetty plugin will (re)load your compiled classes from target\classes
The run goal runs on a webapp that does not have to be built into a WAR. Instead, Jetty deploys the webapp from its sources. It looks for the constituent parts of a webapp in the Maven default project locations, although you can override these in the plugin configuration. For example, by default it looks for:
resources in ${project.basedir}/src/main/webapp
classes in ${project.build.outputDirectory}
web.xml in ${project.basedir}/src/main/webapp/WEB-INF/
The plugin automatically ensures the classes are rebuilt and up-to-date before deployment. If you change the source of a class and your IDE automatically compiles it in the background, the plugin picks up the changed class.
You do not need to assemble the webapp into a WAR, saving time during the development cycle. Once invoked, you can configure the plugin to run continuously, scanning for changes in the project and automatically performing a hot redeploy when necessary. Any changes you make are immediately reflected in the running instance of Jetty, letting you quickly jump from coding to testing, rather than going through the cycle of: code, compile, reassemble, redeploy, test.
... and (may) use the dependencies from the maven repo:
*Note
The classpath of the running Jetty instance and its deployed webapp are managed by Maven, and may not be exactly what you expect. For example: a webapp’s dependent jars might be referenced via the local repository, not the WEB-INF/lib directory.
Some of the above mentioned info can also be observed in the log, when running the plugin (running maven with -X aka debug output on, provides more info):
[INFO] Configuring Jetty for project: vaadin-app
[INFO] webAppSourceDirectory not set. Trying src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = D:\tmp\test\vaadin-app\target\classes
[DEBUG] Starting Jetty Server ...
[INFO] Context path = /
[INFO] Tmp directory = D:\tmp\test\vaadin-app\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[DEBUG] Adding artifact vaadin-server-8.0.6.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact vaadin-sass-compiler-0.9.13.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact sac-1.3.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact flute-1.3.0.gg2.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact vaadin-shared-8.0.6.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact jsoup-1.8.3.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact gentyref-1.2.0.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact vaadin-push-8.0.6.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact atmosphere-runtime-2.4.5.vaadin2.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact vaadin-slf4j-jdk14-1.6.1.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact vaadin-client-compiled-8.0.6.jar with scope compile for WEB-INF/lib
[DEBUG] Adding artifact vaadin-themes-8.0.6.jar with scope compile for WEB-INF/lib
[INFO] web.xml file = null
[INFO] Webapp directory = D:\tmp\test\vaadin-app\src\main\webapp
[INFO] Started Jetty Server
However, if you want to build and deploy a packaged war or an exploded one, you can use the jetty:run-war:
This goal first packages your webapp as a WAR file and then deploys it to Jetty. If you set a non-zero scanInterval, Jetty watches your pom.xml and the WAR file; if either changes, it redeploys the war.
... and/or jetty:run-exploded:
The run-exploded goal first assembles your webapp into an exploded WAR file and then deploys it to Jetty. If you set a non-zero scanInterval, Jetty watches your pom.xml,`WEB-INF/lib, WEB-INF/ and WEB-INF/web.xml for changes and redeploys when necessary.
In target folder after mvn install
After you execute mvn install in Maven, a .war file can be found in the "target" folder.
For example… See this screenshot of a project named TryAgain where the folder target contains the WAR file named tryagain-1.0-SNAPSHOT.war.
The details on the documentation of the Maven War Plugin usage states that:
Invoking
mvn package
or
mvn compile war:war
shall generate the WAR file target/vaadin-app-1.0-SNAPSHOT.war
Additionally linking the vaadin-docs which also state that after executing mvn package
The location of the resulting WAR package should be displayed in the command output.

Where to add dependencies in MAVEN multi-module project

I am trying to make sense of all the dependency thing in maven multiple module projects. As a starting point I used appfuse to create a new spring mvc multi-module project. It initially has web and core modules.
I found the knowledge of deploying this project. But when I get an error. I am confused of where to add a dependency or a plugin always. I would like to clarify with the following issue.
I created a appfuse mvc multimodule project. I maven installed the core and then maven jetty7:run on web (initially I ran mvn install on root folder and then I tied to mvn tomcat:run on the same folder. But it has to be done as below.
mvn install on core folder
mvn tomcat7:run on web folder
I initially got an error like missing prefix "Tomcat7". I resolved it by adding the following plugin to the pom in web.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
And that error was resolved. But I was unsure about that because I can add the plugin to the parent pom. Then I ran again mvn tomcat7:run on web file and now I am getting the following error.
[INFO] >>> tomcat7-maven-plugin:2.0:run (default-cli) # test-web >>>
[WARNING] The POM for org.aspectj:aspectjweaver:jar:1.8.0.M1 is missing, no depe
ndency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
I am not sure where to add the dependency to which pom. I would like know some basics of how the poms can work together to do the installation. For example, There is also a parent pom. But I am not doing a mvn install or anything on the parent pom. I am going to the core and do a mvn install and then go to the web and do a mvn tomcat7:run
I this case how the parent pom contribute to the installation and ruining process? and how should I resolve the above warning and resolve the error.
Some informative answer is very much appreciated. Thanks
You should add the Tomcat plugin to the web project as it will only work in a project that's type "war". There should already be a jetty plugin configured, so "mvn jetty:run" should work from the web folder.

Jenkins Build fails while compiling java code using Maven

I have a Java application and I am able to compile it using maven on CLI, I have a couple of build scripts to deploy the Java code to a remote server and compile the code using Maven but unfortunately the build fails while compiling it using my build script for Jenkins. When I try to compile the code on the remote server the build is successful. The error log is as follows:
[WARNING] The POM for org.im4java:im4java:jar:1.3.2 is missing, no dependency information available
[WARNING] The POM for com.aliyun:aliyun-openservices:jar:1.0.0-20120705 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] GuestPath Project ................................. SUCCESS [5.183s]
[INFO] guestchat biz module .............................. FAILURE [4.001s]
[INFO] GuestChat Web Common .............................. SKIPPED
[INFO] GuestChat Portal Webapp ........................... SKIPPED
[INFO] guestchat openapi Webapp .......................... SKIPPED
[INFO] guestchat chat server ............................. SKIPPED
[INFO] guestchat service dashboard Webapp ................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.518s
[INFO] Finished at: Wed Sep 19 10:49:39 CST 2012
[INFO] Final Memory: 9M/23M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project guestchat-biz:
Could not resolve dependencies for project com.guestops.guestchat:guestchat-biz:jar:1.0.0-SNAPSHOT:
The following artifacts could not be resolved:
org.im4java:im4java:jar:1.3.2, com.aliyun:aliyun-openservices:jar:1.0.0-20120705:
Failure to find org.im4java:im4java:jar:1.3.2 in http://repo.maven.apache.org/maven2
was cached in the local repository, resolution will not be reattempted until
the update interval of central has elapsed or updates are forced -> [Help 1]
I hope I am being clear enough, any help is highly appreciated. I can provide with more details if needed..Thanks in advance!
I think you should try to do the following:
Try to compile the project locally but make sure you're downloading the artifacts from the maven repository. Radically you can do it by renaming your ~user/.m2/repository and running ''mvn clean install''
If it compiles - your local maven is configured properly and its not a pom.xml issue. Also the remote repositories are configured right in maven. In this case its a jenkins issue or rather the issue of maven installed on the same machine with jenkins or maybe some network/security related issue (like a connection to the remote repository is firewalled and not accessible from the jenkins machine and so on).
I would suggest to check out the repository configuration on that maven, or if you want checkout the source code of your project on the jenkins machine and manually run the first step described above from that machine. You should see that the code can't be compiled and get the same error you're getting now.
Now if in during the step 1 the project can't be compiled - its just because you have had a dependency on the lacking module and they were somehow presenting in your local repository (I assume previously it could be compiled locally) and since we're kind of running a clean installation the local repository 'gets purged'. In this case you should find out where do your dependencies come from.
Things like
mvn dependency:tree on the failing module
Can be helpful here.
Hope this will help somehow
2 possible quick solutions:
If it compiles locally, then go to the build configuration on Jenkins and check the "Poll SCM" option to do polling on every build.
Run from the command line on Jenkins server mvn clean install and make sure that the artifacts are available in maven repository after the build. If they are not, download the jars of the relevant versions and put them in the local maven repository (on Jenkins server).
Good luck!
This is what the error message tells you:
The following artifacts could not be resolved:
org.im4java:im4java:jar:1.3.2,
com.aliyun:aliyun-openservices:jar:1.0.0-20120705: Failure to find
org.im4java:im4java:jar:1.3.2 in http://repo.maven.apache.org/maven2
So you have references in your pom for im4java 1.3.2 and aliyun-openservices 1.0.0-20120705, but these cannot be found in the general maven repo. If you do a search for im4java in mvnrepository.com, you'll see that it only has version 1.2, so it is reasonable that it would fail. aliyun-openservices package doesn't exist there at all.
So, where should those be found? Maybe you have installed them locally only and not to Jenkins machine?
What you can do then, is either
(recommended) set up an intranet maven repo where you would deploy the needed libraries and reference that or
install them locally on the machine running Jenkins
Both of these should fix the issue.
A quick look on maven repository, only version 1.2.0 is available and not version 1.3.2 (which you are using).
Does your code compile with a maven build?
I suggest you try to review the repository setting on the jenkins instance

maven: war:war rebuilds war even when content unchanged - why?

why does maven ear plugin runs the war:war (plugin goal) when I try to build the ear project from netbeans
my process:
I right click on the ear project (which has the war dependency listed) and first Clean and then right click on it and select Build with Dependencies. Then it builds the war again using the war:war and it takes time. even though there was no change in the war but will re create it again.
this is what it says :
------------------------------------------------------------------------ Building finweb 1.0-SNAPSHOT
------------------------------------------------------------------------ The POM for org.netbeans.external:jdom-1.0:jar:RELEASE71 is missing,
no dependency information available The POM for
com.ibm:com.ibm.mq:jar:6.0.2.5 is missing, no dependency information
available The POM for com.ibm:com.ibm.mqbind:jar:6.0.2.5 is missing,
no dependency information available The POM for
net.sf.saxon:saxon:jar:10.0-b19 is missing, no dependency information
available
[dependency:copy]
[resources:resources] Using 'UTF-8' encoding to copy filtered
resources. skip non existing resourceDirectory
C:\Beta\fin\finweb\src\main\resources
[compiler:compile] Nothing to compile - all classes are up to date
[resources:testResources] Using 'UTF-8' encoding to copy filtered
resources. skip non existing resourceDirectory
C:\Beta\fin\finweb\src\test\resources
[compiler:testCompile] Nothing to compile - all classes are up to date
[surefire:test] No tests to run. Surefire report directory:
C:\Beta\fin\finweb\target\surefire-reports
------------------------------------------------------- T E S T S
------------------------------------------------------- There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[war:war] Packaging webapp Assembling webapp [finweb] in
[C:\Beta\fin\finweb\target\finweb-1.0-SNAPSHOT] Processing war
project Copying webapp resources
[C:\Beta\fin\finweb\src\main\webapp] Webapp assembled in [109467
msecs] Building war:
C:\Beta\fin\finweb\target\finweb-1.0-SNAPSHOT.war WEB-INF\web.xml
already added, skipping
[install:install] Installing
C:\Beta\fin\finweb\target\finweb-1.0-SNAPSHOT.war to C:\Documents
and
Settings.m2\repository\com\comp\finweb\1.0-SNAPSHOT\finweb-1.0-SNAPSHOT.war
Installing C:\Beta\fin\finweb\pom.xml to C:\Documents and
Settings\5510041.m2\repository\com\comp\finweb\1.0-SNAPSHOT\finweb-1.0-SNAPSHOT.pom
So if there is nothing to compile why would it build a war again if it was already made and there are no changes. is this the default behaviour, looking at compile : compile when it doesnt compile if there is nothing needed then why does war:war does it, it shud be intelligent enuff to do it right?
pls correct me if I am wrong
Thanks in advance..
Syed.
This may be considered as workaround.
Following configs will speed up your build time.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<useCache>true</useCache>
<recompressZippedFiles>false</recompressZippedFiles>
</configuration>
</plugin>
Reference :https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
Also am looking forward for easy way to skip war:war phase from maven default build lifecycle.
Your concern can be understood. But in principle maven-war-plugin does not know that the resulting WAR artifact will be identical to one which was build a minute ago because:
You might define MANIFEST entry that contains the current build time.
You might enable different profile, which will change the picture completely.
Other plugins (like maven-ant-plugin, maven-dependency-plugin) might add something to target directory depending on some changing conditions (e.g. property from command line).
So it is safer to rebuild war each time. On modern platforms this is really negligible.

Resources