Results 1 to 2 of 2
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Building an executable jar, then using it to generate source

    Project A produces an executable jar artifact that generates Java source from XML files specified on the command line. So far so good.

    Now I want project B to run A's artifact (building it if necessary) in B's process-resources phase to generate some of B's source. How do I do that?

    My Google-fu is weak tonight...
    Get in the habit of using standard Java naming conventions!

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Building an executable jar, then using it to generate source

    It may not be ideal, but this is how I did it: exec-maven-plugin runs my custom build tool in the generate-sources phase and registers its source output directory as a Maven source directory. Then build-helper-maven-plugin registers the tool's resource output directory as a Maven resource directory. All the generated stuff is under target so it gets cleaned automatically.

    Java Code:
    <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/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>com.github.kjkrum</groupId>
    	<artifactId>JTX</artifactId>
    	<version>1.0</version>
    	<name>Java Terminal eXtreme</name>
    	<description>A fast and flexible Swing terminal system</description>
    	<properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    	</properties>
    	<dependencies>
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.6</version>
    			<scope>test</scope>
    		</dependency>
    		<dependency>
    			<groupId>com.github.kjkrum</groupId>
    			<artifactId>Automaton</artifactId>
    			<version>1.12</version>
    		</dependency>
    	</dependencies>
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.codehaus.mojo</groupId>
    				<artifactId>exec-maven-plugin</artifactId>
    				<executions>
    					<execution>
    						<id>jplex-build</id>
    						<phase>generate-sources</phase>
    						<goals>
    							<goal>java</goal>
    						</goals>
    					</execution>
    				</executions>
    				<configuration>
    					<mainClass>krum.jplex.JPlex</mainClass>
    					<arguments>
    						<argument>${basedir}/src/main/jplex/DemoLexer.jplex</argument>
    						<argument>${project.build.directory}/generated-sources/jplex/</argument>
    						<argument>${project.build.directory}/generated-resources/jplex/</argument>
    					</arguments>
    					<sourceRoot>${project.build.directory}/generated-sources/jplex/</sourceRoot>
    					<includePluginDependencies>true</includePluginDependencies>
    				</configuration>
    				<dependencies>
    					<dependency>
    						<groupId>com.github.kjkrum</groupId>
    						<artifactId>JPlex</artifactId>
    						<version>1.1</version>
    					</dependency>
    				</dependencies>
    			</plugin>
    			<plugin>
    				<groupId>org.codehaus.mojo</groupId>
    				<artifactId>build-helper-maven-plugin</artifactId>
    				<executions>
    					<execution>
    						<id>add-resource</id>
    						<phase>generate-resources</phase>
    						<goals>
    							<goal>add-resource</goal>
    						</goals>
    						<configuration>
    							<resources>
    								<resource>
    									<directory>${project.build.directory}/generated-resources/jplex/</directory>
    								</resource>
    							</resources>
    						</configuration>
    					</execution>
    				</executions>
    			</plugin>
    			<plugin>
    				<artifactId>maven-compiler-plugin</artifactId>
    				<configuration>
    					<source>1.5</source>
    					<target>1.5</target>
    				</configuration>
    			</plugin>
    		</plugins>
    	</build>
    </project>
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Generate UML2 from source
    By Flipper in forum Eclipse
    Replies: 2
    Last Post: 08-01-2012, 03:52 PM
  2. create windows executable using executable jar file
    By sarwar1234 in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 09:29 PM
  3. Replies: 0
    Last Post: 01-29-2009, 11:43 AM
  4. Replies: 1
    Last Post: 11-28-2008, 07:27 PM
  5. Generate an executable file
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •