Guest User

Executable jar won't find the properties files

a guest
Feb 22nd, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Properties properties = new Properties();
  2. URL url = new App().getClass().getResource(PROPERTIES_FILE);
  3. properties.load(url.openStream());
  4.  
  5. <plugin>
  6. <artifactId>maven-assembly-plugin</artifactId>
  7. <version>2.2</version>
  8. <configuration>
  9. <descriptorRefs>
  10. <descriptorRef>jar-with-dependencies</descriptorRef>
  11. </descriptorRefs>
  12. <archive>
  13. <manifest>
  14. <mainClass>com.stackoverflow.App</mainClass>
  15. </manifest>
  16. <manifestEntries>
  17. <Class-Path>.</Class-Path> <!-- HERE IS THE IMPORTANT BIT -->
  18. </manifestEntries>
  19. </archive>
  20. </configuration>
  21. <executions>
  22. <execution>
  23. <id>make-assembly</id> <!-- this is used for inheritance merges -->
  24. <phase>package</phase> <!-- append to the packaging phase. -->
  25. <goals>
  26. <goal>single</goal> <!-- goals == mojos -->
  27. </goals>
  28. </execution>
  29. </executions>
  30. </plugin>
  31.  
  32. java -cp .;filename.jar com.example.YourClassWithMain
  33.  
  34. URL root = getClass().getProtectionDomain().getCodeSource().getLocation();
  35. URL propertiesFile = new URL(root, "filename.properties");
  36. Properties properties = new Properties();
  37. properties.load(propertiesFile.openStream());
  38.  
  39. Class-Path: .
  40.  
  41. <plugin>
  42. <artifactId>maven-jar-plugin</artifactId>
  43. <configuration>
  44. <resources>
  45. <resource>
  46. <directory>src/main/java</directory>
  47. <includes>
  48. <include>**/*properties</include>
  49. </includes>
  50. </resource>
  51. </resources>
  52. </configuration>
  53. <plugin>
  54.  
  55. <!-- Create a custom MANIFEST.MF file, setting the classpath. -->
  56. <delete file="${project.base.dir}/resources/MANIFEST.MF" failonerror="false"/>
  57. <manifest file="${project.base.dir}/resources/MANIFEST.MF">
  58. <attribute name="Class-Path" value="." />
  59. </manifest>
  60.  
  61. <!-- JAR the server-side code, using the custom manifest from above. -->
  62. <jar destfile="services/${name}.aar" manifest="${project.base.dir}/resources/MANIFEST.MF">
  63. [....]
Add Comment
Please, Sign In to add comment