Hi Mark, Thanks for that. I changed the pom as you suggested. When I ran with java -jar myApp.jar I got the output: *Failed to load Main-Class manifest attribute from target/myApp.jar*
I opened the manifest and the *Main-Class* attribute was entered as *mainClass.* So I changed it to the former and that got rid of that error. But now I *still *get the original error. The only pom change I'm not sure about is *<classpathPrefix>lib/</classpathPrefix>*. What classes is that classpath trying to capture? Thanks, Ten On Wed, Feb 5, 2014 at 7:01 PM, Mark Eggers [via Maven] < [email protected]> wrote: > On 2/5/2014 9:52 AM, TenLeftFingers wrote: > > > When I build my Maven project with dependencies (using Netbeans but > pointing > > to a vanilla Maven installation), I get BUILD SUCCESS. Great! > > > > When I try to /run /it in the form of *java -cp > > target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App* I get this: > > *java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory* > > > > How come this dependency fails at this late stage? > > > > Trying to run the class from NetBeans itself gives a different error: > > *Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec* > > > > Please enlighten me as to how I can run this thing. It works fine in > Eclipse > > when I run it as a Java Application - but Eclipse has other problems > that > > I'm avoiding so I need to do this either from CLI or NetBeans > (preferable). > > > > Thanks, > > Ten > > I normally use NetBeans . . . . > > One way to handle this (and it'll end up looking like a standard > NetBeans project) is the following. > > 1. Modify the manifest via the maven-jar-plugin > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-jar-plugin</artifactId> > <version>2.4</version> > <configuration> > <archive> > <manifest > <addDefaultImplementationEntries>true</addDefaultImplementationEntries> > <mainClass>main-class-name</mainClass> > <addClasspath>true</addClasspath> > <classpathPrefix>lib/</classpathPrefix> > </manifest> > </archive> > </configuration> > </plugin> > > 2. Use the maven-dependency-plugin to copy over the libraries > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-dependency-plugin</artifactId> > <version>2.8</version> > <executions> > <execution> > <phase>package</phase> > <goals> > <goal>copy-dependencies</goal> > </goals> > <configuration> > <outputDirectory>${project.build.directory}/lib</outputDirectory> > <includeScope>compile</includeScope> > </configuration> > </execution> > </executions> > </plugin> > > 3. Run from the command line to test > > mvn package > cd target > java -jar jarFileName.jar > > To ship the binaries, use the maven-assembly-plugin and package both the > JAR and the supporting libraries. That way when someone unpacks the zip > (or tar or tar.gz, etc.), the directory structure will be maintained. > > Here's an assembly.xml file. I've left out the xml namespace declarations: > > <?xml version="1.0" encoding="UTF-8"?> > <assembly> > <id>bin</id> > <formats> > <format>tar.gz</format> > <format>zip</format> > </formats> > <includeBaseDirectory>false</includeBaseDirectory> > <includeSiteDirectory>false</includeSiteDirectory> > <fileSets> > <fileSet> > <directory>target</directory> > <outputDirectory></outputDirectory> > <includes> > <include>*.jar</include> > <include>lib/</include> > </includes> > </fileSet> > </fileSets> > </assembly> > > Other ways include creating an uber-jar. > > . . . . just my two cents. > /mde/ > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden > email]<http://user/SendEmail.jtp?type=node&node=5783298&i=0> > For additional commands, e-mail: [hidden > email]<http://user/SendEmail.jtp?type=node&node=5783298&i=1> > > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://maven.40175.n5.nabble.com/Build-is-successful-but-can-t-run-tp5783294p5783298.html > To unsubscribe from Build is successful but can't run?, click > here<http://maven.40175.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5783294&code=amFybGF0aHJlaWR5QGdtYWlsLmNvbXw1NzgzMjk0fDEyMDg3OTQ0MDQ=> > . > NAML<http://maven.40175.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- View this message in context: http://maven.40175.n5.nabble.com/Build-is-successful-but-can-t-run-tp5783294p5783304.html Sent from the Maven - Users mailing list archive at Nabble.com.
