QtJambi example not executing - java

I'm trying to compile and run the tooltip code from this tutorial. I obtained QtJambi from my package manager (the package is qtjambi-beta from AUR), which installed it into the directory /opt/qtjambi-beta/. In particular, the qtjambi-4.7.0.jar file is located at /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar.
Now, I made a folder called qtpractice and put the example in there under the name JambiApp.java. The code I put into it was exactly as follows (following the example I linked):
package qtpractice;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QWidget;
public class JambiApp extends QWidget {
public JambiApp() {
setWindowTitle("Tooltip");
setToolTip("This is QWidget");
resize(250, 150);
move(300, 300);
show();
}
public static void main(String args[]){
QApplication.initialize(args);
new JambiApp();
QApplication.exec();
}
}
I compiled it with javac qtpractice/*.java -cp /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar, which worked fine. I then tried to execute it with java qtpractice.JambiApp, and I got the following error:
Error: Could not find or load main class qtpractice.JambiApp
EDIT: Based on some advice from the comments, I tried this command instead: java -cp /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar qtpractice.JambiApp
. When I did this, I got the following error again:
Error: Could not find or load main class qtpractice.JambiApp
What did I miss? From what I can tell, I did everything necessary to make it execute.

You need to include all jars Qt Jambi needs in classpath.
This can be done on CLI with command similar to
java -cp /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar:/opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-linux64-gcc-4.7.0.jar:. qtpractice.JambiApp
When compiling, native jar does not need to be present, as the native libraries are just for Jambi classes to be able to use Qt.

Related

Java file compile using javac unable to refer to other files in the same directory

I am trying to migrate from IDEs like Eclipse to a standalone Java environment, but I'm having problems tying together multiple files into a project.
Here is some sample code, where both files are in the same directory:
App.java
package com.example.main;
public class App {
public static void main(String[] args) {
Example.test();
}
}
Example.java
package com.example.main;
public class Example {
public static void test() {
System.out.println("It's working");
}
}
When running App.java in an IDE, the expected output of It's working is printed, however after executing javac *.java the files seem to ignore eachother.
Here is the error that occurs when executing java App.java after it's been compiled:
App.java:5: error: cannot find symbol
Example.test();
^
symbol: variable Example
location: class App
1 error
error: compilation failed
How can I compile the files in a project so that they recognise eachother?
If you running Java 11 and above, java App.java will compile App.java only.
If you need to refer Example.java, first you need to compile both java files into a directory.
Let give it named 'classes'. The command will be
javac -d classes *.java
After that, you can run it via
java -cp classes com.example.main.App. Please note that App is without .class suffix
Of course, it is advisable to use build tools like Apache Maven or Gradle to build your project if it grow larger or need other dependencies.

Using command prompt to execute .java

I am trying to use the command line to execute a java class but I am receiving the below error
"error could not find or load main class
caused by java.lang.noclassdeffounderror"
I could used the "javac" to create my java class but then I ma getting this error.
Thank you for any help,
Regards
package start;
public class sdz1 {
public static void main(String[] args) {
System.out.println("Hello World !");
}
}
I just found that is not working when I am in the src folder created by eclipse where my ".java" is located.
Anyone has a explanation why is not working in this case ?
Check you've all required classes present at runtime as those were available at compile time
NoClassDefFoundError :- comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time
Read more: https://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html#ixzz6VZaZBT8y
Check that you have written all the "public class..." and the main method. If you then compile it, it shouldn't give you errors.
If your program is in directory start, execute this from the directory just above that to compile:
javac start/*.java
and then execute this to run:
java start/sdz1

Compiling Java with multiple classes with javac

Until now I always used an IDE to write my java apps. Now for different reasons, mainly also to understand more about the language and the things the IDE is just making for you, I switched to vim and have now the following problem:
I wrote two classes:
package seedInformatik.LinearList;
import seedInformatik.LinearList.*;
// A linear list. Contains LinearListElement<T>
public class LinearList<T> {
and
package seedInformatik.LinearList;
public class ListElement<T> {
Now I want to compile LinearList and get the following:
➜ LinearList javac LinearList.java
LinearList.java:10: error: cannot find symbol
private ListElement<T> first; // head of list
^
Both classes are in the same dir. What do I miss?
Many Thanks
Robin
Maybe this can help:
javac *.java // compliles all java files in the dir
java MyClass // runs the particular file
If your files are under some package you need to specify the package like this:
javac com.mypackage/.*java
java com.mypackage.MyClass
I would also recommend using a build tool like maven: http://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project

Class not found - JavaFX Native Packaging

I'm trying to deploy a program that I created but I'm having an error after the installation.
I used Native Packaging to package it as an EXE installer and when I click said installer, it says the main class cannot be found. Here are some screenshots of the error:
Why is it not finding the class?
This is not always the best method.
However, I had the same problem but it was solved.
First, if you are using kotlin,
Create a main class that will be the new entry point as a Java file.
The generated Java file should be as follows:
package {your_package};
import javafx.application.Application;
public class EP extends Main {
public static void main(String... args) {
Application.launch(args);
}
}
The Main should be the class that seems to be the current entry point.
Perhaps the Main is defined as open class Main: Application () {.
Set the EP class generated this time as the entry point (main class).
If exe is generated as -native image,
Please try to execute the generated exe, paying attention to the following points.
○ Make sure the generated directory does not contain spaces or multibytes.
○ Do not execute directly from USB etc. (Copy to PC and execute)
I ran into the exact same issue. I used maven and spring boot for the project. So after using maven to build the jar first then used org.springframework.boot.loader.JarLauncher for the -appclass option. Problem solved.

Using guava with j2objc

I'm trying to use guava with j2objc but I'm getting the error:
j2objc TestJava.java
translating TestJava.java
error: TestJava.java:1: The import com.google.common cannot be resolved
error: TestJava.java:10: Lists cannot be resolved
Translated 0 files: 2 errors, 0 warnings
while running:
j2objc Test.java
where Test.java contains:
import com.google.common.collect.Lists;
import java.util.ArrayList;
public class Test {
public static void TestMethod() {
ArrayList<String> objects = Lists.newArrayList();
objects.add(0, "Hello world");
System.out.println(objects);
}
}
I've downloaded the lastest release 0.9.5 and added it to .profile:
export PATH=$HOME/bin/j2objc-0.9.5:$PATH
What else do I need to do in order to use guava?
Thanks!
The j2objc translator uses a Java compiler as its front-end, so the same classpath and sourcepath needs to be used when translating as when compiling to Java classes. Here you'll get a similar error if you ran "javac Test.java", because the guava jar needs to be included in the classpath. The j2objc distribution includes lib/guava-jdk5.jar, so run "javac -classpath /lib/guava-jdk5.jar Test.java", and fix any problems with the directory for the guava jar if necessary. Once javac can compile it, substitute "j2objc" for "javac" using the same arguments, and it should translate fine.
You don't always have to use javac first, but whenever there are translation errors reported, it's a quick test to see whether the issue is related to a missing source or class path.
One difference from Java is that when you link the application, the -lguava flag is needed to include that library.

Categories

Resources