I made a java application using javaFx on Eclipse IDE.
I am using JavaSE-11 compiler and the javafx-sdk-11 version.
It works when I run it from Eclipse, but now i'm trying to make a runnable .jar of the application.
When I double click on the .jar, nothing happens. I tried installing, uninstalling and reinstalling Java ...
Here are the issues I'm having when I try to launch it with [java -jar filename.jar] command :
Extracting the required libraries into generated JAR
java : Error : JavaFX runtime components are missing,
and are required to run this application
Packaging the required libraries into generated JAR
java : Graphics Device intialization failed for : d3d, sw
Error initializing QuantumRenderer : no suitable pipeline found
Don't hesitate to ask me more details, I'm not very good at this but I'm trying my best.
Thanks
I had same problem few days back. I just made another class that doesn't extend Application, and has its own main. Then just launched the application from that class like so:
public class Fakemain {
public static void main(String[] args) {
game.main(args); //this is the class that extends Application
}
}
Let me know if this worked for you.
Related
I've created a maven-based Java Swing project in Netbeans 12.1. I added some dependencies in pom.xml:
com.formdev.flatlaf 0.43
com.formdev.flatlaf-swingx 0.43
com.formdev.flatlaf-extras 0.43
I initialize the use of FlatLAF in my main form like this:
public static void main(String args[]) {
FlatLightLaf.install();
}
When I start my program in Netbeans, it all works perfectly. Netbeans uses this command to run the program:
cd /Users/rene/htdocs/my-program; JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-
12.0.1.jdk/Contents/Home "/Applications/NetBeans/Apache NetBeans
12.1.app/Contents/Resources/NetBeans/netbeans/java/maven/bin/mvn" "-Dexec.args=-classpath
%classpath de.renepoepperl.my-program.Login" -
Dexec.executable=/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java
org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
But when I build the program "with dependencies" and try to run java -jar my-program.jar I get multiple errors saying: java.lang.Error: no ComponentUI class for
I guess that, FlatLAF misses some configuration. But I don't know why.
What can I do to get FlatLAF working?
This happens in case that the FlatLaf classes were renamed by obfuscation or by other class minimizer tools (e.g. Maven Shade Plugin).
See https://github.com/JFormDesigner/FlatLaf/issues/104
Check whether the jar contains all files from the flatlaf.jar.
I'm trying to execute carel programs based on CSA106a Stanford class videos available on YouTube.
I've downloaded the jar and related files, imported the whole project into Neon Eclipse and am trying to run.
While clicking "run", I get the error:
Error: Could not find or load main class (default package).CheckerboardKarel
Note: other programs that I have created in Neon from scratch are working fine (not imported ones). Please help.
I've attached the screenshots as well.
I can't tell for sure, but I think there might not be a "main" function in what you downloaded. In order for a java program to run the class you are running needs to have a main function. it should look like:
public static void main(String[] args){
...
}
This is my first time with Java and Eclipse. I started a brand new Java project and I want to import/add NanoHTTPD into it. How do you this?
This is NanoHTTPD's site: http://nanohttpd.com
Thanks!
Edit
Lesson learned, be specific or you get backslashed for asking. I edited the question and here's some background and the problem I'm running into.
I'm developing a Nodejs backend that needs to query a JAVA project I was given. Pipes are a no go because the services will run on different machines. Tomcat seems like an overkill so I decided to use NanoHTTPD to develop the web service. I come from Ruby & Nodejs so compilation and Eclipse are very new to me. First off, I have no JAR file just TAR and ZIP and from what I read they are fundamentally different. However, I tried importing the TAR and ZIP files as recommended but the structure I get in Eclipse does not seem right compared to the JRE System Library or others I've seen. Notwithstanding, I went ahead and tried to import the package from my Main.java file
package fi.iki.elonen;
public class Main {
public static void main (String[] args)
{
System.out.println("Main");
}
}
When I try to run it I get the following error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Main.main(Main.java:4)
I found a great article from IBM "Managing the Java classpath (UNIX and Mac OS X)" where it mentions that an IDE such as Eclipse can alleviate the pain of dealing with the source path, classpath and compilation. Unfortunately, I'm afraid this is where I might be getting stuck.
I tried uploading images of what I have but apparently I'm not popular enough yet to do it.
Could someone help me figuring out how to not only import libraries but using them on projects? Even just a URL to a clear Linux/Mac OS X post that explains import with multiple packages would be great.
NanoHTTPD is designed to be very lightweight.
I just cut and pasted the 'NanoHTTPD' class from the source on github, its all in there - and pasted it as a class into my own project.
Then I created a subclass of nanoHTTPD, overrode the 'serve' method to send my own stuff and it was job done.
Download the jar, drag it into the project, and right-click it to add it to the build path.
I am using jdk 1.8 , jre 1.8 and eclipse juno.Whenever i use to run my program with eclipse it gives me this error
Error: Main method not found in class A, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
my basic program is
public class A {
public static void main(String[] args) {
System.out.println("Hello");
}
}
Then i tried to run my program from CMD on the first time it run successfully after that it also start giving me this error..Points to remember
When i create a new project i use default jre.which is jre 8.
I am not using any kind of javaFx Application.My basic program is in front of you all
I cant every time extend javafx .So i need a strong way to resolve it.
I run a program from the command prompt for the first time it run ,but when i run another program with little bit of change it did not run.
I am stuck here guys please give me a solution for that and a little bit of explanation for that will be appreciated..
Please, close your cmd prompt.
And reopen cmd prompt.
Then open your directory containing pom.xml
To build your project, Type : mvn install
Then run the java code. For eg,
java -cp target/sample-0.0.1-SNAPSHOT.jar com.maven.sample.HelloMaven
Here HelloMaven is the class name.
I had the same error. Imported java.lang.String and the error went off.
import java.lang.String;
I have a Scala project and I would like to export it as a jar.
*1. At first I tried creating a Java class for the project as an entry point
public class JMain {
public static void main(String[] args) {
System.out.println("Java main calling Scala main");
SMain.main(new String[] {""}); //SMain.main is the actual *main*
and this worked fine and dandy when launched from Eclipse, but when I export it as jar it'll give me 18 exceptions or so. I do now know how to replicate then "environment" in which Eclipse manages to launch this and I'm prety sure it relies on the fact that Scala is on my system already - I need a self contained jar with everything packed in there.
*2. My second try consisted of trying what lach suggested here How to deploy a Scala project from Eclipse?
namely:
public class JMain {
public static void main(String[] args) {
System.out.println("Java Main");
List<String> argList = new ArrayList<String>();
argList.add("fully.qualified.ClassName"); //???
for (String s : args) argList.add(s);
scala.tools.nsc.MainGenericRunner.main(argList.toArray(new String[0]));
This time it won't even run from Eclipse, although it gives only 6 or so exceptions starting with the famous NoClassDefFoundError. I have a feeling I'm not getting fully.qualified.ClassName right. *3. If the main Scala class is called "Dis.scala" and is located in package "pack" shouldn't this fully.qualified.ClassName be "pack.Dis"?
I'm using Jre 1.6 and Scala 2.9.2
EDIT: I have included all external imported jars, even scala-library.jar - everything is nice and packed in the jar
P.S. I am not familiar with Ant or Maven or Sbt. I just want my Scala project jared - if possible without getting into hairy things.
Here is what worked for me:
1. Create scala project
2. Create Wrapper java project
3. Add the scala-library.jar to you java project build path.
So you only need the 3rd step in addition since the rest looks similar to what I did. Then you can happily use: java - jar file.jar
EDIT:
How to create a JAR File which contains Scala/Code which can be consumed by another Java Project, using Scala - Eclipse IDE.
Create a new Scala Project and define an object with a main method as entry point.
Now create a new Java Project and add your Scala Project to the new ones buildpath. Additionally add the scala-library.jar to the Java project.
Now create a Wrapper class in the java project which calls your entry point class from the scala lib. Run the wrapper class to create a eclipse run configuration and test if you can call the scala project.
Use the Export->Java->Runnable JAR file, Wizard now on the wrapper project.The eclipse run configuration will be used as entrypoint into the JAR. Depending on your needs you may want to :
extract required libraries into generated JAR
or
Package required libraries into generated JAR
Finally you get a complete packaged JAR which you can use like this:
java - jar wrapped.jar
For me, it was relatively straightforward.
Develop and test the project using the scala IDE (or eclipse for java).
once ready, generate the jar for the project using file -> export method.
for submitting the spark (i was writing something for spark), i just had to mention --class option for specifying the main class for the jar.
hope to help.