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

    Default Maven forum dead...

    There are an awful lot of questions with zero answers in the Maven subforum here. Do people not read the highly specific subforums, or does this crowd just hate Maven?

    I'm a Maven noob. I've been studying the different plugins, but I'm not sure if any of them will do exactly what I want. The assembler plugin looks like it might come the closest. Maybe there are creative ways of combining different plugins to achieve what I want.

    Basically, I want Maven to generate an executable jar the way Eclipse's export does, with the dependencies in a directory next to it. Then I'd like to drop a couple more files next to the jar (a Logback configuration and some scripts) and zip the whole directory for distribution.

    Any pointers?
    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: Maven forum dead...

    I'm experimenting with a "Hello, World!" type project that prints its message through slf4j, just so I have an excuse to bring in a dependency. Here's what I've got so far.

    My pom.xml:

    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.chalcodes.fnord</groupId>
    	<artifactId>HelloMaven</artifactId>
    	<version>1.0</version>
    	<packaging>jar</packaging>
    
    	<properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    	</properties>
    
    	<dependencies>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-api</artifactId>
    			<version>1.7.2</version>
    		</dependency>
    	</dependencies>
    
    	<build>
    		<sourceDirectory>src</sourceDirectory>
    		<plugins>
    			<plugin>
    				<artifactId>maven-compiler-plugin</artifactId>
    				<version>3.0</version>
    			</plugin>
    
    			<!-- make an executable jar *without* deps -->			
    			<plugin>
    				<artifactId>maven-jar-plugin</artifactId>
    				<version>2.4</version>
    				<configuration>
    					<archive>
    						<manifest>
    							<addClasspath>true</addClasspath>
    							<mainClass>fnord.Hello</mainClass>
    						</manifest>
    					</archive>
    				</configuration>
    			</plugin>
    
    			<!-- assemble a zip file with the deps included -->
    			<plugin>
    				<artifactId>maven-assembly-plugin</artifactId>
    				<version>2.4</version>
    				<configuration>
    					<descriptors>
    						<descriptor>assembly.xml</descriptor>
    					</descriptors>
    				</configuration>
    			</plugin>
    
    		</plugins>
    	</build>
    </project>
    And the assembly descriptor it refers to:

    Java Code:
    <assembly>
    	<id>complete</id>
    	<formats>
    		<format>zip</format>
    	</formats>
    
    	<files>
    		<file>
    			<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
    			<destName>${project.artifactId}.${project.packaging}</destName>
    			<fileMode>0644</fileMode>
    		</file>
    	</files>
    
    	<dependencySets>
    		<dependencySet>
    		    <useProjectArtifact>false</useProjectArtifact>
    			<outputDirectory>lib</outputDirectory>
    		</dependencySet>
    	</dependencySets>
    </assembly>
    So far so good. The zip is being assembled the way I wanted. But the classpath in the jar's manifest is wrong:

    Java Code:
    Manifest-Version: 1.0
    Built-By: kevin
    Build-Jdk: 1.6.0_27
    Class-Path: slf4j-api-1.7.2.jar
    Created-By: Apache Maven 3.0.4
    Main-Class: fnord.Hello
    Archiver-Version: Plexus Archiver
    The classpath should be "lib/slf4j-api-1.7.2.jar". Any way to control that?
    Get in the habit of using standard Java naming conventions!

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

    Default Re: Maven forum dead...

    Bingo! I added this to the manifest section of the POM:

    Java Code:
    <classpathPrefix>lib/</classpathPrefix>
    THAKNS GUSY LOL
    Get in the habit of using standard Java naming conventions!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Maven forum dead...

    Looks like you now get the wear the mantle of Maven expert here...:)
    I only use the thing.
    I don't think I've actually done anything other than add a dependency.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: Maven forum dead...

    The introduction of the O'Reilly Maven book clams that Maven eliminates the job of the build engineer. Ha!
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Replies: 0
    Last Post: 12-17-2012, 01:32 PM
  2. Dead Code
    By Eranga in forum Eclipse
    Replies: 3
    Last Post: 01-17-2012, 05:01 AM
  3. Dead threads
    By Onra in forum New To Java
    Replies: 2
    Last Post: 12-19-2010, 01:26 PM
  4. Restarting dead threads
    By DC200 in forum Threads and Synchronization
    Replies: 3
    Last Post: 12-03-2010, 10:09 PM
  5. Replies: 0
    Last Post: 04-20-2009, 06:26 PM

Posting Permissions

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