Why doesn't my package (.jar) contain my data/ directory?

Answered

In IntelliJ, I "view", "tools window", "Maven project", and then I use "package" to create a *.jar-with-dependencies.jar file for my project. I specified my main class in the pom.xml. When I run it in the target/ directory, it has no problem. However, I need to copy the jar to another place to run in at command line, then I ran into a problem, it can't find the input file which resides in the data/ directory under my root directory.

I guess it's because the data/ directory isn't packaged in the jar. Why is it that? Is that because the 'data/' is specified in my .gitignore file? What I really want is to exclude the whole data/ directory to be included in the jar, but only include a subdirectory of the data/ in the jar, so that when I run my jar at command line, I don't have to modify my code to pass the input file directory as a command line argument. More specifically, 

data/

...

data/search/

I want the "data/search" to be included in the jar, but not the data/ root. Is there a way to achieve this? Thanks.

  

 

2 comments
Comment actions Permalink

See https://www.jetbrains.com/help/idea/artifacts.html and http://stackoverflow.com/a/42200519/104891.

Normally only directories configured as resources are added to the jar by default. Either place the files you need under the existing resources directory (src/main/resources), see https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html, or customize Maven via pom.xml to use a different directory for resources.

0
Comment actions Permalink

Thanks Serge!

0

Please sign in to leave a comment.