• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Netbeans - why build project without preserving package directory structure?

 
Greenhorn
Posts: 23
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey folks,

Been thinking and searching about this question for a while, and I've never seen a very good answer. My problem is that I would like to be able to click "clean and build" and have my project ready to run from the jar without having to do another thing to it. If it runs in the IDE it should run from the command line, and it does if you have a single package and you have it pointing to the right libraries.

So, I have this bit of code...


which is called by



and uses the file

testScript.sql that contains the following line:


It all runs great when I build and run in the IDE, but I get this when I run the jar:



so I didn't mean for this to be such a huge post, but I really want to understand why this



works in the IDE but not from the command line. Is there a reason you would NOT want this to work automatically? Is there something I should be doing differently?

Wouldn't it make sense for everything in your project to be built into the jar? I didn't put it in that project by accident.

I guess I should mention that SQLScriptLoader.java is in a the package "sqlscripts" and BDConnector.java is in package "mytesting."
 
Ranch Hand
Posts: 624
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because there is no "src" directory when the application is built.
There are few ways for this.
One would be...do not use the relative path. Use the absolute path and take the path from input/properties file.

This is why using IDEs are not recommended while learning Java.
They can create a lot of confusion if you have not understood the basics yet.
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greg, you should only use file paths for files that are not going to be integrated with your application. If your application is not going to work without a certain script or image or data file, they should be part of the Jar, and they should also be referenced that way from your application.

You can make a directory in your project that contains a certain types of resources, and then add that to the source directories of your project by going to your project properties > sources > add folder.

You can then add packages and resources to that directory, and reference them like this:
Or if MyClass is in com.example.myapp:
 
Greg Zobel
Greenhorn
Posts: 23
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Greg, you should only use file paths for files that are not going to be integrated with your application. If your application is not going to work without a certain script or image or data file, they should be part of the Jar, and they should also be referenced that way from your application.

You can make a directory in your project that contains a certain types of resources, and then add that to the source directories of your project by going to your project properties > sources > add folder.

You can then add packages and resources to that directory, and reference them like this:
Or if MyClass is in com.example.myapp:



Yea, I understand all that. I'll just have to look into what ant does, or maybe maven to see if I can set up the build to my liking.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I really enjoy about Maven is that it has a strong opinion on where you should put your files. You could put your scripts in src/main/sql and then just access them using the getResourceAsStream() method as usual.
 
Greg Zobel
Greenhorn
Posts: 23
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What I really enjoy about Maven is that it has a strong opinion on where you should put your files. You could put your scripts in src/main/sql and then just access them using the getResourceAsStream() method as usual.



I haven't had time to look into it much, but from what I've read so far I'm leaning toward Maven just for that reason. Any thoughts on Gradle?
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't really checked Gradle out in depth, but I imagine it's very pleasant to use. I'm a Maven man myself, but that's mostly because I know it and I'm content with it.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I recall, Gradle has 2 advantages over Maven.

1. Allows building of non-Java projects

2. Project declaration is cleaner (YML, I think). You don't have to deal with XML

There's at least one shop in my town which uses Gradle extensively.
 
Greg Zobel
Greenhorn
Posts: 23
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couldn't hurt to try them both I guess. Gradle website says it uses Groovy. Looks interesting.
 
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic