Delphi 10.1 Berlin - Java2OP: class or interface expected - java

I'm using Delphi 10.1 Berlin. I want to call Java codes from Delphi. So, I created JAR file in Android Studio (this link helped to me). Then I opened Java2OP.exe from C:\Program Files (x86)\Embarcadero\Studio\18.0\bin\converters\java2op directory. I moved the jar file to this directory. Then I worked this commands in CMD:
SET PATH=%PATH%;"C:\Program Files\Java\jdk1.8.0_60\bin"
Java2OP.exe -jar ..\libmylib.jar -unit ..\Androidapi.JNI.MyLib
But I get this error:
Warning: error opening ReservedWordsOP.txt
Warning: error opening ReservedWordsC.txt
Parsing xml: C:\Program Files (x86)\Embarcadero\Studio\18.0\bin\converters\java2op\bootclasses.xml
Parsing jar: ..\libmylib.jar
class or Interface expected
This my Java class for JAR:
public class Test
{
public String work()
{
return "Hello World!";
}
}
Also I tried different Java codes, but result is same. How can I solve this problem?

I have the same problem, and solved it removing spaces from path files.
Probably the Java2OP is calling the Java passing the path without quotes.

Related

javac isn't working in Desktop and Documents Directory

I installed jdk1.8.0_202 and set the path for jdk1.8.0_202/bin, jre1.8.0_202/bin and JAVA_HOME in both 'user variables' and 'system variables'.
I created a test java file on Desktop and opened cmd(non admin) and tried to compile which resulted in the following error.
C:\Users\andey\Desktop>javac Main.java
Main.java:2: error: error while writing Main: Main.class (The system cannot find the file specified)
public class Main {
^
1 error
Same happened with Documents folder and sub folders. I also tried using cmd(elevated) but I got same error.
I could compile successfully on any other folder except those 2 folders(Desktop and Documents) even using non-elevated cmd.
I want my programs to be either on desktop or in documents.
Any help is appreciated.

can't run .jar file /java.jar: line 1: public: command not found

I have Ubuntu 16.04.
and downloaded a JDK with a tar.gz file extension and followed This wikihow to install it.
When I try to run a .jar game (like Minecraft) It works successfully, and I have netbeans downloaded that is connected to the same JDK and compiled some programs that i can run in terminal, But When I type :
./Hello_world.jar
Which is :
package main;
public class project {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
I get this output :
./Hello_world.jar: line 1: $'PK\003\004': command not found
./Hello_world.jar: line 2: $'\b.\020oK': command not found
./Hello_world.jar: line 3: syntax error near unexpected token `)'
./Hello_world.jar: line 3:-oK�}����META-INF/MANIFEST.MFM�1
�0��#��uHh Q���X� ��N1�Ҧ$)��7�(�p�ww
�A����|��}�1���ή�n��p<�Рŗ��:CpN~�s�ν�˚�3��%
��)���goPK`
Simple: JAR files aren't executables. You can only invoke binaries/scripts by telling your shell to ./command.
They are archives that contain compiled Java classes.
Thus you use them like:
java -jar somejar.jar
This starts a java virtual machine, and tells it to open the given JAR file. The JVM will then figure the "main" class to run from the meta information that can be backed into the JAR file - to then "run" that main class.
( assuming that the corresponding JAR file has been built in a why that allows running it like this. see here for details on how you enable this "easy way" of running a JAR file )
And just in case: with some scripting magic, you actually can turn a JAR file into a "binary", see here for example.

How do you use java files in Coldfusion 9?

Im using Coldfusion 9 with Multiserver/J2EE on JRun 4 Configuration in a development engine.
I try to apply sample below into my coldfusion engine however it not work.
Sample : How do you use java files in Coldfusion
Perhaps anyone here can help me to resolve this issue?
Here is what i did :
1) Write a simple Hello.java file, compile into Hello.class file.
public class Hello
{
public String testJava()
{
return "Hello Java!!";
}
}
2) Write a cfm file : jHello.cfm to call the java object.
<cfscript>
helloWorld = CreateObject("java","Hello");
helloTest = helloWorld.testJava();
</cfscript>
3) Save the .class file into class path :
4) Restart coldfusion 9 Server
5) However, it return Error below when run JHello.cfm file :
Object Instantiation Exception.
Class not found: Hello
The error occurred in C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/accuity_dev/JHello.cfm: line 2
1 : <cfscript>
2 : helloWorld = CreateObject("java","Hello");
3 : helloTest = helloWorld.testJava();
4 : </cfscript>
Appreciate your time, hope can get back from any expert here.
Do you have access to CF administrator page? I see a ear/war in path indicating a different configuration than what I have tried or used before. I have done multiple instances but not with J2EE ear/war.
If you can access administrator page, then go to java/jvm settings page. In that, put the full absolute path of the .class file and hit submit. You will have to restart CF.
Note : this is no different than editing the jvm.config file but you dont have to worry about syntax especially windows vs linux, forward slash or back slash.
Finally, please make a backup of jvm.config before making any changes via CF administrator.

I get an error: An unexpected error occurred while trying to open file hola.jar

i am using Linux ubuntu and i have created a java program named hola.java which is the following program code, this program works perfectly
import javax.swing.*;
import java.awt.*;
public class hola extends JFrame {
JButton b1 = new JButton("presionar");
hola(){
super("Botones");
setSize(250,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flo=new FlowLayout();
setLayout(flo);
add(b1);
setVisible(true);
}
public static void main(String[] args)
{
hola bt = new hola();
}
}
This java program works perfectly when it runs
Now I created a jar file of this program using in command line:
jar cf hola.jar hola.class
This creates a Jar file named hola.jar
I even wrote Main-Class: hola in the manifest.mf file.
When I try to run this by:
java -jar hola.jar
I get an error: An unexpected error occurred while trying to open file hola.jar
Please tell me how to run jar file so that I get an output :'( , what could be the possible reason that i can not run this program as a jar file, even the program works perfectly using "java hola.java"
This error mostly indicates invalid MANIFEST.MF file. Perhaps long line, missing final line terminator, accidental empty line in the middle, ... many things can go wrong. Using -cp just goes around the problem, but does not fix the root cause.
To run a java file within a jar file, you don't need to open it. You simply need to ensure your classpath is having the given jar file
If the class is within a package then you can run using
java -cp hola.jar package.hola
If the class is not in a package then simply use
java -cp hola.jar hola
If you are not within the directory where hola.jar is located, then you can try following:
In case of within package
java -cp /locationOfJar/hola.jar package.hola
or In case of not in package
java -cp /locationOfJar/hola.jar hola
Error can also happen with > 65535 files in the .jar on some OS
I experienced same error message attempting to launch via -jar:
$ java -jar app.jar
Error: An unexpected error occurred while trying to open file: app.jar
Root cause is that my sbt-assembly output .jar file contains more than 65535 entries.
$ zipinfo app.jar |wc -l
65543
Solution: Short term solution was removal of older dependencies to lower the number of assembled .class files below the 16 bit file count limit.
Long term solution will involve testing Zip64 jvm support on the target OS. Unsure of why the zip64 auto negotiation isn't occurring automatically.
This issue is reproducible using sbt-assembly 15.0, openjdk version "11.0.8" on MacOSX 10.15.7.
Start of the code review:
package java.util.zip;
...
public
class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
/**
* Whether to use ZIP64 for zip files with more than 64k entries.
* Until ZIP64 support in zip implementations is ubiquitous, this
* system property allows the creation of zip files which can be
* read by legacy zip implementations which tolerate "incorrect"
* total entry count fields, such as the ones in jdk6, and even
* some in jdk7.
*/
private static final boolean inhibitZip64 =
Boolean.parseBoolean(
GetPropertyAction.privilegedGetProperty("jdk.util.zip.inhibitZip64"));

Why can't I load this class file in Rhino console?

I'm prototyping a web page scraper using Rhino and Env-js. Nevermind that the documentation for both projects is atrocious... I'm trying to load up the File.java example class that is supplied with Rhino. For simplicity sake, I've got File.java, js.jar, jline.jar and env.rhino.1.2.js all in one directory. I've tried specifying the current directory using the classpath command line option, but still whenever I call defineClass("File") I get an error saying the class file isn't found. What am I doing wrong here??
$ ls -1
File.java
env.rhino.1.2.js
jline.jar
js.jar
$ java -cp .:js.jar:jline.jar jline.ConsoleRunner org.mozilla.javascript.tools.shell.Main -opt -1
Rhino 1.7 release 2 2009 03 22
js> defineClass("File")
js: "<stdin>", line 2: Class "File" not found.
at <stdin>:2
Don't you need to compile File.java before using it, as the classpath "." only makes sense if it contains some compiled class in it?

Categories

Resources