Skip to content

Commit

Permalink
Add support for packaging fat jars
Browse files Browse the repository at this point in the history
  • Loading branch information
DanClowry committed Nov 30, 2019
1 parent 28e6367 commit 5403403
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
28 changes: 26 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,35 @@
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<version>0.0.3</version>
<configuration>
<mainClass>com.danclowry.noteapp.App</mainClass>
<mainClass>com.danclowry.noteapp.Launcher</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>project-classifier</shadedClassifierName>
<outputFile>shade\${project.artifactId}.jar</outputFile>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.danclowry.noteapp.Launcher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
8 changes: 8 additions & 0 deletions src/main/java/com/danclowry/noteapp/Launcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.danclowry.noteapp;

public class Launcher {

public static void main(String[] args) {
App.main(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private String loadLicence(String licenceName) {
String licenceText = "";
try {
licenceText = LoadResource.LoadResource(licencePath);
} catch (IOException | URISyntaxException ex) {
} catch (IOException ex) {
AlertBuilder.createExceptionAlert("Error - failed to load licence",
"Could not load credit licence text", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public List<Note> getNotesByTitle(String searchTerm) throws SQLException {
}

@Override
public void setupDatabase() throws SQLException, IOException, URISyntaxException {
public void setupDatabase() throws SQLException, IOException {
MysqlDataSource setupDataSource = new MysqlDataSource();
setupDataSource.setURL("jdbc:mysql://" + DatabaseConfig.getHostname());
setupDataSource.setUser(DatabaseConfig.getUsername());
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/com/danclowry/noteapp/util/LoadResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

import com.danclowry.noteapp.App;

import java.io.File;
import java.io.FileReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.LineNumberReader;
import java.net.URISyntaxException;
import java.util.StringJoiner;
import java.io.InputStream;

public class LoadResource {
public static String LoadResource(String path) throws IOException, URISyntaxException {
File file = new File(App.class.getResource(path).toURI());
try (LineNumberReader lr = new LineNumberReader(new FileReader(file))) {
StringJoiner sr = new StringJoiner(System.getProperty("line.separator"));
String line;
while ((line = lr.readLine()) != null) {
sr.add(line);
}
return sr.toString();
public static String LoadResource(String path) throws IOException {
InputStream file = App.class.getResourceAsStream(path);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;

while ((length = file.read(buffer)) != -1) {
bos.write(buffer, 0, length);
}

return bos.toString();
}
}

0 comments on commit 5403403

Please sign in to comment.