• Post Reply Bookmark Topic Watch Topic
  • New Topic

Netbeans - why build project without preserving package directory structure?  RSS feed

 
Greg Zobel
Greenhorn
Posts: 23
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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."
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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: 7969
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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: 7969
143
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Holloway
Saloon Keeper
Posts: 18791
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couldn't hurt to try them both I guess. Gradle website says it uses Groovy. Looks interesting.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!