extract run command from intellij idea - java

Hi I want to run a code on a remote server where IntelliJ Idea is not installed. My code needs a lot of classpath parameter which I handle that with IntelliJ Idea in my local computer. Now how can I export all running parameter and actually a something like:
$ java -cp ... Main.class ...
from Intellij Idea to use on remote server?
thanks.

Related

File not found exception when running with intellj

I'm trying to run my application through intellji so I can debug.
When I run this command from the terminal it works:
java -cp /Users/craigharley/code/IdeaProjects/decaf-CraigHarley/Skeleton/lib/antlr-4.6-complete.jar:Compiler.jar decaf.Main -target inter /Users/craigharley/code/IdeaProjects/decaf-CraigHarley/Skeleton/testdata/semantics/illegal-cust.dcf
But when I create a build using:
Edit Build Configs
New Application
Select the main class
Enter -cp /Users/craigharley/code/IdeaProjects/decaf-CraigHarley/Skeleton/lib/antlr-4.6-complete.jar:Compiler.jar decaf.Main -target inter /Users/craigharley/code/IdeaProjects/decaf-CraigHarley/Skeleton/testdata/semantics/illegal-cust.dcf as the program arguments I get a file not found on the /Users/craigharley/code/IdeaProjects/decaf-CraigHarley/Skeleton/lib/antlr-4.6-complete.jar:Compiler.jar, anyone know why this is?
I assume it's because of the :Compiler.jar, I don't java much so could somebody explain this to me.
Thanks

Why exec-maven-plugin fails while java console command works?

This problem has arisen while working with the Java Chromium Embedded Framework (JCEF).
The JCEF uses a native SO library (libcef.so) and a SO library for the JNI bindings (libjcef.so). I believe the embedded Chromium looks for a file named icudtl.dat next to it, i.e. in the same directory that the libraries reside.
For the following explanation, asume that all those required files are in the same directory, named jcef_libs.
I wrote a test application using JCEF. After compiling, if I execute it with the java command, i.e.
$ export LD_LIBRARY_PATH=/path/to/jcef_libs
$ java -cp src/main/java:/path/to/maven/repo/jcef.jar:/path/to/maven/repo/jogl-all/2.2.4/*:/path/to/maven/repo/gluegen-rt/2.2.4/* tests.simple.MainFrame
it works flawlessly.
On the other hand, using the exec-maven-plugin raises a fatal error, due to not finding the named icudtl.dat file. The POM file is configured to use exactly the same artifacts as the java command does.
$ mvn exec:java -Dexec.mainClass="tests.simple.MainFrame"
[1201/123038:FATAL:content_main_runner.cc(721)] Check failed: base::i18n::InitializeICU().
I have tested the java command with the icudtl.dat file removed from the jcef_libs directory, experiencing the same error, i.e. the error raises only when the icudtl.dat is not found.
Any help will be appreciated.
UPDATE
I have been tracing what maven does under the hood. The failing mvn command above executes this internally:
java -classpath /usr/share/maven2/boot/classworlds.jar -Dclassworlds.conf=/usr/share/maven2/bin/m2.conf -Dmaven.home=/usr/share/maven2 org.codehaus.classworlds.Launcher "exec:java" "-Dexec.mainClass=tests.simple.MainFrame"
I.e. it executes my test application through a launcher. I don't know where this launcher is going to execute my application but, again, I need the icudtl.dat in that directory.
Any idea how could I workaround this?

Cannot run program "adb" from IntelliJ plugin

My problem is that I want to run shell command from Java code (my IntelliJ plugin):
Runtime.getRuntime().exec("adb devices")
But then I receive IOException:
Cannot run program "adb": error=2, No such file or directory.
What is odd is that when I run it on debug mode it works, it's broken only when I deploy my plugin to real IntelliJ. The command also works from any terminal.
The only thing which works now it typing the command with full path:
/Users/adamstyrc/utils/adb
But it's not a solution. How to fix it ? My guess would be to manually load bash PATH variable add adb exec file to project but it's not elegant solution. Thanks in advance!
You need to be sure that the correct path settings are passed to IntelliJ.
If you for example modified the path settings, or if you ran intellij from a different terminal or user, then they might not be correct.
To be sure, close down IntelliJ, start a new terminal - then verify the path settings - and start IntelliJ manually from that terminal.
If you are running a 64 bit machine, try installing 32-bit libraries using
apt-get install ia32-libs

Compiling and running java application using powershell

I am trying to compile and a sample Helloworld.java file.
I have my jdk installed in C:\Program Files\jdk1.7\bin.
And I have my Helloworld.java in C:\Helloworld.java
I am actually a novice in both powershell and java.
I got some examples from web regarding this but many of them advice to run it like this:
java.exe -classpath $Env:CLASSPATH C:\Helloworld.java
But when I give this in powershell I get an error called 'CLASSPATH' is not defined even after adding it in env variables.
And when I try to compile the code with the following syntax:
$javac C:\Helloworld.java I get an error "javac is not recognised as a token".
So, I am literally lost in this topic . Any step by step procedure to run java programs using powershell for dummies like me will be greatly appreciated.
Setup environment variables in your system.
set JAVA_HOME to C:\Program Files\jdk1.7
add to PATH variable the string %JAVA_HOME%\bin
open new cmd session.
navigate your java source folder.
use javac to compile your java files.
UPDATE:
also if you are experiencing difficulities upon launching an executable via PowerShell check this Microsoft TechNet article
The variables you speak of do not exist in PowerShell as you name them.
The correct variable names are
$Env:JAVA_HOME: C:\jdk1.6.0;
$Env:PATH: C:\jdk1.6.0\bin;.;
$Env:CLASSPATH: C:\jdk1.6.0\lib;.;
As they all must be defined in the ENV: PSDrive
To answer it in a much simpler way , its the path problem .
You probably not have set env variables that's it.
This is how you should set it:
JAVA_HOME: C:\jdk1.6.0;
PATH: C:\jdk1.6.0\bin;.;
CLASSPATH: C:\jdk1.6.0\lib;.;
And later if you open a cmd prompt and type java -version , if you are able to see the java installed version then you are good to go.

Unable to execute .jar file

I'm having a problem with running .jar files. Here's what I've observed:
running executable .jar by doubleclicking doesn't do anything, not even start a process
running it from cmd by typing javaw myfile.jar doesn't do anything as well, I've redirected STDERR but it doesn't say anything
because of school requirements I'm developing in BlueJ, when I run my code directly from this IDE, it works and starts processes like java.exe or javaw.exe
when I try to compile my console program from cmd and then run it by java myclass, it works
I'm working on Windows 7 Professional with Java SE 7u51 JDK installed. I've already tried to uninstall anything that had "java" in its name and then install only JDK or only JRE. I've also tried to run jarfix or manually delete all .jar associations in registry. I've added my JRE path to other system variables. Nothing has worked for me.
Please do you have any idea what to try next? Thank you.
Resolved:
Thanks to the answers I've managed to resolve the problem with doubleclicking as well. I've just had to:
set the JAVA_HOME variable
restart the computer
run jarfix
Couple of quick solutions:
Use java -jar <jar-file-name>
Note: This will be useful if your jar is Runnable
Use java -cp <jar-file-name> main-class-name
Note: Specify the entry point with the class-name to start execution.

Categories