How to compile on save? - netbeans

I would like to compile the project every time I save, but in properties this option is greyed, so for any change I do I have to click save then clean and build.
How can I do to avoid to clean and build for every code modification?

Change your netbeans project's project.properties like below.
Find below line in project.properties file
compile.on.save.unsupported.javafx=true
Change this value to set to false
compile.on.save.unsupported.javafx=false
After change this file, compile on save option will be enabled and you are good to go.

Answer for Apache NetBeans 9, 10, 11 using Maven.
Configuration is set at nbactions.xml file, usually it'll look similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>war</packaging>
<packaging>ear</packaging>
<packaging>ejb</packaging>
</packagings>
<goals>
<goal>package</goal>
</goals>
</action>
</actions>
To activate the Compile On Save option you only need to add the <netbeans.compile.on.save> setted to all, it'll look like this:
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>war</packaging>
<packaging>ear</packaging>
<packaging>ejb</packaging>
</packagings>
<goals>
<goal>package</goal>
</goals>
<properties>
<netbeans.compile.on.save>all</netbeans.compile.on.save>
</properties>
</action>
</actions>
Also...
At latest NB 10 and 11 you may see the warning It is recommended to install nb-javac Library to improve Java editing experience and enable compile on save at Notifications section:
You just need to install that plug-in (nb-javac) by clicking on that link, more info here, there's currently an open issue for NB11.2, if you have problems with it try using beta 3 (or latest)

You should choose the Sources rather than Build from the Categories.

Related

Partly mirrored p2 repository does not contain installable units - "There are no items available" in Eclipse

I want to mirror some features from the latest Orbit update site. I use the configuraiton below. (This configuration is taken it from the effective pom, to make sure that this is really the configuration I used.)
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-p2-extras-plugin</artifactId>
<version>0.18.0</version>
<executions>
<execution>
<id>mirror-orbit-R20130827064939</id>
<phase>prepare-package</phase>
<goals>
<goal>mirror</goal>
</goals>
<configuration>
<source>
<repository>
<url>http://download.eclipse.org/tools/orbit/downloads/drops/R20130827064939/repository</url>
<layout>p2</layout>
</repository>
</source>
<ius>
<iu><id>com.google.guava</id></iu>
<iu><id>com.google.guava.source</id></iu>
<iu><id>org.mockito</id></iu>
<iu><id>org.mockito.source</id></iu>
<iu><id>org.junit</id></iu>
<iu><id>org.junit.source</id></iu>
<iu><id>org.objenesis</id></iu>
<iu><id>org.objenesis.source</id></iu>
<iu><id>org.hamcrest</id></iu>
<iu><id>org.hamcrest.core</id></iu>
<iu><id>org.hamcrest.core.source</id></iu>
<iu><id>org.hamcrest.text</id></iu>
<iu><id>org.hamcrest.text.source</id></iu>
<iu><id>org.hamcrest.library</id></iu>
<iu><id>org.hamcrest.library.source</id></iu>
<iu><id>org.hamcrest.integration</id></iu>
<iu><id>org.hamcrest.integration.source</id></iu>
<iu><id>org.hamcrest.generator</id></iu>
<iu><id>org.hamcrest.generator.source</id></iu>
<iu><id>org.slf4j.log4j</id></iu>
<iu><id>org.slf4j.log4j.source</id></iu>
<iu><id>org.slf4j.api</id></iu>
<iu><id>org.slf4j.api.source</id></iu>
<iu><id>javax.servlet</id></iu>
<iu><id>javax.servlet.source</id>
</ius>
<destination>/somefolder/mirror/orbit/R20130827064939</destination>
</configuration>
</execution>
</executions>
</plugin>
I build the maven pom, and the mirrored repository seems to be ok:
R20130827064939
-plugins
--com.google.guava_12.0.0.v201212092141.jar
--com.google.guava_12.0.0.v201212092141.jar.pack.gz
--com.google.guava.source_12.0.0.v201212092141.jar
--com.google.guava.source_12.0.0.v201212092141.jar.pack.gz
--com.thoughtworks.qdox_1.6.3.v20081201-1400.jar
--com.thoughtworks.qdox_1.6.3.v20081201-1400.jar.pack.gz
--javax.annotation_1.0.0.v201209060030.jar
--javax.annotation_1.0.0.v201209060030.jar.pack.gz
--javax.annotation_1.1.0.v201209060031.jar
--javax.annotation_1.1.0.v201209060031.jar.pack.gz
--javax.servlet_3.0.0.v201112011016.jar
--javax.servlet_3.0.0.v201112011016.jar.pack.gz
--javax.servlet.source_3.0.0.v201112011016.jar
--javax.servlet.source_3.0.0.v201112011016.jar.pack.gz
--javax.xml_1.3.4.v201005080400.jar
--javax.xml_1.3.4.v201005080400.jar.pack.gz
--org.apache.ant_1.8.2.v201303080311.jar
--org.apache.ant_1.8.2.v201303080311.jar.pack.gz
--org.apache.ant_1.8.3.v201303080312.jar
--org.apache.ant_1.8.3.v201303080312.jar.pack.gz
--org.apache.ant_1.8.4.v201303080030.jar
--org.apache.ant_1.8.4.v201303080030.jar.pack.gz
--org.apache.batik.css_1.7.0.v201011041433.jar
--org.apache.batik.css_1.7.0.v201011041433.jar.pack.gz
--org.apache.batik.dom_1.7.0.v201011041433.jar
--org.apache.batik.dom_1.7.0.v201011041433.jar.pack.gz
--org.apache.batik.util_1.7.0.v201011041433.jar
--org.apache.batik.util_1.7.0.v201011041433.jar.pack.gz
--org.apache.batik.util.gui_1.7.0.v200903091627.jar
--org.apache.batik.util.gui_1.7.0.v200903091627.jar.pack.gz
--org.apache.batik.xml_1.7.0.v201011041433.jar
--org.apache.batik.xml_1.7.0.v201011041433.jar.pack.gz
--org.apache.xerces_2.8.0.v200803070308.jar
--org.apache.xerces_2.8.0.v200803070308.jar.pack.gz
--org.apache.xml.resolver_1.1.0.v200806030311.jar
--org.apache.xml.resolver_1.1.0.v200806030311.jar.pack.gz
--org.apache.xml.resolver_1.2.0.v201005080400.jar
--org.apache.xml.resolver_1.2.0.v201005080400.jar.pack.gz
--org.easymock_2.4.0.v20090202-0900.jar
--org.easymock_2.4.0.v20090202-0900.jar.pack.gz
--org.hamcrest_1.1.0.v20090501071000.jar
--org.hamcrest_1.1.0.v20090501071000.jar.pack.gz
--org.hamcrest.core_1.1.0.v20090501071000.jar
--org.hamcrest.core_1.1.0.v20090501071000.jar.pack.gz
--org.hamcrest.core_1.3.0.v201303031735.jar
--org.hamcrest.core_1.3.0.v201303031735.jar.pack.gz
--org.hamcrest.core.source_1.3.0.v201303031735.jar
--org.hamcrest.core.source_1.3.0.v201303031735.jar.pack.gz
--org.hamcrest.generator_1.1.0.v20090501071000.jar
--org.hamcrest.generator_1.1.0.v20090501071000.jar.pack.gz
--org.hamcrest.generator.source_1.1.0.v20090501071000.jar
--org.hamcrest.generator.source_1.1.0.v20090501071000.jar.pack.gz
--org.hamcrest.integration_1.1.0.v201303031500.jar
--org.hamcrest.integration_1.1.0.v201303031500.jar.pack.gz
--org.hamcrest.integration.source_1.1.0.v201303031500.jar
--org.hamcrest.integration.source_1.1.0.v201303031500.jar.pack.gz
--org.hamcrest.library_1.1.0.v20090501071000.jar
--org.hamcrest.library_1.1.0.v20090501071000.jar.pack.gz
--org.hamcrest.library.source_1.1.0.v20090501071000.jar
--org.hamcrest.library.source_1.1.0.v20090501071000.jar.pack.gz
--org.hamcrest.text_1.1.0.v20090501071000.jar
--org.hamcrest.text_1.1.0.v20090501071000.jar.pack.gz
--org.hamcrest.text.source_1.1.0.v20090501071000.jar
--org.hamcrest.text.source_1.1.0.v20090501071000.jar.pack.gz
--org.junit_3.8.2.v3_8_2_v20130308-0410.jar
--org.junit_3.8.2.v3_8_2_v20130308-0410.jar.pack.gz
--org.junit_4.10.0.v4_10_0_v20130308-0414.jar
--org.junit_4.10.0.v4_10_0_v20130308-0414.jar.pack.gz
--org.junit_4.11.0.v201303080030.jar
--org.junit_4.11.0.v201303080030.jar.pack.gz
--org.junit_4.7.0.v4_7_0_v20130308-0411.jar
--org.junit_4.7.0.v4_7_0_v20130308-0411.jar.pack.gz
--org.junit_4.8.1.v4_8_1_v20130308-0412.jar
--org.junit_4.8.1.v4_8_1_v20130308-0412.jar.pack.gz
--org.junit_4.8.2.v4_8_2_v20130308-0413.jar
--org.junit_4.8.2.v4_8_2_v20130308-0413.jar.pack.gz
--org.junit.source_4.11.0.v201303080030.jar
--org.junit.source_4.11.0.v201303080030.jar.pack.gz
--org.mockito_1.8.4.v201303031500.jar
--org.mockito_1.8.4.v201303031500.jar.pack.gz
--org.mockito.source_1.8.4.v201303031500.jar
--org.mockito.source_1.8.4.v201303031500.jar.pack.gz
--org.objenesis_1.0.0.v201105211943.jar
--org.objenesis_1.0.0.v201105211943.jar.pack.gz
--org.objenesis.source_1.0.0.v201105211943.jar
--org.objenesis.source_1.0.0.v201105211943.jar.pack.gz
--org.slf4j.api_1.7.2.v20121108-1250.jar
--org.slf4j.api_1.7.2.v20121108-1250.jar.pack.gz
--org.slf4j.api.source_1.7.2.v20121108-1250.jar
--org.slf4j.api.source_1.7.2.v20121108-1250.jar.pack.gz
--org.slf4j.log4j_1.7.2.v20130115-1340.jar
--org.slf4j.log4j_1.7.2.v20130115-1340.jar.pack.gz
--org.slf4j.log4j.source_1.7.2.v20130115-1340.jar
--org.slf4j.log4j.source_1.7.2.v20130115-1340.jar.pack.gz
--org.w3c.css.sac_1.3.0.v200805290154.jar
--org.w3c.css.sac_1.3.0.v200805290154.jar.pack.gz
--org.w3c.css.sac_1.3.1.v200903091627.jar
--org.w3c.css.sac_1.3.1.v200903091627.jar.pack.gz
--org.w3c.dom.events_3.0.0.draft20060413_v201105210656.jar
--org.w3c.dom.events_3.0.0.draft20060413_v201105210656.jar.pack.gz
--org.w3c.dom.smil_1.0.0.v200806040011.jar
--org.w3c.dom.smil_1.0.0.v200806040011.jar.pack.gz
--org.w3c.dom.smil_1.0.1.v200903091627.jar
--org.w3c.dom.smil_1.0.1.v200903091627.jar.pack.gz
--org.w3c.dom.svg_1.1.0.v201011041433.jar.pack.gz
--org.w3c.dom.svg_1.1.0.v201011041433.jar
-artifacts.jar
-contents.jar
However when I load it into a target file specification in Eclipse, it says that there is nothing to choose from:
If I remove the <ius> tag (and hence disable the filtering), Eclipse still shows it as empty. So full mirroring also does not work.
What do I do wrong?
Your repository contains only plug-ins that's why you have nothing in Install dialog. The resulting repository itself is correct and can be used in builds to resolve dependencies.
To have all plugins visible in Install dialog you cold consider mirroring org.eclipse.orbit.category.all category IU.
Another option to consider is building p2 repository using packaging (this is just a guess and I haven't tested it):
<packaging>eclipse-repository</packaging>
and category.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<site>
<bundle id="com.google.guava" version="0.0.0">
<category name="all"/>
</bundle>
<bundle id="com.google.guava.source" version="0.0.0">
<category name="all"/>
</bundle>
<category-def name="all" label="My Orbit bundles"/>
</site>

How to run annotation processor in eclipse on save

Currently I generate files with an annotation processor in eclipse for a project by
Right click on project > Run As > Maven Clean
Right click on project > Run As > Maven install
This is quite time consuming. How do I set up eclipse to make it run the annotation processor on save?
I have the "Build Automatically" feature set but it seems to ignore the annotation processors. BTW I am using m2e apt plugin with "Automatically configure JDT APT activated".
I have annotation processing working in Eclipse for some of my projects; for me, it IS working on save, and I don't have to mvn install (and it works differently than Maven, as Eclipse runs its own compiler).
I'm also using m2e-apt plugin for this.
As noted above, Eclipse runs its own compiler; that means that its output can differ slightly than Maven's (when you "Right click on project > Run As > Maven Clean / Install" you're invoking Maven, not Eclipse). I'm mentioning this because it is entirely possible that your processors have a problem and work in Maven but not in Eclipse (although most of the time they do produce the same output; I've seen some differences, but very small). I'd keep an eye on Eclipse's error log if I were you (because that's where annotation processing errors are written).
So here is what I suggest:
Post A picture with your Maven / Annotation Processing settings in Eclipse (even though you do seem to have the correct option activated).
Post a picture with Java/Compiler settings (there is a checkmark in there that needs to be activated; it doesn't work without).
Posting your pom.xml would, strangely, be helpful. Especially if you have custom configuration for maven-compiler-plugin. Some of that config is interpreted by m2e-apt, such as compiler arguments.
Look for a file called .factorypath. That's where m2e-apt keeps the list of jars that it scans for annotation processing (you'll find all the jars of your project in there, even though they don't actually contain processors; that is, unless your maven-compiler-plugin is configured as such to only consider a specific list of processors). If the jar containing your processor is not in .factorypath, it won't work.
Last but not least, there is another thing that can cause problems. If the project containing the actual annotation processor (so NOT the "client") is in the same workspace as the "client" project, then m2e-apt will simply ignore your annotation processor; I don't know why. Closing your annotation processor project would be enough in this case (you don't have to delete it from workspace).
Edit: Forgot to say that if you do run your annotation processing via Maven (and you're invoking Maven just to process annotations), then mvn compile should be enough. Also, you don't need to run it separately (first mvn clean then mvn compile). You can run it in one shot with mvn clean compile; it is supposed to have the exact same effect.
Make sure your Java project settings (accessible with right-click on project > Java compiler > Annotation processors) do enable annotation processing and that the settings match your expections.
For Maven project, m2e is supposed to configure those settings properly according to the pom.xml content. However, this is not working smoothly for all Maven plugins (some will be supported "out-of-the-box", some others will require a specific plugin...).
I think you need a trigger to run Maven goal, So:
You have to add a valid maven lifecycle action
Example for a jar which is automatically deployed locally by maven install plugin:
<build>
<!-- ... -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>jar</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<versionRange>[2.5.0,)</versionRange>
<goals>
<goal>install</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Hint: relates to Maven Project Builder is invoked every time I change a source file (GWT) and as a warning: install typically includes tests if you have included them in your normal maven build cycle

How can I run a Maven webapp in Eclipse when I need resource filtering for properties files?

I need to get some updates on this issue, I found this thread back in 2009 here, but the answer was to use maven 2, I'm not sure if Q4E works with maven 3 or not. I need to have some properties files filtered during the mvn package phase for the resulting war to be functional, the resource filtering is working fine with CLI mvn install. But when I do "Run on server/debug on server", the filtering is not working any more.
The aforementioned thread author ended up using q4e, claiming q4e gets the resource filtering right. I have q4e installed as well along with m2e, but still doesn't work, so I don't know if q4e is not working with maven 3, or I'm doing something wrong.
Thanks,
David
updated to the latest m2e-wtp plugin 0.15 (resource filtering bug fix since 0.12), it works fine now.
I'm not sure if this matches your problem, but I wanted to populate my web.xml file with properties from the pom during build and I put a groovy script in the pom to do it. It worked a treat and might work for you too. It definately works in both eclipse and on the command line. Here is my pom fragment:
<plugin>
<!-- Groovy script to set the description and version in the web.xml display name -->
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>groovy-magic</id>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def file = new File("src/main/webapp/WEB-INF/web.xml");
def fileText = file.text;
def match = "<display-name>[^<]*</display-name>";
def replace = "<display-name>"+project.description+" "+project.version+"</display-name>";
fileText = fileText.replaceAll(match, replace);
file.write(fileText);
println "Updated web.xml"
</source>
</configuration>
</execution>
</executions>
</plugin>

Beginner Steps to Configure a Java Project to Build with Apache Maven

I've been given the task of migrating an existing project -- formerly built with Ant -- to use Apache Maven. I'm brand new to the entire concept, though I've spent the last several hours doing as much research as I can on the subject. Sadly, I'm having some proxy issues when it comes to installing things like m2e and Eclipse IAM, so everything must be done from the command prompt. As of right now, I do have maven installed properly; the trick now is to use it in my project rather than Ant. I've looked online and found a few tutorials, but they are all too vague for me considering my lack of experience with all of this. If anyone can break the steps down for me one-by-one in a detailed manner, that would be more than amazing. On a side note, I've been told to add the following to the local Maven Settings:
<settings>
<servers>
<server>
<id>local_tomcat</id>
<username>admin</username>
<password>tomcat</password>
</server>
<server>
<id>artifactory</id>
<username>user</username>
<password>password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>artifactory</id>
<name>Artifactory</name>
<url>https://jenkins.web.jw.local/artifactory/repo1</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.jw.local</host>
<port>80</port>
<username>user</username>
<password>password</password>
<nonProxyHosts>*.jw.local</nonProxyHosts>
</proxy>
</proxies>
</settings>
With the obvious username and password information filled in. I think I've managed that thus far by simply adding the necessary blocks into the settings.xml file under my ApacheMaven\conf directory. Other than that single step, I'm pretty much lost. Again, any help, especially that of a detailed tutorial in terms of command line instructions to build this project would be wonderful. Oh, and on another side-note, I am using Eclipse... Not sure if that would matter much.
EDIT: Considering Petr Kozelka's answer, I've attempted to make a pom.xml file for my project. Here's what I have so far...
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>appName</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>Application Name</name>
<description>Yadda Yadda</description>
<build>
<plugins>
</plugins>
</build>
<dependencies>
</dependencies>
<repositories>
</repositories>
</project>
Is this heading in the right direction? Also, do I need to construct the archetype.xml file myself, or will Maven do that through the command line somehow? If I need to do it myself, this is what I've come up with thus far:
<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">
<id>lighthouse</id>
<sources>
<source>src/com/jeldwen/lighthouse/controller/AddTimeController.java</source>
<source>src/com/jeldwen/lighthouse/controller/BugController.java</source>
<source>src/com/jeldwen/lighthouse/controller/DeleteTimeController.java</source>
<source>src/com/jeldwen/lighthouse/controller/EnterTimeController.java</source>
<source>src/com/jeldwen/lighthouse/controller/ModifyTimeController.java</source>
<source>src/com/jeldwen/lighthouse/controller/PersonController.java</source>
<source>src/com/jeldwen/lighthouse/controller/ProjectController.java</source>
<source>src/com/jeldwen/lighthouse/controller/TimeController.java</source>
<source>src/com/jeldwen/lighthouse/model/Area.java</source>
<source>src/com/jeldwen/lighthouse/model/Bug.java</source>
<source>src/com/jeldwen/lighthouse/model/DBModel.java</source>
<source>src/com/jeldwen/lighthouse/model/DefaultModel.java</source>
<source>src/com/jeldwen/lighthouse/model/JWModel.java</source>
<source>src/com/jeldwen/lighthouse/model/JWTime.java</source>
<source>src/com/jeldwen/lighthouse/model/Person.java</source>
<source>src/com/jeldwen/lighthouse/model/Project.java</source>
<source>src/com/jeldwen/lighthouse/util/Lighthouse.java</source>
<source>src/com/jeldwen/lighthouse/util/LighthouseApplicationListener.java</source>
<source>src/com/jeldwen/lighthouse/util/LighthouseServlet.java</source>
<source>src/com/jeldwen/lighthouse/util/LighthouseSystemProperties.java</source>
<source>src/com/jeldwen/lighthouse/LighthouseApp.java</source>
</sources>
<testSources>
<!-- None -->
</testSources>
<allowPartial>true</allowPartial>
</archetype>
First of all: if you wish to customize settings.xml, do not touch the one in maven distro - instead, create a new file in $HOME/.m2/settings.xml where maven finds and uses it.
As the very first step, I recommend you to not use settings.xml at all.
Create a supersimple maven project, and try to compile it:
mvn clean install
Second step
Use very simple settings.xml:
you probably do not need proxy
servers part is needed only for publishing artifacts to a maven repository; that's not important at the beginning
here it is:
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<mirrors>
<mirror>
<id>repos</id>
<mirrorOf>*</mirrorOf>
<name>internal mirror</name>
<url>https://jenkins.web.jw.local/artifactory/repo1</url>
</mirror>
</mirrors>
<!-- TODO: the proxy part here -->
</settings>
This assumes that you use inhouse maven repository, for instance Nexus or Artifactory.
Using maven repo makes only sense if your projects are not happy with deps available in the Maven Central Repository - otherwise, you can safely go without it. (let's neglect the performance effect of repoman for now)
Now, add some java sources, dependencies etc. - and watch how new depenencies get automatically downloaded to your local repository...
Third step
Learn how to add further repositories to your repository manager (group "public" on Nexus)...
The rest is probably subject of further research.

deploying a maven project

I have a maven project and I'd like to create a distribution of it with the dependencies. I've tried the maven-assembly-plugin and built the jar with dependencies, but that unpacked all of the jars and repackaged them all into a big, single jar. What I'd like is something like my jar file and a lib folder that has all of the dependencies. Then when I run it, I could run "java -cp lib/* my.package.MainClass".
What's the best way to go about doing this with maven? Or the recommended way to deploy?
thanks,
Jeff
I have used the Maven assembly just for that in my project.
First enable your plugin in your POM and call your assembly config :
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<!--I recommend 2.1 as later versions have a bug that may
Duplicate files in your archive
-->
<version>2.1</version>
<!--Executes the packaging along with the mvn package phase
-->
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<!--Relative path to your descriptor -->
<descriptor>src/main/assembly/package.xml
</descriptor>
</descriptors>
</configuration>
</plugin>
Then in your descriptor you can decide how you want your layout to be before you package the whole thing
<assembly>
<!-- this will create an extra resource project-1.1.1-package.zip, you can
choose jar as well in the format-->
<id>package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<!-- Insert here extra files as configs or, batch files, resources, docs etc-->
<fileSets>
<fileSet>
<directory>src/main/assembly/files</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/conf/*.*</include>
<include>**/doc/*.*</include>
</includes>
</fileSet>
<!-- I like to integrate the jre as well... simplifies my deployement -->
<fileSet>
<directory>target/jre</directory>
<outputDirectory>/jre</outputDirectory>
</fileSet>
</fileSets>
<!-- This will scrub your dependencies and add them to your lib folder, I excluded
Test stuff as it is not needed, could have declared the resource as a test
only phase as well would not have had to exclude it here
-->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
This will create a zip file with the layout you have specified in your output directory config, package the whole thing as a zip file (you can choose zip, jar, war ...) and deploy it in my repository with the rest.
I skipped bits and pieces to make it simpler but my package expands to include batch files, dlls, config, doc and the JRE so everything needed is in the same zip... all is needed to run the thing is extract and click start.bat !
I could also probably make it in to a jar properly formatted with METADATA and just double click the jar itself to start it all, I did not need or have time to toy around this option but you may try it as well.
Beware of versions above 2.1 of the assembly plugin, it will create duplicate entries if your directives enable it to find the same file in different locations, this will give you a lib folder with the same jars repeating twice. not very dangerous as unzipping will collapse them but still annoying to have the unzip ask you if you want to overwrite files. Plus the fact that you do not know which won if somehow they turned out to be different in content.
Maven is great but I find that it is sometimes frustrating to get it working, Plus documentation can sometimes be hard to find and use. However, used appropriately it will save you tons of time.
good luck
See:
http://maven.apache.org/shared/maven-archiver/index.html
You should be able to use the maven-jar plugin to package up an archive, specify the main class to execute along with the classpath. It can generate a manifest file for you for your project.
http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Prefix