5

My jar is not running, I can tell it tries to run as the log4j file manage to create the log folder but then nothing happens and the log is in blank.

My problem is I have the jar file in a folder called bin and the libraries in a folder called lib

I'm triying this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
    <outputDirectory>${staging.dir}/bin</outputDirectory>
      <archive>
        <manifest>
          <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
          <addClasspath>true</addClasspath>
          <mainClass>com.Main</mainClass>
          <classpathPrefix>../lib/</classpathPrefix>
        </manifest>
      </archive>
    </configuration>
  </plugin>

and

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${staging.dir}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

I also tried with maven-assembly-plugin, but it packs everything on the jar and I really need to have the folders bin and lib

What do I need to setup to make it work correctly?

EDIT: META-INF file

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: me
Build-Jdk: 1.6.0_26
Main-Class: com.Main
Class-Path: ../lib/ojdbc6-11.2.0.jar ../lib/sqljdbc4-4.2.0.jar ../lib/
mysql-connector-java-5.1.17.jar ../lib/hibernate-core-3.6.5.Final.jar
../lib/antlr-2.7.6.jar ../lib/commons-collections-3.1.jar ../lib/dom
4j-1.6.1.jar ../lib/hibernate-commons-annotations-3.2.0.Final.jar ../
lib/hibernate-jpa-2.0-api-1.0.0.Final.jar ../lib/jta-1.1.jar ../lib/s
lf4j-api-1.6.1.jar ../lib/hibernate-entitymanager-3.6.5.Final.jar ../
lib/cglib-2.2.jar ../lib/asm-3.1.jar ../lib/javassist-3.12.0.GA.jar .
./lib/slf4j-log4j12-1.6.1.jar ../lib/log4j-1.2.16.jar ../lib/commons-
codec-1.5.jar ../lib/lablib-checkboxtree-3.3-20110114.141734-3.jar

SOLUTION

turns out the META-INF file is incorrect. The reason is that maven-archiver-plugin renames SNAPSHOT libraries with a timestamp as default behaviour

to override that use this, as instructed by the Maven Archiver doc:

<plugins>
  <plugin>
     <artifactId>maven-war-plugin</artifactId>
     <configuration>
       <archive>
         <manifest>
           <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
          <addClasspath>true</addClasspath>
          <useUniqueVersions>false</useUniqueVersions>
          <mainClass>com.Main</mainClass>
          <classpathPrefix>../lib/</classpathPrefix>
         </manifest>
       </archive>
     </configuration>
  </plugin>
</plugins>

other than that, I hope people find useful the maven code at the start because it does work, just beware the SNAPSHOTS in your projects

javaNoober
  • 1,338
  • 2
  • 17
  • 43
  • How does your MANIFEST file look? Also have you actually placed the dependant jars in lib folder? – Raghuram Jul 30 '11 at 01:57
  • everything is there and the MANIFEST looks good, just attaching to edit right now – javaNoober Jul 30 '11 at 02:12
  • youa re right is a META-INF issue, my last lib is lablib-checkboxtree-3.3-SNAPSHOT.jar, tried running the jar on console and it can't find the library. I tried removing and redownloading the lib but it keeps placing thtat numebr instead of the word SNAPSHOT, why? – javaNoober Jul 30 '11 at 02:31
  • Yes, "useUniqueVersions" was the fix to the 'time stamping' problem as you named it, I had similar issue. – tomasz_kusmierczyk Sep 06 '13 at 17:19

1 Answers1

3

The above all seems OK. Here are some things/questions you may want to try/confirm/answer:

  • Are you running this from command line? I.e. using java -jar <your.jar> or are you starting it e.g. by double-clicking the file, etc.? If not, try running it from the command line to see what happens
  • Try using mvn exec:java to see if that starts your app (maven-)regularly. See http://mojo.codehaus.org/exec-maven-plugin/usage.html if you are not familiar with exec plugin
  • Can you use regular Java System.out.println instead of logging to confirm that it actually starts? Having a zero-size log might be a logging configuration issue
  • I see you have some DB libraries above. Can you put some println (or better logging, but only after you confirm your logging actually works) statements around basic initialization, to confirm that you are not just stalling there (provided that's what's happening - you don't mention any exceptions or other issues in specific)

A lot depends on the actual application code, but hope some of the above might help you pinpoint the issue.

As a side note, is your main class really com.Main? If yes, may I suggest to change that to something more appropriate - e.g. com.yourdomain.yourapp.Main or something along these lines. Not that this will change the above result, just a stylistic comment.

icyrock.com
  • 27,952
  • 4
  • 66
  • 85
  • I was double-clicking it, hence I wasn't seeing any errors, now that I used console I see it can't load the last library, the name should be lablib-checkboxtree-3.3-SNAPSHOT, however maven is changing it to that lablib-checkboxtree-3.3-20110114.141734-3, I changed the lib name manually and confirms it works, how to correct this? – javaNoober Jul 30 '11 at 02:46
  • and don't worry the name is not com.Main ;) – javaNoober Jul 30 '11 at 02:46
  • Can you try deleting the artifact from your `.m2` folder (see this if you are not familiar: http://stackoverflow.com/questions/6081617/missing-maven-m2-folder) and then try `mvn package` again? You should find it in .m2/repository//lablib-checkboxtree/3.3-SNAPSHOT - just move that folder somewhere else (as a backup solution) and then reinstall it however you did before (did you use `mvn install:install-file` or do you have something like Nexus on site?). You should confirm you have lablib-checkboxtree-3.3-SNAPSHOT.jar there – icyrock.com Jul 30 '11 at 02:51
  • > and don't worry the name is not com.Main ;) Cool :) – icyrock.com Jul 30 '11 at 02:53
  • Or better yet deploy it as a non-snapshot version - much better if you can do it (e.g. http://stackoverflow.com/questions/758921/how-to-get-rid-of-maven-snapshot-versions) – icyrock.com Jul 30 '11 at 02:55
  • wish I could, but thats the only available version of that component, hate when there is a good SWING component that goes discontinued – javaNoober Jul 30 '11 at 02:59
  • maven-archiver was overwritting the SNAPSHOT with a timestamp, found the documentation to override that :D – javaNoober Jul 30 '11 at 03:04
  • Well, SNAPSHOT is not a "version", it's actually a collection of versions - that's why you have the date, as that's the latest version in the SNAPSHOT set. These are used while developing, so you update code frequently, but should not be used in the final product. You can always use `mvn install:install-file` (check http://maven.apache.org/plugins/maven-install-plugin/usage.html) to upload it a whichever version you want (e.g. `3.3-javaNoober`, to if you want to signify it's for your use only), though do this carefully and only if you have to, with specific reasons. – icyrock.com Jul 30 '11 at 03:05
  • As a (bad) alternative, you can use `stripVersion` option to dependency plugin, see http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html. – icyrock.com Jul 30 '11 at 03:05