I've set up a Vagrant VM running Java/Maven/Tomcat. I've then taken an application I'm working on and copied the war to the shared folder that the VM has access to, namely webapps. I hunted around as didn't want to be copy / pasting when it should be automated and found reference to a maven plugin:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>/Username/Development/temp/vagrant-tomcat-2/vagrant-ubuntu-tomcat7/tomcat/webapps</outputDirectory>
</configuration>
</plugin>
</plugins>
I've added this to my build. Made a simple change to the index and ran clean install. My console panel looks as I'd expect it to, the war is being copied across - magic.
[INFO] Installing Username/Development/temp/vagrant-tomcat-2/vagrant-
ubuntu-tomcat7/tomcat/webapps/FitnessTracker.war to Username/.m2/repository/com/pluralsight/FitnessTracker/0.0.1-SNAPSHOT/FitnessTracker-0.0.1-SNAPSHOT.war
[INFO] Installing Username/Development/temp/vagrant-tomcat-2/Spring Tutorial - JPA Hibernate/spring_mvc_base-master/pom.xml to Username/.m2/repository/com/pluralsight/FitnessTracker/0.0.1-SNAPSHOT/FitnessTracker-0.0.1-SNAPSHOT.pom
I then reload the port and get a resource is not available error. Commenting out the plugin and running clean install again has the effect of copying the last changes I made to the webapp folder so that If I then check the port I'll see the changes.
What am I missing? I'm certain it's something daft.
The short short version: the maven plugin appears to be copying the last updated war instead of the current one, I think.
Related
I'm not well experienced in java.
I build a UI using JSP for my servlets to get input data from users. Everytime I want to see the UI and how the Servlets are performing I have to do all thses steps over and over again,
create the war file by mvn clean install
Copy war file to Webapps folder
restart apache tomcat
View the result using the url
I want to know if there is a command that i can use to rerun apache tomcat with the war file im building at once, So that i only have to refresh the webpage to see the result. Or any method that is easier than above.
I use Intellij Idea.
Thanks in advance.
IntelliJ IDEA Community Edition does not support J2EE, but you can also achieve this in the following two ways. For full support of tomcat, you can buy IntelliJ IDEA Enterpries Edition.
Use maven-compiler-plugin
1) Add this plugin to your pom.xml:
<build>
<finalName>mvn-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
</plugins>
</build>
2) Then run this command:
mvn tomcat:run
Or Install Tomcat Runner Plugin
Refer to this link for usage of this plugin.
May be this will help you to deploy the war file on server
I've recently started using maven with eclipse.
I've set up several projects and I've noticed that if I try and specify a build directory (to over-ride target) which is outside the project directory, I get an error when doing "update project":
'Updating Maven Project' has encountered a problem.
An internal error occurred during: "Updating MAven Project".
Path must include project and resource name: /[my project name]
I need to build outside the project. How can I get around this? Can I perhaps have maven automatically create a softlink?
Although this is a fairly old thread, I recently encountered this problem and was able to solve it. The reason why maven threw this error is I had, somewhere in my pom.xml file, an absolute path that was not consistent with the directory from which the project was imported into eclipse. So I had two absolute paths (one incorrect, or points to a previous location) that point to resources, i.e. project.build.outputDirectory, in the pom.xml file.
The Solution: Locate the faulty absolute path, /home/userA/ProjectB/bin, and replace with a relative, ./bin, path. Update the project in eclipse and you should be fine.
This is a bit old thread, but since nobody gave a correct answer...
The following Eclipse error:
An internal error occurred during: "Updating Maven Project".
java.lang.IllegalArgumentException: Path must include project and resource name:
at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2069)
at ...
can occur in many different scenarios - in the Eclipse Bugzilla you can find a lot of similar bug reports.
In situation you described, it is a known limitation. But it's not a m2e fault - simply Eclipse JDT does not allow setting output dir outside of the project.
IMHO it's a pity, because if maven supports a such layout, so I would expect that m2e should as well.
I've reported it as a bug 493229. But it has been closed with status WONTFIX.
To answer the last paragraph in your question, you can get around the problem with a softlink. I did it a little differently than what you guessed at. It's not Maven that creates the symlink because this is a problem with Eclipse JDT (as others have pointed out) which runs without invoking Maven at times (it seems). Here's what I did, with all paths relative to my Maven project directory:
1) I wanted my actual build directory to be "../../local/java/scratch/target"
2) I created a softlink: ln -s ../../local ./
3) I added this entry to my "pom.xml":
<build>
<directory>${project.basedir}/local/java/scratch/target</directory>
</build>
Now Eclipse JDT happily thinks it's building within the project directory but in reality the path "../../" takes it outside of the project directory. My guess is that an absolute path would have worked too.
For example, if you'd like to have build contents in some folder outside workspace, you can have something like :
<build>
<plugins>
<plugin>
<executions>
<execution>
<phase>move-build</phase>
////do your build
</plugin>
<plugin>
<executions>
<execution>
<id>copy-resources</id>
<phase>move-build</phase>
// do your copying to external
</plugin>
<plugin>
<executions>
<execution>
<phase>move-build</phase>
// do your deletions from target
</plugin>
</plugins>
</build>
then you can call mvn move-build to have your build, copy, delete done.
here is an example of copy to external folder and delete, you can combine both into your move-build phase as described above
why can't I build somewhere like ../build
Yes you can build in some folder called build provided it contains the pom.xml.
The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project.
In short the pom.xml will have all information to build your project.
pom.xml is a file which contains the project configuration details used by Maven. It provides all the configuration required for a project.
I was convinced that this problem was caused by either Maven or Eclipse, perhaps because I found this and other references to that combination on Stackoverflow.
After considerable investigation, and going slightly mad, it turns out that Git was involved - though I don't know if it was the cause.
My Maven project consists of several "nested" POMs, and I don't open the parent POM in Eclipse, but only the children. I had a couple of files (batch scripts) at the top level which I hadn't committed to Git, but once I committed these the
Path must include project and resource name
problem disappeared completely.
Eclipse version: 2020-12 (4.18.0)
This is my first time using maven on a project. Basically, I am working in the src on a webapp and when I am ready to push a change to the target i do a mvn clean install (this was what I was told to do).
The issue is that if I am just making a minor html tweak in a jsp and want to see the results I have to wait for tests, compile copy the war over deploy, server restart and then I have to log in again.
There's got to be a better way to do this. It's making my development speed slow to a crawl.
You can use maven tomcat plugin to run an in-memory tomcat over your maven project. Any jsp or static resource changes will apply immediately. Java code changes still require you to manually stop and start the server.
To do so use following maven goal
mvn clean tomcat:run
One other choice is jetty plugin. add jetty plugin to pom.xml,and run,that's ok.
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.11.v20130520</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<contextPath>/</contextPath>
</configuration>
</plugin>
</plugins>
</build>
run your application:
mvn jetty:run
I'd like to compress all of my javascript files and aggregate them
using YUICompressor, and I saw that there was a maven plugin to allow
me to do this. I got it working for the most part.
I am also using the Mojo tomcat plugin as well. When i go to run the
tomcat:run goal, tomcat does not read from the target's output
directory (this is where the YUI compressor put my javascript files) -
but rather, it reads from the actual source files in my "src/main/
webapp/scripts" directory. Of course, the aggregated javascript file
(all.js) is not there.
I have a few questions.
How can I get the tomcat plugin to read the target's output folder
that the yui compressor plugin created?
Do I have to run the yui compressor maven goal every time I want to
update my javascript files during development?
Is there a better way to achieve this? Essentially, my end goal is
to be able to develop JavaScript and test my source files in
development mode, but I want to compress and aggregate the files and
use the all.js script when the application is running in production
mode.
While the Rails people have certainly figured this out, this seems to
be a non-trivial thing to do with Maven and Spring.
I would appreciate any and all assistance on how I can get this
running correctly. Thanks!
I was just investigating this very problem and found my answer by looking at the plugin documentation.
mvn tomcat:run - Runs the current project as a dynamic web application
using an embedded Tomcat server.
What this means in practice is that the package execution phase has not been reached when the embedded tomcat runs.
The answer is to instead use:
mvn tomcat:run-war - Runs the current project as a packaged web
application using an embedded Tomcat server.
This allows the maven build to get as far as packaging the WAR file and therefore allows the yuicompressor-maven-plugin to do what it needs to before the embedded tomcat starts up.
As for having to run it every time, you should attach the run of the yui plugin to the "generate-sources" execution phase.
Add the following to your plugin (the important part is the "phase" element to attach it to the lifecycle):
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>...</configuration>
</plugin>
This way the plugin will run every build during the generate-sources phase. So any time you change your java scripts which you have configured the plugin for, the output .js file will be updated as soon as you run something like:
mvn compile
mvn test
mvn install
mvn package
and so forth.
The above does cause the minified (and possibly aggregated) files to be created earlier in the lifecycle but tomcat:run cannot find them!
Over the past few days I have been trying to create/run a project in Eclipse using the gwt-maven-plugin and keep running into roadblocks (see some of my previous questions). I like to use Maven to do my builds, but I'm at the point where I'm thinking of going the Ant build route because of the complications of using Maven.
Does anyone out there have it configured/working well? Is it just me or is this harder than it should be?
After much frustration trying to get things to play nicely together, this is the setup I have that "works" for me. "Works" meaning that I can create, run and debug a GWT project with tweaks, but it isn't the most elegant solution.
Create Project
Much of the steps are the same as Pascal's answer in this post: Maven GWT 2.0 and Eclipse. I'll list mine out to be clear.
In Eclipse (Helios) with m2eclipse and GWT Eclipse plugins installed:
Create a new Maven project using the gwt-maven-plugin archetype
Modify the pom.xml:
set <gwt.version property> to 2.0.4
(needs to be same as GWT Eclipse
Plugin version)
set <maven.compiler.source> and
<maven.compiler.target> properties to
1.6
remove <goal>generateAsync</goal>
from gwt-maven-plugin <plugin> config
add maven-war-plugin to pom.xml
maven-war-plugin example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<warSourceDirectory>war</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
Update project Properties:
Google -> Web Toolkit, check the "Use Google Web Toolkit" box, and ensure "Use default SDK (GWT-2.0.4) is selected.
Run Maven "gwt:eclipse" goal on project (sets up environment and launch config)
Copy *.launch file to workspace.metadata.plugins\org.eclipse.debug.core.launches
Restart Eclipse
Compile/Run Project
I created a Run Configuration that does mvn clean compile gwt:run. The gwt:run is necessary to copy the resources and lib jars into the war directory. However, it does not copy the web.xml from src/main/webapp/WEB-INF into war/WEB-INF/. So, I have to manually copy that file.
If I want to run my application, the above step is sufficient. However, if I want to debug the application, I launch it by choosing the Google "Web Application" configuration from Debug Configurations that was created when the .launch file was copied previously. This configuration allows for debugging (breakpoints etc.) without any other config or need for remote debugging.
It is harder then it should be, however it is possible. All hints posted here can do the trick. However you can still have classloading issues. I decided to switch to GWT 2.1 and use new abilities of JettyLauncher. You can create own jetty launcher like this:
public class MyJettyLauncher extends com.google.gwt.dev.shell.jetty.JettyLauncher {
#Override
protected WebAppContext createWebAppContext(TreeLogger logger, File appRootDir) {
return new WebAppContext(appRootDir.getAbsolutePath(), "/");
}
}
And then add -server MyJettyLauncher option to your gwt launcher configuration. With such configuration all the libraries are managed by m2eclipse (you can even remove GWT SDK from classpath) and there is no need to copy anything to WEB-INF/lib (you can remove gwt-servlet.jar which could be already there).
Ready launcher is here in tadedon library:
http://code.google.com/p/tadedon/source/browse/tadedon-gwt-dev/src/main/java/com/xemantic/tadedon/gwt/dev/JettyLauncher.java
Yes, in 2016 it does, quite nicely indeed. :)
I launch Tomcat from within Eclipse, I launch GWT codeserver (SuperDev mode) from Eclipse, I launch Chrome from Eclipse.
You will find quite recent and very valuable set-up tutorials on Brandon Donnelson's YouTube channel: https://www.youtube.com/user/branflake2267/videos
What is essential for me is Eclipse debugger for GWT SuperDevMode: https://sdbg.github.io/
I prefer to have my project "mavenized", and there is lot of Maven archetypes also provided by Brandon: https://github.com/branflake2267/Archetypes/tree/master/archetypes
The official starting point (not just) for downloading the GPE plugin (not to confuse with above mentioned debugger plugin) is on GwtProject.com: http://www.gwtproject.org/download.html
For me personally GPE itself has become rather optional "convenience" component. (Yes, refactoring and auto-completion are nice to have, but that's all it is needed for. :)
It is not a one-click solution, and I prefer it like that, as those tend to be black-boxes prone to breaking.
And BTW make sure to take a look at GWT Material: http://gwtmaterialdesign.github.io/gwt-material-demo/
(Currently playing with 2.8-beta1.)
For Eclipse I use: m2eclipse plugin (1.0). It works well with one or two minor things. Also download the m2eclipse-extras plugin to add SVN functionality AND Maven (or CVS if you prefer).
When you download then your project it reads the pom.xml and [re]creates the Eclipse configuration files like the mvn eclipse:eclipse command.
For GWT... I've used it too. It's a pretty twiked configuration but it works. I use GWT 2.0.3, the maven-gwt-plugin uses the dependencies to work (no ref to GWT SDK) and it can debug from Eclipse which is simply great.
You have to compile to a war directory (not the target/classes standard). But the details are in my work, so let me see it tomorrow and complete this answer :) Don't give up. It's a great thing to have GWT+Eclipse+Maven.
Edit: part of my configuration
<build>...
<outputDirectory>war/WEB-INF/classes</outputDirectory>
...
</build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<gwtVersion>${gwt.version}</gwtVersion> <!-- para forzar que use el de maven y no el SDK instalado -->
<disableCastChecking>true</disableCastChecking>
<disableClassMetadata>true</disableClassMetadata>
<runTarget>/subscriber/listSubscribers.htm</runTarget>
<webappDirectory>${basedir}/war</webappDirectory>
<soyc>true</soyc>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- dont know/remember if the jetty inside the gwt uses this... but it doesnt hurt-->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.14</version>
<configuration>
<webAppConfig>
<contextPath>/magazine</contextPath>
<baseResource implementation="org.mortbay.resource.ResourceCollection">
<resourcesAsCSV>
${basedir}/src/main/webapp,
${basedir}/war
</resourcesAsCSV>
</baseResource>
</webAppConfig>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8888</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargets>
<scanTarget>${basedir}/war</scanTarget>
</scanTargets>
</configuration>
</plugin>
AND
For debugging I create two tasks:
1) maven build inside eclipse that runs two goals: war:exploded gwt:debug
The first one copies all the resources into war directory for gwt debug to use them.
Next the gwt is ready.
Maybe you need to execute gwt:compile for the first time
2) a Java Remote Application debug configuration, with your project selected.
You run this configuration when the gwt:debug is "listening at port 8000"
AND: this is in a parent pom.xml (sorry I'll edit this post later :)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
<warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
<webappDirectory>${basedir}/war</webappDirectory>
<warName>${artifactId}</warName>
</configuration>
</plugin>
helios wrote good explanation. But it's not actual at the moment. So I advice you to try my modern example of EAR application running on GlassFish and with full debug support.