Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Idea Import Library Maven Project

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added a library dependency to my Maven project. So in my POM, I added:



I then utilized a single function:

When I run the code in the IDE, it runs just fine, no errors, and makes the names I feed it uppercase (first letter), just like I want it to.  However, when I run it from the command prompt:

java -jar IntoTheVoid.jar
...when I get to the code that capitalizes the word:



Why would it run fine in the IDE, but not from the JAR?
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Setting your classpath is a common Beginning Java question. But since you apparently used Maven to set up your jar file, it would be better to ask the question in the Maven forum. I've moved the thread there. However, more information about how you used Maven and where the jar file came from would be helpful.
 
A Diamond
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure. I didn't download any extra jars, but I'm assuming the IDE did, using the Maven info that I plugged in above.
 
Saloon Keeper
Posts: 13394
296
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IDEs don't use the jar command to run Maven artifacts, but the mvn command, specifically the exec goal of the exec-maven-plugin. This goal uses the POM to add your runtime dependencies to the class path.

You have a couple of options:

  • Use mvn exec:exec to run your application.
  • Add your dependencies to the classpath using the -cp command line switch.
  • Add your dependencies to your JAR's CLASS-PATH manifest entry.
  • Make a fat JAR that also contains your dependencies.

  • I recommend using either mvn exec:exec or adding your dependencies to your manifest. You can easily do the latter by configuring the maven-jar-plugin in your POM.
    reply
      Bookmark Topic Watch Topic
    • New Topic