I have my own project(https://github.com/reinvert/CrossStitchConverter)
And I always compile the project on eclipse by File-Export-Runnable JAR File-(Library handling)Package required libraries into generated JAR.
It works fine, but the jar file size is too big(83.0MB)
How can I reduce the file size?
I tried jlink, jpackage, and etc, but none of those have an effect.
This is my pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CrossStitchConverter</groupId>
<artifactId>CrossStitchConverter</artifactId>
<version>1</version>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>CrossStitchConverter</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>io.github.palexdev</groupId>
<artifactId>materialfx</artifactId>
<version>11.13.3</version>
</dependency>
</dependencies>
</project>
I found large library file(JavaFX-web-17.0.2-linux.jar and JavaFX-web-17.0.2-win.jar, which is total 50MB) in exported jar file, so I deleted these file and tried to run jar file, it worked. I think other unused jar library can be removed as those, but I can't find an option for it.
Related
I am making a JavaFX project (for the GUI) on Maven and for the moment I want to convert a StringBuffer object to JSON.
I tried to add the dependency org.json from Maven but there is a problem in pom.xml file
Missing Artifact org.json:json:bundle:20220924
I tried adding an older version of org.json dependency, it had the same issue
I tried a different dependency, everything was ok in the pom.xml file but I could not import it into my project (any dependency).
All dependencies return this error: The type org.json.JSONArray is not accessible
Lastly, I tried to download the json-java.jar from github and add it into a libs folder on the base project directory and added it in the pom file as a dependency but it could not be resolved either.
My pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>books</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
<type>bundle</type>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/json-20220924.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
In the end I downloaded Maven again and extracted it into a folder and changed my environment variables on path. Maven is successfully installed on version 3.8.7
Thank you in advance for any help!
UPDATE
I should mention that I tried it on a new java project (without maven) and it works fine, by importing the .jar file from git-hub repository
There are a lot of threads about JavaFX not being included with JDK 12/11, and that you need to have your own installation of JavaFX, but I found only this example of a modular installation without external download requirements :
https://github.com/openjfx/samples/tree/master/IDE/IntelliJ/Modular/Maven
Here is my pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>scheduler</groupId>
<artifactId>shop-solver</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>scheduler.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>com.jfoenix</groupId>
<artifactId>jfoenix</artifactId>
<version>9.0.8</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.21</version>
</dependency>
</dependencies>
I'm still getting this error when I try to run through the javafx:run plugin :
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --module-path
When I try to run from IntelliJ I get another error :
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0xd5599b7) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0xd5599b7
The project worked fine under JDK1.8 and JavaFX 2, here is a video of the error happening on the upgrade : https://puu.sh/E25JW/7ecdca26d7.webm
Again, the issue is that I'm trying to build all of this modularly, I want to be able to publish a repository with maven dependencies and maybe plugin or build directives, but do not want to have people who clone my repo need to install JavaFX externally outside of Maven. Thanks.
I'm trying to install j-text-utils to make a table. When I click on the jar file, nothing happens. So I tried make a .bat file and run the file from cmd. However, this shows up:
no main manifest attribute, in j-text-utils-0.3.3.jar
I searched around and the problems were mainly with pom.xml and MANIFEST.MF.
I dragged the file in Eclipse and the thing did have both pom.xml and MANIFEST.MF.
Here is what the pom.xml looks like:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dnl.utils</groupId>
<artifactId>j-text-utils</artifactId>
<packaging>jar</packaging>
<version>0.3.3</version>
<name>Java Text Utilities</name>
<url>http://code.google.com/p/j-text-utils</url>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>org.jvnet.wagon-svn</groupId>
<artifactId>wagon-svn</artifactId>
<version>1.9</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>googlecode</id>
<url>svn:https://d-maven.googlecode.com/svn/trunk/repo/</url>
</repository>
</distributionManagement>
</project>
Here is what the MANIFEST.MF looks like:
Manifest-Version: 1.0
Built-By: danielo
Build-Jdk: 1.7.0_45
Created-By: Apache Maven 3.1.0
Archiver-Version: Plexus Archiver
How may I fix this problem please? :(
I used the download link from Google Code: https://code.google.com/archive/p/j-text-utils/downloads
This .jar file is to be used as a library, not a as an executable application.
To access the functionalities, you should write your own application in Java and import the needed classes contained in the j-text-utils-0.3.3.jar file.
To be able to compile your Java code, the j-text-utils-0.3.3.jar needs to be available on the classpath.
See this question for more info : What is a classpath and how do I set it?
I am trying to follow the Maven in 5 Minutes tutorial for my project but for some reason I can't seem to actually run my project when it builds. I have the following pom.xml file:
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my-group</groupId>
<artifactId>my-artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/jfxrt.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<manifest>
<mainClass>com.my.package.MyClass</mainClass>
</manifest>
</configuration>
</plugin>
</plugins>
</build>
</project>
The tutorial seems to imply that I can do this from my project root:
mvn package
java -cp target/my-artifact-0.0.1-SNAPSHOT.jar com.my.package.MyClass
However, if I try to do this, I get the following error message:
Error: Could not find or load main class com.my.package.MyClass
If I run java -cp ../my-artifact-0.0.1-SNAPSHOT.jar com.my.package.MyClass from the target/classes directory I still get the same message, which is weird because I've verified that the .class file is there. Why am I not able to run my project after building it with the above steps?
I am writing an android library project and would like to add the support for maven. My library project pom file looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my_group_id</groupId>
<artifactId>my_artifactId</artifactId>
<version>1.0.1</version>
<packaging>apklib</packaging>
<name>My Library Project</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<extensions>true</extensions>
<configuration>
<sdk>
<platform>19</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
My main project pom file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.simpligility.android</groupId>
<artifactId>helloflashlight</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>
<name>HelloFlashlight</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>my_group_id</groupId>
<artifactId>my_artifactId</artifactId>
<version>1.0.1</version>
<type>apklib</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<extensions>true</extensions>
<configuration>
<sdk>
<platform>19</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
I am installing the library project to my local repository using:
mvn clean install
then I am compiling and installing the main project to my local repository using:
mvn clean install
and generating the apk using:
mvn android:deploy
Now the problem occurs when I compile the project with maven. The project compiles successfully, however when I am running the apk on the device I receive NullPointerException when trying to perform findById for resources that are inside the library project. Please note that part of the time findById does return value, but not always the correct type (e.g, expected layout but got a button). It is important to say that when running in eclipse without maven everything works perfectly.
Please advise
Finally I found the solution, so I'll update my answer for future readers.
The solution to this problem was to create aar file instead of apklib file using maven.