Maven jetty plugin using wrong resource file URL - maven

I am running a project within a vagrant box setup over my eclipse workspace. I am working on setting up a new maven project but I am having problems with the plugin using windows paths instead of the vagrant path. My windows workspace is setup in C:\Dev, so when I 'vagrant up', my entire workspace is available within my VM. In other words, /vagrant in the VM contains the contents of C:\Dev.
When I execute mvn jetty:run, everything starts up fine and all paths use the vagrant versions (/vagrant/mvn_project/target...). However, once the plugin starts scanning the project for changes, it throws the following error:
2014-02-26 01:18:53.756:WARN:oejw.WebAppContext:Scanner-0: Failed startup of context o.e.j.m.p.JettyWebAppContext#591f46d8{/,[file:/vagrant/mvn_project/web, file:/vagrant/mvn_project/target/webapps/ROOT/],STARTING}{/ROOT/]}
javax.servlet.UnavailableException: Malformed URL 'file://C:\\Dev\\mvn_project/target/webapps/ROOT/WEB-INF/dtd/web-app_2_3.dtd' : For input string: "\\Dev\\mvn_project"
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:402)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:561)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:351)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:840)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:300)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1347)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:745)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.maven.plugin.JettyRunMojo.restartWebApp(JettyRunMojo.java:532)
at org.eclipse.jetty.maven.plugin.JettyRunMojo$1.filesChanged(JettyRunMojo.java:485)
at org.eclipse.jetty.util.Scanner.reportBulkChanges(Scanner.java:681)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:539)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Is this a bug with the plugin or is there a configuration setting I can use to set this value?
Edit: A little more context... It seems that the problem has something to do with filtered resources.
<resources>
<resource>
<directory>${project.basedir}/src/main/filtered-resources</directory>
<filtering>true</filtering>
<targetPath>${project.basedir}/target/webapps/ROOT</targetPath>
</resource>
</resources>
Changing ${project.basedir} to /vagrant/mvn_project seems to fix the problem, but clearly this is just a workaround and not a solution (won't work in CI for example).
UPDATE: It turns out, the blame is on Eclipse. Eclipse is occasionally building the project and when it does so, ${project.basedir} refers to C:\Dev\mvn_project instead of /vagrant/mvn_project. Is there a way to override ${project.basedir} without hard coding?

Simple answer: disable builds in eclipse. Uncheck Project -> Build Automatically. Always run builds from within vagrant (mvn compile). JSP hot changes still work automatically.

Related

Unable to build maven project, pom.xml file not found

We recently lost (i.e they died after SAN failure) build VMs for an inhouse application. Unfortunately, these VMs were never backed up.
The devs that set this environment up have moved on and now I'm trying get these VMs going again as mods are required to this inhouse application. I'm a sys admin not a developer and this is proving harder than I thought...
The VMs that died were a TeamCity server and an Artifactory server.
I've built a new VM with both TeamCity and Artifactory (it should be lightly loaded enough to handle it). I have TeamCity talking to the git repo but when I try and build the project, I get
Non-readable POM /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430/webview/pom.xml: /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430/webview/pom.xml (No such file or directory)
Looking on the file system, indeed there is no pom.xml file at /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430/webview. There is however a pom.xml file in /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430.
Any pointers on how to get Maven to look one directory up for this file?
Thanks
Edit:
Apologies all, I just found that I hadn't correctly defined the "VCS Root", I done that now and am getting further although the project still doesn't build. I'll poke it some more and see how I go.
I just found that I hadn't correctly defined the "VCS Root".
I faced similar issue. Solution is: Please check the module name in parent POM and child pom, both name should be same.
Adding to that Teamcity build using maven thrown me same kind of error with the below message
The project (/opt/buildagent/work/d1df6864f98d2599/pom.xml) has 1 error
Non-readable POM /opt/buildagent/work/d1df6864f98d2599/pom.xml: /opt/buildagent/work/d1df6864f98d2599/pom.xml (No such file or directory)
for me it solved by creating VCSRoot configuration

Share Maven run configurations with other developers using Intellij IDEA

We have the following project setup: Maven, Eclipse, Subversion. Eclipse Launch configurations are in a separate docs folder next to the pom.xml. The launch configurations run something like mvn clean install -Pdev or mvn tomee:run -pl something-ear
The good thing is that a shared run configuration is picked up by the IDE and shown in the External Tools run commands. This way, every developer that checks out this project immediately has access to run the build.
We would like to have something similar using IntelliJ IDEA, but I haven't found a good equivalent. What I have considered so far:
Share run scripts
My first idea was to replace the launch configurations with run scripts. I just could not figure out how to have those run scripts run inside IntelliJ IDEA just the way a Maven goal would be executed.
Share IDEA project configuration
The IDEA project configuration (specifically .idea/runConfigurations) inside the checked out directory is not a good solution. We have (speaking one IDEA project with different IDEA modules depending on the task at hand: as a developer you might need multiple IDEA modules (and sub-modules) in the same IDEA project
An IDEA project consisting of the following modules is not something unusal
projectA/trunk
projectB/tags/1.2
projectC/branches/some-change
My preferred solution would remove all IDE-specific configuration from the repository and have some kind of run definitions either in the project folder or a folder next to the pom.xml that a developer can run from the command line or from her IDE of choice.
The optimal solution would let me define something like this in the pom:
<runConfigs>
<default>clean install</default>
<container>tomee:run -pl something-ear</container>
</runConfigs>
This configuration would then be picked up by the IDE and provided as a run or launch configuration to the developer.
Any ideas or suggestions?
Thank you very much!
My current approach is a hybrid solution:
No configuration in the separate modules
One IDEA project configuration with run configurations managed in VCS
The .idea/runConfigurations directory is versioned separately from the project sources. It contains commands with a working directory set relative to the PROJECT_DIR:
<MavenRunnerParameters>
…
<option name="workingDirPath" value="$PROJECT_DIR$/path/to/submodule" />
</MavenRunnerParameters>
When setting up a new project, the developer also checks out this folder and has a set of pre-configured launch configurations for all projects. The downsides are
All launch configurations are managed centrally instead of with the module
The IDEA project directory has a fixed location relative to the modules. If you set up another project, you will have to change the run configurations
The setup does not clearly state how changes to the launch configurations are shared with other developers

How to update folders automatically with IntelliJ

I have a Maven configuration that copies my web resources to a directory in target. From there it is read by Jetty. What I want (and what Eclipse always did for me) is update the target/web directory when something in the src/main/webapp directory changed. I can't get IntelliJ to do the same:
The resource configuration like this:
<resource>
<directory>src/main/webapp</directory>
<excludes>
<exclude>less/</exclude>
</excludes>
<filtering>false</filtering>
<targetPath>${project.build.directory}/web</targetPath>
</resource>
Right now I have to run the Generate sources and update folders everytime I make a change. Can't IntelliJ Detect this automatically?
Notes:
I do not build a war but a folder distribution.
I already tried moving it to target/generated-sources/web but that makes no difference.
The target/web is not marked as excluded in the module configuration.
The folder is marked as a resource folder. I tried marking it as a source folder but that made no difference.
The problem can be solved by using the File watchers plug-in. This plug-in doesn't ship with IntelliJ by default but it is very useful. From there, you can watch your *.less/html/js files and re-generate them if you edit them. In my case I run the appropriate Maven goals but you can also call the less compiler directly if you want to.
In the configuration set "Output paths to refresh" to the the custom directory you are using (in my case $OutputPath$/web). After that, any change should be refreshed automatically.
I think, yes: try pressing Ctrl+Shift+A, type "Import Maven", click the checkbox "Import Maven project automatically". This will enable auto-import which copies resources as well.

Maven ignores settings.xml file

I have added proxy configuration in settigns.xml file, but it is not used by Maven, i confirmed this by making the settings.xml file invalid. I ran the maven install command to update settings and global-settings to point to the correct file, still no luck. I am using maven3.0.4.
Try running Maven with the -X option. It should print as part of the debug output which settings file is being used.
Since you already tried it with an invalid file, I bet that something is wrong with the location of your file.
It's almost to stupid to tell, but it might save some time for somebody else: If you're using a new computer, make sure file extensions are displayed. Otherwise your "settings.xml" file probably is a "settings.xml.txt" file in fact...
Make sure it is in the right directory (HOME/.m2/settings.xml)
You can find the relevant paths and a proxy example here: Maven proxy settings not working
And of course the reference is always useful: https://maven.apache.org/settings.html
have you tried with these options: from the command line to specify the settings file?
mvn -o –Dmaven.repo.local=$HOME/.my_m2path/repository clean install --settings $HOME/.my_m2path/settings.xml Dcheckstyle.skip=true –DskipTests
Some options that might not be necessary
-o is for offline (unless you have all your repos in your m2, its suggested to skip this option)
skip tests is for skipping tests while building
–Dmaven.repo.local - repo path - if you are having own repo path, then use this option
--settings $HOME/.my_m2path/settings.xml (remember there is space between settings and the path)
Since there is no accepted answer, and I encountered that problem today and other answers proved unhlepful as the file path was correct:
The solution is to restart your computer. No, seriously. After restart maven is guaranteed to read settings.xml file again and use whatever changes you made.
For those using Linux
In the Ubuntu package repository (and probably other disto's too), there are two maven packages: maven and maven2. For some reason, I had maven2 installed, which seems to ignore settings.xml in ~/.m2.
As a solution, I removed it using
sudo apt-get purge maven2
and installed the other one with
sudo apt-get install maven
What's going on?
I couldn't find a reliable source, but apparently, maven2 is an older version (2.x), as the latest maven has version 3.x and is served with maven.
Please make sure you are using the settings.xml which you modified.
for example: your using IDE's embedded maven which using different settings.xml in you operation system.
You can set the path of settings file in Eclipse* as :
In the menubar goto Window -> Preferences
In Preferences Dialog, Goto Maven Section(On the left) and Expand it.
Click on UserSettings.
Add the path of settings file using Browse. The default for most users will be (C:\Users\.m2\settings.xml). It will be shown in grey but you need to actually enter the location.
Click on Update Settings !
You can also enable debug logs and stack traces for debugging by clicking on the Maven Section in the Preferences dialog and Checking the box against the label "Debug Output".
P.S. I am currently using Eclipse(Neon) on Windows 10 x64.
I have also been facing the same issue. I removed the file and folder, but still maven was still picking the settings.
For me, restarting the system solved the issue.
What I found was that even if I set my own maven setting file using the --settings or -s command such as:
mvn -s $MAVEN_HOME/libexec/conf/my-settings.xml clean
Maven was still reading the default global setting.xml
Two ways that one can slove this:
Rename the setting.xml to something like setting.xml.bak in the $MAVEN_HOME/conf dicrectory.
The preferred approach add global to the command -gs hence the final command becomes:
mvn -gs $MAVEN_HOME/libexec/conf/my-settings.xml clean

Jenkins on Jetty - Unable to update plugins

I am after some pointers to the problem I have.
I am installing Jenkin 1.450 on CentOS 5.5. Java has been installed and JAVA_HOME had been set properly.
I deployed Jenkins on Jetty 8.0.4. I downloaded Jetty and extracted onto a user's directory. Jenkins is deployed to Jetty's webapps directory.
Then I created a directory outside Jetty's directory, and set JENKINS_HOME to that directory. Then I also set JETTY_HOME to the extracted jetty directory. Then I run Jetty using jetty.sh script which you can find in /bin.
All worked well and I can add users etc. Then from "Manage Plugins" section I see that there is a newer svn plugins, so I want to update it. So I begin the update process. At the end Jenkins tells me "subversion plugin is already installed. Jenkins needs to be restarted for the update to take effect" - so I restarted Jetty. However, checking the version of svn now it was still the same as before and it tells me again there is a new version.
Can somebody tells me where I did wrong?
Thanks!
Your set up is good. The issue is with Jenkins itself, and a bug has been opened for this on their JIRA:
https://issues.jenkins-ci.org/browse/JENKINS-12514
While this issue was resolved for new plugins in version 1.450, it remains in the upgrade feature.
Related bugs:
https://issues.jenkins-ci.org/browse/JENKINS-12632
https://issues.jenkins-ci.org/browse/JENKINS-12583
I've had the same issue today =)
I tried setting various things in the context:
<Call class="java.lang.System" name="setProperty"> <Arg>HUDSON_HOME</Arg> <Arg>/opt/jenkins</Arg> </Call>
<Call class="java.lang.System" name="setProperty"> <Arg>JENKINS_HOME</Arg> <Arg>/opt/jenkins</Arg> </Call>
However in the end the only thing that worked was to crack open the WAR and add the following to WEB-INF/web.xml (where /opt/jenkins is my jenkins home)
<env-entry>
<env-entry-name>HUDSON_HOME</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>/opt/jenkins</env-entry-value>
</env-entry>
As soon as I did this all the previous installed/upgraded plugins that were marked as missing we present.

Resources