When I try to build my project using ant, I get:
"java.lang.NoClassDefFoundError: sun/org/mozilla/javascript/internal/Scriptable"
This stems from my usage of Rhino (the bundled java-script that comes with Oracle JDK)
When I build the project with eclipse, everything works fine.
The ant file I am using was generated by eclipse, and works fine except for the java-script dependencies.
These dependencies are located in the RT.jar that comes with the oracle JDK.
I have tried both jdk6_0_u41 and jdk7, and both give the same results: success in eclipse, fail with ant.
I have tried to build on both ubuntu 10, and 12
I have seen two other suggestions which seem unacceptible to me:
One thread suggested copying RT.jar into the project lib directory. (RT is entire java runtime! )
Another thread suggested that I shouldn't use:sun/org/mozilla/javascript/internal. But since I am doing advanced manipulation (Calling object methods, registering callbacks, etc) I see no alternative to using the sun.org.mozilla.javascript.internal family of classes.
A comment from Oracle's site:
Users should not write code that depends on internal JDK implementation classes. Such classes are internal implementation
details of the JDK and subject to change without notice.
This is not a compiler issue. javac is behaving correctly, according
to the information provided in ct.sym.
The issue belongs with those who decide what should be available with
(and what should be hidden by) ct.sym
You may suggest to include Rhino's jar to your project and repoint it on original's Rhino classes where 'internals' are not hidden from users
Related
In a Java project I have a dependency on my own library. I have installed this library in the local repository by running mvn install in the root of the library's directory.
When I updated the library and re-installed it, VS Code couldn't see a newly-added method (everything compiles fine from the command-line).
I've tried Java: Force Java Compilation (full) and that didn't work.
In pom.xml I right-clicked on my library and chose Update Project and that didn't help either.
If it makes any difference, I am running on WSL2 (Ubuntu-20.04) on Windows 10.
Is there any solution short of restarting VS Code (which is a rather cumbersome workaround)?
Executing the Java: Clean Java Language Server Workspace command from the Command Palette (Ctrl+Shift+P) should work.
If you added new dependencies or jars, java language server will build and compile them automatically.
In some rare cases, you may need to execute the above command to let the language server rebuild your dependencies.
Reference: Library Configuration
I am trying to use a library called Journey browser which uses the Java Chromium Embedded Framework. I first created a Java Maven Project with Netbeans and I edited the pom.xml to match the values on the library's guide, which is here: https://github.com/CodeBrig/Journey, to add the maven dependencies. (No errors detected by Netbeans) I then built the project to download the maven dependency and put their default code (modified slightly) in the main class. Netbeans found no errors in the code. However, when I run the project I get a "no chrome_elf in java.library.path". I think this has something to do with embedding JCEF, but I am not sure how to add this to the "java.library.path" in Netbeans.
How do I fix this "chrome_elf" problem?
Also, if I am able to fix this will it be an error for production if someone doesn't have "chrome_elf" installed?
For Windows
This happens because the chrome_elf.dll (on Windows) file cannot be found.
Java is looking for this file on java.library.path - which (on my machine, anyway) refers to all the locations referenced by the Windows %path% environment variable.
One way to fix this is to download one of the pre-built distributions from that GitHub page (for example the Windows one, referred to here):
https://github.com/CodeBrig/Journey/releases/download/0.4.0-78-assets/jcef-distrib-windows64.zip
Then unzip the resulting jcef-distrib-windows64.zip. In the win64\bin\lib\win64 directory under that main directory you will find the chrome_elf.dll you need - and other binaries which are also needed.
Add this directory to your path - either by adding it to the Windows environment variable or via java -Djava.library.path=....
For example, the path may be similar to this:
C:\your\path\to\jcef-distrib-windows64\win64\bin\lib\win64
This should allow you to run the demo code provided in the JourneyBrowser class. A browser window should open as a result.
Here is the browser:
The above steps worked for me - and the only files I needed to keep from the (large) distribution download were those in the jcef-distrib-windows64\win64\bin\lib\win64 directory. It's possible that I already have some other dependencies which may be needed - so I cannot guarantee this process will also work for you.
For Linux (and MacOS)
I have not tried this on a Linux machine. But in that case, I believe you will need to download and unzip the jcef-distrib-linux64 release - and then point to the jcef-distrib-linux64\linux64\bin\lib\linux64 directory, containing libcef.so and other libraries.
Similarly for MacOS, there is a distribution which can be downloaded and unzipped.
Alternative
An alternative is to simply use the pre-built distributions provided on GitHub, using the commands provided. Obviously, in this case, you will not be creating your own customized implementation (so, no JourneyBrowser class).
copy scr/native/Release to jcef_build/native/Release from the default output directory of VS.check whether the Release exists in java.lib.path
Started coding in java , just wanted to see the implementation of classes and interfaces we actually import to use their methods.
Ex:
import java.util.Scanner;
I am curious to see what's inside the class Scanner(){}
Is that possible?
Tried Searching but couldn't find the implementation and definitely did not understand how they hide them from public.
Please follow the following Steps to See Java predefined classes implementation
1) Get rt.jar (It contains all Core Java API Classes which required for JRE at Runtime)
Download it from the internet directly or Search it in JDK at Path like C:\Program Files\Java\jdk1.8.0_181\jre\lib and copy it to other location on your Desktop
2) Extract the copy of rt.jar
Extracting .jar file with command line
https://www.wikihow.com/Extract-a-JAR-File
After extracting you can see all the Core Java Classes in .class file (cant read it Directly) which we use normally in our programs
3) Download tools like cavaj java decompiler to open and read .class file
You Can see any code in Any jar with this approach... Its very smart way to understand basics of java with fun ..
There is nothing "hidden from public" concerning java.util.Scanner.
#shmosel already linked to the source of it, #Stultuske pointed out, that there are various websites covering source code of java.
Modern IDEs also allow you to view into source for your libraries (aka .jar files).
My Netbeans IDE shows source from known jar files whenever I ctrl-click on a class.
Same goes with Eclipse, IntelliJ, ...
For a lot of open-source libraries (e.g. from Apache) there is also source code available. Just by cloning the version control repository, downloading source packages (zip, ...-source.jar) or browsing the version control repository online.
If project is buildable with maven, the IDE can even download and show sources for open source project automatically.
I have an application that works fine and that I can execute from a .jar file. But I want to know how to make it runnable from any computer even if there is no JRE or the JRE version is not the good one. I thought about a .exe file but don't know how to do it.
I made my code with Eclipse and it use jxl,jdom and jfx librairies.
I tried to use Inno Setup 5.5.6 but when in Eclipse I run my build.xml as Ant Build it return me an error that says :
"'Launching JFX Build - Myapp' has encountered a problem.
The achive : C:/Program%20Files/eclipse/plugins/org.eclipse.swt.win32.win32.x86_64_3.104.0.v20150528.jar which is referenced by classpath, does not exist."
JavaFX provides specific utilities for bundling your application as a native package, which is referred to as "Self contained application packaging". These utilities are provided as a command-line tool, or as ant tasks. Additionally, the common IDEs support this via wizards, either out of the box (NetBeans) or via a plugin (e(fx)clipse for Eclipse). The details of how to use any of these are far beyond the scope of a stack overflow question, but the basic documentation is available here. A tutorial for e(fx)clipse is here.
Briefly, for e(fx)clipse, you should double-click the build.fxbuild file that is created in your project. Under the "Overview" tab, find the "Packaging format" option, and select "All" (or the specific type of package you want to create).
Note that you can only create a package targeted at the platform on which you are building, so if you want to create packages for windows, Mac, and Linux, you will need access to all three types of machine.
I know I am late. I faced same problem a trick worked for me. Look at the given directory in the error message. It contains a space (C:/Program Files/...). Move your e(fx)clipse to another directory where the directory doesn't contains any space.
Not sure it will work your everyone or not but it worked for me.
Thanks
There are various tools that let you wrap your Java application in a Windows executable. Some tools are only simple installers, others allow you to bundle your application with a specific JRE version.
A widely used but commercial tool is install4j, but there is a bunch of other tools, such as WinRun4J.
This is the third time I've installed it. I had it working on Windows, and up until a few days ago on Linux. I've done all I can do and I don't understand how to run this Java program.
The source code is a folder with a lib, src some jars and a classpath and project file.
The classpath file makes some declarations like classpathentry=src/main and path=lib, path=src.
All of these make sense. There is a folder 'main' inside 'src'.
The tiny file I'm trying to run starts off by
import de.l3s.boilerpipe.demo
I'm trying to run 'Oneliner.java'. I cannot compile it.
No matter what/where that class file is, I cannot run it. It results in a noclassdeffound.
I've run it in the main, the src, the root, the demo, the ... anywhere.
I've tried compiling it in different directories, running it with various java command line switches that were recommended. Supposedly you can have it 'search' for the file, which I've yet to experience. The sheer stubbornness of this java environment is terrifying. And massively humiliating for me.
I had the same problem with installing it. The 'Getting Started' page is poor quality.
My solution was to use a python wrapper, which you can find here: https://github.com/misja/python-boilerpipe
It takes care of all of the dependencies you'll need (however, you might be missing jpype if you're on a Mac. In that case, you'll need to install it manually from: http://jpype.sourceforge.net/).
The best way to start using the boilerpipe algorithm (and to see what it is for) is to use the demo site:
http://boilerpipe-web.appspot.com/
If you want to integrate the boilerpipe library into your applications, or even intent to modify/improve the code, you will definitely need solid Java programming skills.
As a quick-start I suggest that you install a recent version of the Eclipse IDE for Java Developers and import boilerpipe-core as a project. This avoids pretty much of the classpath configuration, and almost everything should be set up correctly for you.
The classpath file you mentioned is probably ".classpath", which is part of the Eclipse project configuration. You don't need it unless you want an Eclipse project.