Home > Net >  Eclipse: How to Include Files in Build But Not in Export
Eclipse: How to Include Files in Build But Not in Export

Time:04-20

In Eclipse, I know how to include additional files in a build by adding them to the Build Path. And I know how to exclude files from a build by adding include/exclude filters on the included folder. But what I'm trying to figure out is how to do a combination of the two such as include a file in the build but not in the export. And I want to do this without Ant, Maven, etc.

Here's the situation:

I have a simple Java project. It includes a properties file with logon information for a server. I want a build that will include this file in the classpath so that it is found while I'm developing and debugging in Eclipse. But, when I'm ready to export a runnable .jar, I want it to exclude this file because it's a security risk, etc.

For sake of discussion let's assume this project structure:

MyProject
     ----bin
     ----lib
     ----src
     ----resources
              ----application.properties
              ----version.properties

Ideally, I'd like the build and the export to ignore application.properties but include version.properties. Then at run time (both in Eclipse & from runnable .jar) I'd like the app to be able to find application.properties in the resources/ folder.

Doesn't work:

I've tried some variations like including the "resources" folder in the build path but excluding application.properties, But this seems to also prevent application.properties from being found at runtime.

Solutions?

I suspect that this fundamentally can't be done in Eclipse alone as it seems to require the file to be simultaneously both on and not on the buildpath.

I know that I can just open the .jar and remove the files. This is probably what I'll end up with, but I'd rather have a cleaner solution for those who come after me. This seems like it would be a common scenario -- configuration files kept out of a jar but kept on the build path. How do you others handle this?

CodePudding user response:

Add the things you need for running locally and that should not be included in the JAR to the launch configuration (tab Dependencies) instead of to the Java Build Path of the project.

  • Related