Jetty Maven plugin - Put properties file in classpath - classpath

I'm using the eclipse jetty plugin in my project:
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.3.v20130506</version>
I have my application that read a file in the classpath of the server, but I can't manage to put it in the Jetty classpath...
I would to put it in a folder in my project and make that folder part of the Jetty classpath, how can I do it?
Is there a better solution to make that file external to the application?

It was just a matter of configuration of the maven plugin
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<jettyXml>jetty/jetty.xml</jettyXml>
<webApp>
<extraClasspath>${basedir}/jetty/classpath</extraClasspath>
</webApp>
</configuration>
to add a classpath folder to Jetty, it needs the extraClasspath folder in the webApp tag.

Related

How to use third party JAR into AEM?

I have a jar file that i received from other team and need to use in AEM. I can not use jar directly in AEM so i converted the Jar into bundle with help of the link "https://helpx.adobe.com/experience-manager/kb/ConvertAJarIntoOsgiBundle.html" , Now my bundle is ready and uploaded into AEM through felix console. Bundle is active. Now i need use the classe which are there in bundle to my java classes. How to use that bunlde in java classes . do i need to added the bundle in POM.xml? if so then how i can use that bundle into POM.xml so that my code can complile.
Now my bundle is ready and uploaded into AEM through felix console
That is not a good idea. Yes, you can install bundles from the Felix console but bundles installations in AEM ideally should be managed by the Sling OSGi Installer which can scan the JCR repository for bundles.
As said in the other response, you should put your bundle in a folder named "install" below the /apps folder.
My recommendation would be to use the Maven Content Package Plugin that is used to generate AEM comments to embedd your bundle in your AEM package:
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<configuration>
<failOnMissingEmbed>true</failOnMissingEmbed>
<filterSource>src/main/META-INF/vault/filter.xml</filterSource>
<filters combine.self="override" />
<embeddeds>
<embedded>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.validation-impl</artifactId>
<target>/apps/example/install</target>
</embedded>
</embeddeds>
</configuration>
</plugin>
</plugins>
</build>
Also, dont forget to add /apps/example/install to your filter.xml.
More information on the content package plugin
You can put your lib into src/main/jcr_root/apps/your_app/libs/install folder(path depends on your project structure). Now it will be installed to AEM using maven.
To import necessary classes use provided scope, we have the following configuration for Jedis lib:
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.jedis</artifactId>
<version>2.7.3_1</version>
<scope>provided</scope>
</dependency>

Eclipse plugin with Maven dependencies for third party libraries

I am converting Subclipse to build with Eclipse Tycho and Maven.
Subclipse depends on a few third party JAR files that are not Eclipse plugins so do not exist in any p2 repository. Currently, I just include these in a lib folder within the plugin.
Since these JAR files do exist in Maven, I was hoping that by converting the plugins to build with Maven I could use Maven dependencies. IOW, the plugin would have a pom.xml where I used Maven dependencies to grab and include the third party jar's that have to be included in the plugin. Basically, it would just automate having to refresh what I include in the lib folder of the plugin.
Is this possible? I tried doing what I said above by when I build, I saw no sign that Maven/Tycho was trying to fetch the dependencies. I imagine it is because when the packaging is eclipse-plugin it looks solely at the Eclipse configuration files for the dependency information.
Thanks
To add plain (without OSGi metadata) jar files into your folder at biuild time, you can specify an <execution> of the maven-dependency-plugin to fetch them. However it will require to update your MANIFEST.MF Bundle-Classpath directive whenever a version changes.
It's usually better to hunt for OSGi-able jars or to make an extra effort to package existing libs as OSGi bundles/p2 artifacts like Eclipse Orbit or JBoss Tools Locus do.
Did you try doing the following after adding the dependencies to the pom.xml file?
Project->Clean
Right click on project: Maven->Update dependencies
Right click on project: Maven->Update project configuration
Just adding the plugin to pom dependencies and including the entry <pomDependencies>consider</pomDependencies> in the configuration of target-platform-configuration makes it work.
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<!-- The configuration to make tycho consider the maven dependencies -->
<pomDependencies>consider</pomDependencies>
<!-- other configurations -->
</configuartion>
</plugin>
<!-- other plugins-->
</plugins>
<dependencies>
<!-- An example third-party bundle (plugin) present in maven repository-->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.shell</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
Reference link here.

Maven dependency and eclipse classpath

I tried to search for existing questions but cant find any - feels like my question is quite simple but probably because it's quite specific I cant find the answers on Stackoverflow / Google.
Anyways - I have few projects with Maven that are depend on each other. In certain cases I want the dependency to be on the JAR rather than a project dependency (ie. I want the dependency to be part of the "Libraries" in Eclipse rather than "Projects" in the Build Path).
Your help is greatly appreciated! Thanks
To get the referenced projects in the same workspace as jar files instead of the projects, we could use the VM parameter -Declipse.useProjectReferences=false or add it in the pom file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<useProjectReferences>false</useProjectReferences>
</configuration>
</plugin>
See this URL for more info.
In your project properties in Eclipse, select Maven. There is a checkbox, 'Resolve dependencies from workspace projects'. If this is checked, then the Eclipse projects are used. Otherwise the jars are used as with other maven dependencies, assuming that you've got the dependencies in your pom.xml as normal.
EDIT: If your project is not a maven project, then you'll have to create the jar outside Eclipse and add it as a jar or external jar as normal. If the project is a maven project, then the above will work.
Say Client-Project depends on Services-Project. If Services-Project generates a JAR. In the Client-Project POM you would express a dependency on this JAR. It would be something like:
<dependency>
<groupId>group.id.of.services.project.goes.here</groupId>
<artifactId>artifact.id.of.services.project.goes.here</artifactId>
<version>version.number.of.services.jar</version>
</dependency>
If services project generates a JAR called com.mycompany.services-1.3.jar, the dependency would be:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>services</artifactId>
<version>1.3</version>
</dependency>

Run WAR file in /target directory of Maven project by Tomcat

I'm developing a web application with Java and Maven build system and the web server is Tomcat 7.0.12. After packaging whole project to a WAR file to \target directory by Maven build command, I have to copy it to the webapps folder of Tomcat home to run it. It's very inconvenient, especially when I modified some source files because I have to do all those things (build, copy to Tomcat, run it) again. I've research some articles about Maven, Tomcat, Eclipse on this problem, but there's no result.
Could you please help me:
1. How to make Tomcat run the WAR file on target directory of project which is built by Maven command directly? No need to copy/paste the WAR file and restart Tomcat?
2. How can I configure the Tomcat to debug the web application on Eclipse?
Thank you so much!
BTW, I've read and tried to configure Tomcat, Maven and pom file many times. But I don't know what is the exact configuration, because there are so many advices! Could you provide a particular example of configuration for me?
Here is my configuration files:
Tomcat tomcat-users.xml
<role rolename="manager-gui"/>
<user username="admin" password="" roles="manager-gui"/>
**<role rolename="manager"/>
<user username="admin" password="" roles="manager"/>**
<role rolename="admin-gui"/>
<user username="admin" password="" roles="admin-gui"/>
Maven settings.xml
tomcat
admin
And the pom.xml file of project:
<build>
<finalName>my-project</finalName>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<server>tomcat</server>
<warFile> ${project.build.directory}/${project.build.finalName}.war</warFile>
</configuration>
</plugin>
</plugins>
// Other plugins
</build>
More details:
If I run mvn tomcat:deploy before starting a Tomcat instance, the returned error is "Cannot invoke Tomcat manager: Connection refused: connect."
Otherwise, if a Tomcat instance has been started before calling mvn tomcat:deploy, the error is "Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fmy-project&war=..."
There are a couple of ways to do this.
The tomcat maven plugin http://mojo.codehaus.org/tomcat-maven-plugin/ provides you a way to deploy directly to tomcat from maven. You must have configured your tomcat users first. See http://tomcat.apache.org/tomcat-7.0-doc/config/realm.html for instructions on how to configure your users.
For debugging you can start tomcat with the arguments specified at http://wiki.apache.org/tomcat/FAQ/Developing
The other way would be to configure tomcat to point to your war. See http://tomcat.apache.org/tomcat-7.0-doc/config/context.html particularly the docbase parameter.
EDIT 1
Based on the revised question http 403 is a forbidden this means you didn't authenticate correctly.
Change your tomcat-users.xml to look as follows:
You need to add a refrence to the username/password in your pom.xml.
You settings.xml must contain (based on your configuration)
<server>
<id>tomcat</id>
<username>admin</username>
<password></password>
</server>
Theres a good page http://www.avajava.com/tutorials/lessons/how-do-i-deploy-a-maven-web-application-to-tomcat.html that explains it more fully. However the information may be out of date.
I ran into exactly the same issue.
I suppose it is eclipse-tomcat plugin that is doing this. And I have no idea why it works differently in tomcat 7 opposed to tomcat 6 which I didn't have problem with.
Anyways, what I did was to have maven build into the /web-app/WEB-INF directory
<build>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
...
</build>
After this config, eclipse:eclipse should yield a proper eclipse project/classpath files
resources:resources shoudl work accordingly as well.

GWT Maven and web.xml

I'm using the GWT Maven plugin from Codehaus with m2eclipse. Where is my web.xml file supposed to end up? Isn't the Maven build supposed to copy it to the /war directory? I can't see it there. Or does Jetty pick it up automatically from src/main/webapp/WEB-INF/?
Here's a relevant section from my pom.xml.
<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>
I believe web.xml (and everything else under src/main/webapp/) gets copied into target/<projectname>-<version>/ during the normal maven lifecycle (For example, when you run mvn install).
If you're running any of the gwt-maven plugin goals, then check out this link.
When running gwt:run, if you want to run the full web app just as if you have built and deployed a war, I found the best way is to add the following to the configuration for the gwt-maven plugin:
<hostedWebapp>
${project.build.directory}/${project.build.finalName}
</hostedWebapp>
This tells gwt-maven plugin to look for the web.xml (and all the other parts of the war file) under target/<projectname>-<version>/. So make sure to either run mvn install first (or mvn war:exploded), then run mvn gwt:run and you should be set.