I am experiencing a lot of trouble while trying to run a jar file in the terminal. Until now, my command line looks like this:
java -jar /usr/src/Apache_FOP/fop-2.3/fop/build/fop.jar
Notice that i have already builded Apache FOP from source using Apache Ant, and the fop.jar is running fine when i run this line in the same folder. The problem is, whenever i'm trying to run it from any different directory, (let's call it TestFolder), i get this error:
Unable to start FOP:
java.lang.RuntimeException: fop.jar not found in directory: /home/evandro.teixeira/TestFolder (or below)
at org.apache.fop.cli.Main.getJARList(Main.java:71)
at org.apache.fop.cli.Main.startFOPWithDynamicClasspath(Main.java:130)
at org.apache.fop.cli.Main.main(Main.java:219)
I'm not really sure of how is this related to Java, ApacheAnt or ApacheFop, but for some reason the fop.jar file is indeed executed if ai run the command line like this:
cd /usr/src/Apache_FOP/fop-2.3/fop/build ; java -jar fop.jar
The problem with this attempt is that i can't pass any parameters to fop.jar that are not within the same directory when using $# in a shell script, and i really need them to be outside the fop.jar folder.
Any ideas?
Related
When i try to execute to execute this line
bash -x ExecutionAuto.bat
I get an error from my Lib folder saying that one of the jars isnt working properly.
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 1: $'PK\003\004': command not found
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 2: $'ؔ\220L': command not found
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 8: syntax error near unexpected token `)'
��������0 6&»���2<��߽�{�i'���arseBitSet-1.2.jar: line 8: `��6)Ѐ*u)�����RP �rN-p�đ�
�{�eB�M}i��Qa0�{}/�aHU�
'���xQXk)�Ћ.'?l3����A�I�|��0AİV���v�)s ?���5N���V��v��hH�;"���~Gt D��}|ȣ^�`�ܨ"r��d���}7��0t)y���{�W���
+ java org.testng.TestNG ../Demo_Automatisation/testng.xml
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
I dont know if there is a probleme with the jar files since it works fine in Windows but in linux it doesnt work.
This is my .sh file:
export projectLocation=../Demo_Automatisation
cd $projectLocation
export CLASSPATH=$projectLocation/bin;$projectLocation/lib/*
java org.testng.TestNG $projectLocation/testng.xml
I just coppied what i found on the internet since i had a .bat file at first since i was using Windows does transferring from Windows to linux requieres that i do something to my jar files ?
The issue is that the ; in your classpath definition actually separates two commands so the $projectLocation/lib/* is interpreted as a new command, expands to the name of the jar file and the shell tries to execute the jar file as a shell script (which fails miserably). On Linux the separator for classpaths is : and not ; (almost certainly for exactly this reason).
In other words: instead of
export CLASSPATH=$projectLocation/bin;$projectLocation/lib/*
you need
export CLASSPATH=$projectLocation/bin:$projectLocation/lib/*
As a bonus suggestion: the /* in the CLASSPATH should be interpreted by Java and not the shell, so it's better to actually quote the value:
export CLASSPATH="$projectLocation/bin:$projectLocation/lib/*"
I want to run a .sh file named ubiqstart.sh. using java. Specifically, I just want to execute a java class when running this .sh file. But I keep getting this error: Error: Could not find or load main class com.ubiq.update.MainEntry. Seems like the system is not able to locate where the java class is at. However, when I directly type in and execute this command in terminal (under this exact directory), it runs perfectly.
The script I use in the .sh file is: "../java/bin/java" -cp "./*" com.ubiq.update.MainEntry.
I wonder what causes this conflict and what should I do to make my .sh file to do the same thing as directly running the script.
When you are using older editors like vim or nano, just simply add a space after your classpath, like: com.ubiq.update.MainEntry . Especially if you convert the script from windows' .bat to Linux .sh
I am sure this is a stupid question and it must have been asked by every java programmer before. But I cannot find a related question at all.
This talks about subdirectories but I don't have any subdirectories as they are all in the same directory as the java file and the directory I executed the command line from Executable jar file error
This solution gives me the same error as I am writing below: Java command line with external .jar
Others (I don't have links to) talk about Eclipse and other IDE but I am not using an IDE, just a Linux terminal.
I am trying to import a public jar file from http://www.hummeling.com/IF97. The downloaded jar file has been renamed to if97.jar.
I have a java file called steam.java with these commands inside the file:
'
import com.hummeling.if97.IF97;
IF97 H2O = new IF97(IF97.UnitSystem.ENGINEERING);
System.out.println("test H2O table PSpecificEnthalpy(1): "+H2O.specificEnthalpyPT(1,300));
System.out.println("test H2O table PSpecificEnthalpy(5): "+H2O.specificEnthalpyPT(5,300));
'
But I do not know how to run this file in the command line.
I successfully compiled by typing:
'javac -cp if97.jar ~/test/steam.java'
Now I have a file called steam.class
But when I execute it with:
'java steam -cp if97.jar'
or
'java steam -jar if97.jar'
I get error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/hummeling/if97/IF97
at steam.start(steam.java:364)
at steam.main(steam.java:341)
Caused by: java.lang.ClassNotFoundException: com.hummeling.if97.IF97
I am trying to execute this in Linux Ubuntu 16.04 using Terminal. Both the files (steam.java and if97.jar) are in the same Home directory where I execute the javac & java command on.
I believe (or I'm mistaken) that the problem is that java isn't able to find the jar file. But I don't know why.
Please advise, thank you in advance.
You need to specify the class name after the JVM options, because whatever coming after the class name are considered arguments for the class, not the JVM.
Try this:
'java -cp if97.jar steam'
I am trying to run a Java program by using jsvc.
I have installed it by
sudo apt-get install jsvc.
To find out a solution, I tried to read the Apache documentation about it (at https://commons.apache.org/proper/commons-daemon/jsvc.html). But this command:
./jsvc -cp commons-daemon.jar:my.jar MyClass
and this other:
./jsvc -cp my.jar MyClass
did not work (of course, I replace the terms by the name of my class etc.).
It gives me the error:
bash: ./jsvc: no such file or directory of this type
So I use jsvc without "./". And I saw here: How to start tomcat with jsvc? that I should use /usr/bin/jsvc
But an other problem is when I use
/usr/bin/jsvc -cp path/to/my/.jar path/to/my/class
nothing happens.
I try the link: How to convert a java program to daemon with jsvc?. But there is something I don’t understand: for the "CLASS =", have I to put a .Main file ? And do I have to put the extension name of the file (for the class and the .jar) ?
I decided to put the .java file which contains my main class (once I putted the .jar, then I didn’t). Then I copied the code, and when I write "esac" and pressed the enter key in the Ubuntu console, the console closed up, and then…nothing.
Has someone already encountered this ?
Are you sure your java installation is in /usr/java?
Beside this, in the second command there's the directory missing. You should do something like that:
export JAVA_HOME=path/to/java/home
./configure
If you don't know where your java installation is located, try this if you are on a mac/*nix, or this if you have windows.
My site is being hosted on a shared server so I don't have su access. I needed to run a piece of code with java but it's not available on the server. So I got a self-extracting version of java and put it on the server in my home directory. Then I gave executable permissions to java and I try running the code. I have to use relative paths when running the file because of the restrictions of the server.
Trying to run the java file ../java/bin/java -jar 'javafile.jar' gives me the following:
error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
I looked and libjli.so is located at ../java/lib/i386/jli/libjli.so. So I'm thinking that because I'm running java using a relative path it doesn't exactly know how to look for the other files. I'm hoping that if I can add absolute/path/to/java/bin to $PATH then this issue will be resolved.
So once I'm running my PHP, I can use dirname(__FILE__) to get the full path of my java bin directory. I've tried the following code:
exec('export PATH='.$bin_path.':$PATH', $output, $return);
print_r(array(getenv('PATH'), $output, $return));
Prints:
Array(
[0] => /usr/local/admin/bin:/usr/local/admin/bin/servers:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin,
[1] => Array(),
[2] => 0
)
So nothing was added to $PATH, no output was given, and the command returned a successful exit value. Is it just the restriction of the server that is preventing me from getting this working?
Firstly, this is not going to work.
exec('export PATH='.$bin_path.':$PATH', $output, $return);
It will launch a child process with a shell, run the export command in the shell, and then the shell will exit. But the export command only changes $PATH for that shell.
I'm not sure, but I suspect that you need to use putenv.
I'm hoping that if I can add absolute/path/to/java/bin to $PATH then this issue will be resolved.
Well, it could only help if you used a simple command name for invoking the java command.
And it would be simpler to just run java using the full absolute pathname; e.g. "/absolute/path/to/java/bin/java"