Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I made a project and named the class the same as the file name. Let say I saved the project and wanted to run it. How do I do this through emacs? I also have jdk installed.
I have a few hacks left over from when I was trying out Java.
This one is for the simplest programs consisting from a single file:
(defun java-eval-nofocus ()
"run current program (that requires no input)"
(interactive)
(let* ((source (file-name-nondirectory buffer-file-name))
(out (file-name-sans-extension source))
(class (concat out ".class")))
(save-buffer)
(shell-command (format "rm -f %s && javac %s" class source))
(if (file-exists-p class)
(shell-command (format "java %s" out) "*scratch*")
(progn
(set (make-local-variable 'compile-command)
(format "javac %s" source))
(command-execute 'compile)))))
This one is for an ant-controlled project:
(defun ant-compile ()
"Traveling up the path, find build.xml file and run compile"
(interactive)
(save-buffer)
(with-temp-buffer
(while (and (not (file-exists-p "build.xml"))
(not (equal "/" default-directory)))
(cd ".."))
(set (make-local-variable 'compile-command)
"ant -emacs")
(call-interactively 'compile)))
Some equivalent of these you can probably find in JDEE
I you can set it up (which I couldn't).
And here are the key bindings I have:
(define-key java-mode-map [C-f5] 'java-eval-nofocus)
(define-key java-mode-map [f5] 'ant-compile)
You'll have to have a version of emacs that has some feature to launch separate applications. From there, you pass the command to launch the JVM (e.g. java MyClass)
If you are developing a web application, your server may be able to dynamically load classes as they change -- it depends on many factors. If you are developing under that type of environment, then you only need to compile your Java code for the changes to be reflected on the server (assuming the server does dynamic class loading and it works for your development environment -- I've worked on many projects where it doesn't).
You should perhaps install and test out this:
http://www.emacswiki.org/emacs/JavaDevelopmentEnvironment
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I was just trying to compile my java code then I did this in the cmd:
chdir C:\All_files (my directory)
javac Hello.java
then when I did this:
java Hello
오류: 기본 클래스 hello을(를) 찾거나 로드할 수 없습니다.
(Error: cannot find class hello)
then I did this:
javac myclass
then it worked.
How do I fix that?
Here is my code:
public class Hello
{
public static void main(String[] args) {
System.out.println("Hello Windows 10");
}
}
I want to know how do I make javac produce the right title for the compiled class.
What do you want to fix?
First you compiled your source file with javac Hello.java...
Then you tried to run it with java Hello...
However the command java requires a fully qualified class name. What you supplied (Hello) seems to me, like the name of he .class file, without extension.
When you tried with java myclass, it worked, because it is the fully qualified class name of your class...
See: java and javaw reference
This question is related to a previous question, here: Java Runtime.getRuntime().exec() appears to be overwriting $PATH
I am trying to build Go from source from inside a Java program. I can build it properly using Terminal, but Java's Runtime.getRuntime().exec() gets interesting results. I tried using ProcessBuilder, but could not get it to properly make Go. Using my current setup with exec(), it makes properly, but then fails two tests. Code snippet:
String[] envp = new String[4];
envp[0] = "CC=/usr/bin/clang";
envp[1] = "GOROOT_BOOTSTRAP=/usr/local/go";
envp[2] = "CGO_ENABLED=0";
envp[3] = "PATH=" + System.getenv().get("PATH");
Runtime.getRuntime().exec("./all.bash", envp, "$HOME/Desktop/go/src");
It runs properly and compiles properly, but when it gets to running the test suite, I get two errors:
--- FAIL: TestCurrent (0.00s)
user_test.go:24: Current: user: Current not implemented on darwin/amd64 (got &user.User{Uid:"502", Gid:"20", Username:"", Name:"", HomeDir:""})
FAIL
FAIL os/user 0.009s
and a much longer one that I won't paste here due to absurd length, but it comes down to:
panic: test timed out after 3m0s
...
FAIL runtime 180.056s
I haven't any idea why the former is failing, but for the runtime when I build from the Terminal, it says:
ok runtime 19.096s
So something is causing that to take absurd amounts of time. I did some googling, and heard that it might be fixed if I use ARM=5 as an environment variable, but that didn't change anything. Does anyone have any idea why these tests are failing when I build from Java as opposed to the Terminal?
Looking at the source code for the os/user package, it looks like the native user handling depends on having cgo enabled. If cgo=0 (your case), it will fall back to the USER and HOME environment variables.
source code in question
Try putting USER=whatever in your exec environment.
I'm afraid I'd need more information to diagnose the runtime issue.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a program in which the properties file is in the same path as the program I'd like to run.
The properties file name is initialized at the start of the program with:
public static final String DEFAULT_PROPERTIES_FILE = "defaultProperties.properties";
The program runs perfectly when running it in the directory it itself is located in with:
java -jar program.jar
When running the program from another directory with:
java -jar path/program.jar
The program will not find the properties file and returns a:
java.io.FileNotFoundException: defaultProperties.properties (No such file or directory)
FIXED
I came up with a solution. It is possible to call the path of the class and give the path to the configurations file.
StringBuilder stringBuilder = new StringBuilder( PolicyBoosterTool.class.getProtectionDomain().getCodeSource().getLocation().getPath() );
String pathToFolderOfJarFile = stringBuilder.substring( 0, stringBuilder.lastIndexOf( "/" ) + 1);
DEFAULT_PROPERTIES_FILE = pathToFolderOfJarFile + "defaultProperties.properties";
Sadly I can't mark the case as solved for myself. Any improvements to this are always welcome. Thank you for your help everyone!
You have to specify the complete path of the property files. If you don't specify the path, then it will try to find file in same directory from which you started the jar. Hence FileNotFoundException.
One simple solution is - define property file's path as command line argument.
One way, to keep your properties file at any arbitrary location and make your application read it, is using VM params
for example:
Pass a VM Param say prop.path
java -Dprop.path=path/to/your/properties/file -jar path/program.jar
Then you can read it with
System.getProperty("prop.path")
Hope this helps.
I am trying to install Matlab on a Linux machine, but setting LD_LIBRARY_PATH (as the installation requires) breaks other library files. I am not an Linux expert, but I have tried several things and cannot get it working correctly. I have even contacted Matlab support, got the issue elevated to the dev team, and was basically told "haha sucks to suck". I have seen a few other people online have had the same issue, but either their questions were never answered or they had a slightly different problem and their solution didn't apply to me.
Installing on a VM running Ubuntu:
I set LD_LIBRARY_PATH as the instructions say, then it breaks network files. I can ping google.com, but I cannot nslookup google.com or visit it in a browser. Nslookup provides this error:
nslookup: /usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64/libcrypto.so.1.0.0: no version information available (required by /usr/lib/libdns.so.100)
03-Feb-2016 11:32:22.361 ENGINE_by_id failed (crypto failure)
03-Feb-2016 11:32:22.362 error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
03-Feb-2016 11:32:22.363 error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:447:
03-Feb-2016 11:32:22.363 error:2606A074:engine routines:ENGINE_by_id:no such engine:eng_list.c:418:id=gost
(null): dst_lib_init: crypto failure
The installation worked though (I can run my Java programs that reference compiled Matlab functions). Unsetting LD_LIBRARY_PATH fixes the network files but then I can't run programs anymore.
Installing on EC2 instance:
On an EC2 instance it does not break the network files (nslookup is fine). Instead it messes up Python library files. Trying to use any aws cli command, I get the error:
File "/usr/bin/aws", line 19, in <module>
import awscli.clidriver
File "/usr/lib/python2.7/dist-packages/awscli/clidriver.py", line 16, in <module>
import botocore.session
File "/usr/lib/python2.7/dist-packages/botocore/session.py", line 25, in <module>
import botocore.config
File "/usr/lib/python2.7/dist-packages/botocore/config.py", line 18, in <module>
from botocore.compat import six
File "/usr/lib/python2.7/dist-packages/botocore/compat.py", line 139, in <module>
import xml.etree.cElementTree
File "/usr/lib64/python2.7/xml/etree/cElementTree.py", line 3, in <module>
from _elementtree import *
ImportError: PyCapsule_Import could not import module "pyexpat"
Printing sys.path in Python shows lib-dynload is already there though, so it doesn't seem to the problem.
And when trying to run the program, I get:
Exception in thread "main" java.lang.LinkageError: libXt.so.6: cannot open shared object file: No such file or directory
at com.mathworks.toolbox.javabuilder.internal.DynamicLibraryUtils.dlopen(Native Method)
at com.mathworks.toolbox.javabuilder.internal.DynamicLibraryUtils.loadLibraryAndBindNativeMethods(DynamicLibraryUtils.java:134)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1529)
at VectorAddExample.VectorAddExampleMCRFactory.newInstance(VectorAddExampleMCRFactory.java:48)
at VectorAddExample.VectorAddExampleMCRFactory.newInstance(VectorAddExampleMCRFactory.java:59)
at VectorAddExample.VectorAddClass.<init>(VectorAddClass.java:62)
at com.mypackage.Example.main(Example.java:13)
I'm at a brick wall and really have no clue how to proceed.
Maybe something else already needs LD_LIBRARY_PATH set to work. Make sure you prepend not overwrite:
export LD_LIBRARY_PATH=new/path:$LD_LIBRARY_PATH
Edit:
OK, if LD_LIBRARY_PATH was initially empty, this suggests that Matlab comes with shared libraries that are incompatible with your system ones:
nslookup: /usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64/libcrypto.so.1.0.0: no version information available (required by /usr/lib/libdns.so.100)
suggests that /usr/lib/libdns.so.100 needs libcrypto.so.1.0.0, which is now being resolved to the one that comes with MATLAB, which is incompatible.
You can check the dependencies of a dll by
ldd /usr/lib/libcrypto.so.1.0.0
and hopefully you can find a configuration that keeps both MATLAB and your system happy. Unfortunately, this may involve a lot of trial and error.
If there is no such configuration, you can try setting LD_LIBRARY_PATH only when you run MATLAB:
LD_LIBRARY_PATH=$MATLAB_LD_LIBRARY_PATH matlab
Edit 2:
Well, for the Python issue, it seems to boil down to pyexpat, which is a wrapper around the standard expat XML parser. Try doing (name guessed since I don't have a Linux right now):
ldd /usr/local/lib/python2.7/site-packages/libpyexpat.so
and see what that depends on. Probably, it will be libexpat.so, which is now being resolved to MATLAB's version.
try the following command:
export LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:$LD_LIBRARY_PATH
Perhaps not helpful for OP but if you are generating a python package with MATLAB, you could modify the generated __init__.py file MATLAB creates for your package.
Specifically, the generated __init__.py file contains the following line (as of MATLAB 2017a):
PLATFORM_DICT = {'Windows': ['PATH','dll',''], 'Linux': ['LD_LIBRARY_PATH','so','libmw'], 'Darwin': ['DYMCR_LIBRARY_PATH','dylib','libmw']}
For Linux platform, you could simply replace LD_LIBRARY_PATH with something else such as MCR_LIBRARY_PATH to prevent mucking with your shared libs.
sed -i -e 's/LD_LIBRARY_PATH/MCR_LIBRARY_PATH/g' /MY/PACKAGE/BUILD/PATH/__init__.py
Then obviously export MCR_LIBRARY_PATH before using python.
I'm just starting using JRuby and when I test following code saved as a script
include java_import
frame = javax.swing.JFrame.new
frame.getContentPane.add javax.swing.JLabel.new('Hello, World!')
frame.setDefaultCloseOperation javax.swing.JFrame::EXIT_ON_CLOSE
frame.pack
frame.set_visible true
I get the following error
Switch to inspect mode.
irb(main):001:0> include java_import
TypeError: wrong argument type Array (expected Module)
from org/jruby/RubyModule.java:2068:in `include'
from (irb):1:in `evaluate'
from org/jruby/RubyKernel.java:1066:in `eval'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1174:in `catch'
from org/jruby/RubyKernel.java:1174:in `catch'
from C:\jruby-1.7.2\/bin/jirb_swing:54:in `(root)'
irb(main):002:0>
Can someone help me identify what I'm doing wrong? I have jruby-1.7.2 installed (C:\jruby-1.7.2), added to the PATH in system variables, and running on Windows 7. At the command prompt, I can test jruby and java version correctly
I also launched the jirb_swing via jruby(1.9.3).exe and at the prompt typed
irb(main):001:0> include java_import
and I get the same error message
Update
Hi All
After searching further on the Internet pages on JRuby and Java, I have resolved the problem successfully.
First the two ways that worked for me in calling Java from JRuby:
Using "include Java" (without the quotes in my script file and with capital J)
Using "require 'java'" (without the " quotes and notice the single quotes around java, now starting with lower-cap j)
The "java_import" I was using was an error on my part in being careless as I read the detailed document at GitHub (https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby)
I will research more about the differences or lack thereof in using the "include" vs. "require" statements and post back. As a real novice, this has been a real eye opener
Sri