You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by TenLeftFingers <ja...@gmail.com> on 2014/02/05 18:52:58 UTC

Build is successful but can't run?

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



--
View this message in context: http://maven.40175.n5.nabble.com/Build-is-successful-but-can-t-run-tp5783294.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Build is successful but can't run?

Posted by Mark Eggers <it...@yahoo.com>.
On 2/5/2014 11:40 AM, TenLeftFingers wrote:
> 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*
>

A couple of things:

1. the main-class-name was supposed to be your main class

> 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?
>

You need to change to the project target directory in order for it to 
run and find the supporting jars.

The classpathPrefix line sets where to look for additional JAR files. It 
is relative to where you are.

Maven compiles and packages your program into a JAR. It copies all of 
the supporting JAR files listed in your dependencies into target/lib.

Before you run, make sure that target/lib exists and has all of the JAR 
files you need.

Now, change to the target directory on the command line, and execute the 
program. The keys here are the following:

1. change to the target directory on the command line
2. execute the program with the following:

java -jar my-app-1.0-SNAPSHOT.jar

Now the lib directory will be in the correct relative path, and your 
dependencies should be found.

> Thanks,
> Ten
>

The exec plugin (http://mojo.codehaus.org/exec-maven-plugin/) as Wayne 
has mentioned is another way to accomplish this. This will help you run 
from within an IDE or by using mvn exec:exec, but it won't help you 
package and ship your code out for other users.

You can combine both. I've not used the exec-maven-plugin, so creating 
the plugin configuration for that is left as an exercise for the reader. 
However, the documentation on the link listed above should get you started.

/mde/

>
> On Wed, Feb 5, 2014 at 7:01 PM, Mark Eggers [via Maven] <
> ml-node+s40175n5783298h15@n5.nabble.com> 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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Build is successful but can't run?

Posted by TenLeftFingers <ja...@gmail.com>.
Thanks Wayne. As I say, something isn't connecting when I try without the
maven-assembly-plugin. I may figure it out in the future. Thank you Mark
also.


On Thu, Feb 6, 2014 at 2:43 PM, Wayne Fay [via Maven] <
ml-node+s40175n5783375h2@n5.nabble.com> wrote:

>  > I added the maven-assembly-plugin as described here:
> >
> http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven
> > and now the dependencies are bundled within the jar. Thanks for your
> help
>
> This is a fine approach. I still maintain the exec plugin is a great
> option for these types of uses - so long as you (the developer) are
> the one who needs to run the app. If you want to deliver it to a
> third-party in a single executable jar format, then assembly and other
> plugins are generally superior.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783375&i=0>
> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783375&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-tp5783294p5783375.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-tp5783294p5783377.html
Sent from the Maven - Users mailing list archive at Nabble.com.

Re: Build is successful but can't run?

Posted by Ron Wheeler <rw...@artifact-software.com>.
On 06/02/2014 9:42 AM, Wayne Fay wrote:
>> I added the maven-assembly-plugin as described here:
>> http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven
>> and now the dependencies are bundled within the jar. Thanks for your help
> This is a fine approach. I still maintain the exec plugin is a great
> option for these types of uses - so long as you (the developer) are
> the one who needs to run the app. If you want to deliver it to a
> third-party in a single executable jar format, then assembly and other
> plugins are generally superior.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
It is also a good idea to use an installer to package an app for delivery.
IzPack is a free installer that has a Maven plug-in to help  ease the 
setup.

It allows you to build the code in an OS neutral fashion and make the 
installer deal with your OS-dependent bits such as configuration files 
and registry entries.

Ron

-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Build is successful but can't run?

Posted by Wayne Fay <wa...@gmail.com>.
> I added the maven-assembly-plugin as described here:
> http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven
> and now the dependencies are bundled within the jar. Thanks for your help

This is a fine approach. I still maintain the exec plugin is a great
option for these types of uses - so long as you (the developer) are
the one who needs to run the app. If you want to deliver it to a
third-party in a single executable jar format, then assembly and other
plugins are generally superior.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Build is successful but can't run?

Posted by TenLeftFingers <ja...@gmail.com>.
I added the maven-assembly-plugin as described here:
http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-mavenand
now the dependencies are bundled within the jar. Thanks for your help
-
much to learn, but I'm learning quite a bit about Maven.


On Thu, Feb 6, 2014 at 11:28 AM, Jarlath Reidy <ja...@gmail.com>wrote:

> Cancel that. It does exist. And more importantly it exists in the
> target/lib folder.
>
>
> On Thu, Feb 6, 2014 at 11:11 AM, Jarlath Reidy <ja...@gmail.com>wrote:
>
>> I have just noticed that the dependency it complains about does not exist
>> in my .m2 folder. I don't know how Eclipse is executing this project but I
>> would have expected mvn package to pull in that dependency to the local
>> repository.
>>
>>
>> On Thu, Feb 6, 2014 at 10:02 AM, Jarlath Reidy <ja...@gmail.com>wrote:
>>
>>> "You should specify the fully qualified main class eg:
>>> com.mycompany.app.App
>>> in the mainClass field/parameter to the plugin."
>>> "1. the main-class-name was supposed to be your main class"
>>> Let me clarify. The entry appears in the manifest as:
>>> mainClass: fully.qualified.path.to.MyApp
>>> instead of
>>> Main-Class: fully.qualified.path.to.MyApp
>>>
>>> I've changed it in the pom (I thought that the tag was a fixed keyword
>>> so I didn't change it there initially).
>>>
>>>
>>> "The classpathPrefix line sets where to look for additional JAR files. It
>>> is relative to where you are."
>>> So relative to where I execute my java -jar ... command from. Okay, I
>>> have that. I'm executing from the directory above (..) the target.
>>>
>>>
>>> "Maven compiles and packages your program into a JAR. It copies all of
>>> the supporting JAR files listed in your dependencies into target/lib.
>>> Before you run, make sure that target/lib exists and has all of the JAR
>>> files you need."
>>> Yep, they're all there. Including the jar which contains the class it
>>> says it can't load and I can see that that class is present in the jar.
>>>
>>>
>>> "The exec plugin (http://mojo.codehaus.org/exec-maven-plugin/) as Wayne
>>> has mentioned is another way to accomplish this. This will help you run
>>> from within an IDE or by using mvn exec:exec, but it won't help you
>>> package and ship your code out for other users."
>>> Once I get this running from the command line, this will be an option
>>> that I want to use. I'm still getting ClassNotFoundException though. I'm
>>> guessing that since I _can_ see the dependencies that this line must be the
>>> culprit:
>>> "<classpathPrefix>target/</classpathPrefix>"
>>> I'm going to try target/lib now.
>>>
>>> This is a sample client so packaging isn't too important at this point.
>>> Good to know, thank you.
>>>
>>>
>>> On Wed, Feb 5, 2014 at 10:17 PM, Wayne Fay [via Maven] <
>>> ml-node+s40175n5783328h45@n5.nabble.com> wrote:
>>>
>>>> > *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.
>>>>
>>>> You should specify the fully qualified main class eg:
>>>> com.mycompany.app.App
>>>> in the mainClass field/parameter to the plugin.
>>>>
>>>> Wayne
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&i=0>
>>>> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&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-tp5783294p5783328.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-tp5783294p5783372.html
Sent from the Maven - Users mailing list archive at Nabble.com.

Re: Build is successful but can't run?

Posted by TenLeftFingers <ja...@gmail.com>.
Cancel that. It does exist. And more importantly it exists in the
target/lib folder.


On Thu, Feb 6, 2014 at 11:11 AM, Jarlath Reidy <ja...@gmail.com>wrote:

> I have just noticed that the dependency it complains about does not exist
> in my .m2 folder. I don't know how Eclipse is executing this project but I
> would have expected mvn package to pull in that dependency to the local
> repository.
>
>
> On Thu, Feb 6, 2014 at 10:02 AM, Jarlath Reidy <ja...@gmail.com>wrote:
>
>> "You should specify the fully qualified main class eg:
>> com.mycompany.app.App
>> in the mainClass field/parameter to the plugin."
>> "1. the main-class-name was supposed to be your main class"
>> Let me clarify. The entry appears in the manifest as:
>> mainClass: fully.qualified.path.to.MyApp
>> instead of
>> Main-Class: fully.qualified.path.to.MyApp
>>
>> I've changed it in the pom (I thought that the tag was a fixed keyword so
>> I didn't change it there initially).
>>
>>
>> "The classpathPrefix line sets where to look for additional JAR files. It
>> is relative to where you are."
>> So relative to where I execute my java -jar ... command from. Okay, I
>> have that. I'm executing from the directory above (..) the target.
>>
>>
>> "Maven compiles and packages your program into a JAR. It copies all of
>> the supporting JAR files listed in your dependencies into target/lib.
>> Before you run, make sure that target/lib exists and has all of the JAR
>> files you need."
>> Yep, they're all there. Including the jar which contains the class it
>> says it can't load and I can see that that class is present in the jar.
>>
>>
>> "The exec plugin (http://mojo.codehaus.org/exec-maven-plugin/) as Wayne
>> has mentioned is another way to accomplish this. This will help you run
>> from within an IDE or by using mvn exec:exec, but it won't help you
>> package and ship your code out for other users."
>> Once I get this running from the command line, this will be an option
>> that I want to use. I'm still getting ClassNotFoundException though. I'm
>> guessing that since I _can_ see the dependencies that this line must be the
>> culprit:
>> "<classpathPrefix>target/</classpathPrefix>"
>> I'm going to try target/lib now.
>>
>> This is a sample client so packaging isn't too important at this point.
>> Good to know, thank you.
>>
>>
>> On Wed, Feb 5, 2014 at 10:17 PM, Wayne Fay [via Maven] <
>> ml-node+s40175n5783328h45@n5.nabble.com> wrote:
>>
>>> > *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.
>>>
>>> You should specify the fully qualified main class eg:
>>> com.mycompany.app.App
>>> in the mainClass field/parameter to the plugin.
>>>
>>> Wayne
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&i=0>
>>> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&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-tp5783294p5783328.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-tp5783294p5783371.html
Sent from the Maven - Users mailing list archive at Nabble.com.

Re: Build is successful but can't run?

Posted by TenLeftFingers <ja...@gmail.com>.
"You should specify the fully qualified main class eg:
com.mycompany.app.App
in the mainClass field/parameter to the plugin."
"1. the main-class-name was supposed to be your main class"
Let me clarify. The entry appears in the manifest as:
mainClass: fully.qualified.path.to.MyApp
instead of
Main-Class: fully.qualified.path.to.MyApp

I've changed it in the pom (I thought that the tag was a fixed keyword so I
didn't change it there initially).

"The classpathPrefix line sets where to look for additional JAR files. It
is relative to where you are."
So relative to where I execute my java -jar ... command from. Okay, I have
that. I'm executing from the directory above (..) the target.

"Maven compiles and packages your program into a JAR. It copies all of
the supporting JAR files listed in your dependencies into target/lib.
Before you run, make sure that target/lib exists and has all of the JAR
files you need."
Yep, they're all there. Including the jar which contains the class it says
it can't load and I can see that that class is present in the jar.

"The exec plugin (http://mojo.codehaus.org/exec-maven-plugin/) as Wayne
has mentioned is another way to accomplish this. This will help you run
from within an IDE or by using mvn exec:exec, but it won't help you
package and ship your code out for other users."
Once I get this running from the command line, this will be an option that
I want to use. I'm still getting ClassNotFoundException though. I'm
guessing that since I _can_ see the dependencies that this line must be the
culprit:
"<classpathPrefix>target/</classpathPrefix>"
I'm going to try target/lib now.

This is a sample client so packaging isn't too important at this point.
Good to know, thank you.


On Wed, Feb 5, 2014 at 10:17 PM, Wayne Fay [via Maven] <
ml-node+s40175n5783328h45@n5.nabble.com> wrote:

> > *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.
>
> You should specify the fully qualified main class eg:
> com.mycompany.app.App
> in the mainClass field/parameter to the plugin.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&i=0>
> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&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-tp5783294p5783328.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-tp5783294p5783366.html
Sent from the Maven - Users mailing list archive at Nabble.com.

Re: Build is successful but can't run?

Posted by TenLeftFingers <ja...@gmail.com>.
I have just noticed that the dependency it complains about does not exist
in my .m2 folder. I don't know how Eclipse is executing this project but I
would have expected mvn package to pull in that dependency to the local
repository.


On Thu, Feb 6, 2014 at 10:02 AM, Jarlath Reidy <ja...@gmail.com>wrote:

> "You should specify the fully qualified main class eg:
> com.mycompany.app.App
> in the mainClass field/parameter to the plugin."
> "1. the main-class-name was supposed to be your main class"
> Let me clarify. The entry appears in the manifest as:
> mainClass: fully.qualified.path.to.MyApp
> instead of
> Main-Class: fully.qualified.path.to.MyApp
>
> I've changed it in the pom (I thought that the tag was a fixed keyword so
> I didn't change it there initially).
>
>
> "The classpathPrefix line sets where to look for additional JAR files. It
> is relative to where you are."
> So relative to where I execute my java -jar ... command from. Okay, I have
> that. I'm executing from the directory above (..) the target.
>
>
> "Maven compiles and packages your program into a JAR. It copies all of
> the supporting JAR files listed in your dependencies into target/lib.
> Before you run, make sure that target/lib exists and has all of the JAR
> files you need."
> Yep, they're all there. Including the jar which contains the class it says
> it can't load and I can see that that class is present in the jar.
>
>
> "The exec plugin (http://mojo.codehaus.org/exec-maven-plugin/) as Wayne
> has mentioned is another way to accomplish this. This will help you run
> from within an IDE or by using mvn exec:exec, but it won't help you
> package and ship your code out for other users."
> Once I get this running from the command line, this will be an option that
> I want to use. I'm still getting ClassNotFoundException though. I'm
> guessing that since I _can_ see the dependencies that this line must be the
> culprit:
> "<classpathPrefix>target/</classpathPrefix>"
> I'm going to try target/lib now.
>
> This is a sample client so packaging isn't too important at this point.
> Good to know, thank you.
>
>
> On Wed, Feb 5, 2014 at 10:17 PM, Wayne Fay [via Maven] <
> ml-node+s40175n5783328h45@n5.nabble.com> wrote:
>
>> > *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.
>>
>> You should specify the fully qualified main class eg:
>> com.mycompany.app.App
>> in the mainClass field/parameter to the plugin.
>>
>> Wayne
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&i=0>
>> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5783328&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-tp5783294p5783328.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-tp5783294p5783370.html
Sent from the Maven - Users mailing list archive at Nabble.com.

Re: Build is successful but can't run?

Posted by Wayne Fay <wa...@gmail.com>.
> *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.

You should specify the fully qualified main class eg:
com.mycompany.app.App
in the mainClass field/parameter to the plugin.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Build is successful but can't run?

Posted by TenLeftFingers <ja...@gmail.com>.
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] <
ml-node+s40175n5783298h15@n5.nabble.com> 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.

Re: Build is successful but can't run?

Posted by Mark Eggers <it...@yahoo.com>.
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Build is successful but can't run?

Posted by Wayne Fay <wa...@gmail.com>.
> 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?

This line says "run Java with the classpath being my-app.jar and use
com.mycompany.app.App as the main/entry class."

Java says OK and happily tries to run your file. Then immediately
discovers that the classpath you have specified does not include one
or more classes - classes that you have declared as dependencies and
by using Maven to help manage during the compile process you don't
need to worry about the details of your classpath. This is exactly
correct.

But now you are dealing with run-time, not compile-time. Until now,
Maven has ensured that various dependencies are in the classpath --
but note that you are not running Maven, you are running Java, and
java does not know anything about Maven's pom and the dependencies
etc. So now you need to manually build out that classpath to run your
code with a lot more things in the -cp parameter.

A far simpler approach is to use the maven-exec-plugin and again let
Maven help with your run-time dependencies. Here is a link to that
documentation - I'm sure you can sort it out by click a few links and
doing 5 minutes of reading:
http://mojo.codehaus.org/exec-maven-plugin/

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org