Java executable doesn't start - java

I'm having a frustrating issue with a java program I have been working on. I have not had this issue often in the past and I have actually created many versions using this same code and had no problems.
Suddenly, executable JARs of this program will not start. I have tried running them through the command prompt with Java and I get message about the main class not being found.
I have done a search here and none of the answers work for me. I have tried the following:
Removing the system library in the build path settings and adding it back. (The system library is [jre1.8.0_66]).
Changing the compliance settings from 1.7 to 1.6. I don't have an option for 1.8 and the JDK check box that says "Use compliance from execution environment on Java Build Path" is disabled.
Removing the main class and adding it back.
Using the package and export options for libraries.
I'm really not sure what else to do. I've tried doing a rebuild on the project many times and also tried restarting eclipse and re-exporting. I'm certain that I am selecting the main class when in the export preferences.
Any help or suggestions would be greatly appreciated as this has become very frustrating.

From the comments, it seems to me that you are not executing your JAR correctly. As stated in the comments, you are executing your JAR with java {jarname}. This syntax would only work with running a compiled Java class with a main method. To run a JAR, use:
java -jar {jarname}

Related

Why does any collection object not recognized? (VSCode) [duplicate]

Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage

Problem wrapping .java to .exe using Launch4J but problem is likely version compliance

I have a problem trying to wrap a java .jar as .exe and feel like I have checked out all there was on here which was remotely related. But I still couldn't get it to work. All the questions I found which seemed similar only concerned a part of my problem and also, the solution didn't work for me (such as this Convert .jar to .exe using launch4j or this The compiler compliance specified is 1.6 but a JRE 1.8 is used and many more).
The Problem
So, in my concrete case, I need to wrap a small program to a Windows .exe for an elderly person to use (I can't expect them to run a .jar file themselves). I'm trying to get everything to run on 1.0.8, so that's Java 8.
The errors I get are, on the one hand, that the resulting .exe doesn't work, throwing a class error (indicating that there's a problem with the compiler compliance) when trying to run it.
Later on, trying around, I also got a compiler compliance warning in Eclipse, so that's likely the problem.
Then I also get an error concerning module-info.java. Just deleting the contents of the file seems to help (in terms of Eclipse warnings) but the final result also doesn't work.
I saw that you need Java 9 to use module-info.java. What do I have to do with this? I couldn't find any helpful answers on here (or maybe I didn't understand them).
What I've tried
I have both the JDK and JRE installed (enviroment var set to JRE). I tried a clean and rebuild (like suggested in a question I can't find anymore) but it didn't do anything.
I am not so famililar with Java and usually use Linux, so Windows problems are not so familiar to me. I have found myself a Windows machine to compile my program from (because there seem to have been Java version problems when using Launch4J under Linux, trying to get an .exe.)
Edit: If one of you can help me solve my problem under Linux, that would be my favourite kind of solution. I currently use Linux Mint 20 but I also have Ubuntu installed on a machine I can access.
In the end, I think my Launch4J problem is actually a pre-existing problem of my .jar file stemming from the errors outlined above which I'll sum up again below:
I have been trying around for ages but I always get
The warning: The compiler compliance specified is 1.8 but a JRE 14 is used
The error: Syntax error on token "module", interface expected
I think that I should have fixed the compliance (both in Build Path and Compiler in the Properties) but it still doesn't work and it seems I've tried all there is. The environment variable is set and all. (There also isn't a javac.exe in my folder in case that makes a difference? Someone said to download it again but it doesn't help. Also, I've tried it on the customer's computer. They had a javac.exe and the whole thing still didn't work altough throwing different errors.)
Contents of module-info.java
Regarding the module, as the asker of this question ("Syntax error on token "module", interface expected") has nothing but
module NameOfMyThingy {
}
Maybe some of you can help - would appreciate it!
Thanks!
Rather than using launch4j, I recommend that you take a look at jpackage, which is available in JDK 14 and 15. See Packaging Tool User's Guide. Note that for Windows you will also need to download the WiX toolset.

Visual Studio Code - Java - Import Errors and More

Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage

Thinking in java library installation

Hi i've been trying to install the library on Thinking in Java book 4th edition and i hit a very thick brick wall. I've done everything that the guide from the website told me to do and i still can't get the library to work. From what i've read it seems that the problem is from the build.xml files. having no xml knowledge I am clueless about how I have to modify it in order for it to work. In both cmd and eclipse I am getting these error
c:\TIJ4\code\build.xml
Build Failed
c:\TIJ4\code\build.xml:59:J2SE5 required
Can anyone tell me what I should do ?
I am using eclipse if there is a simpler solution by using eclipse rather than ant please help me out. It's been a week now and I still can't make it work.
The important thing to do is to realize that your ant file has a specific java requirement.
Something to try that might fix this very easily : I believe you can remove any references to a specific JDK, and if you have a reasonably up to date JDK, the build will succeed.
The definete fix : Look into the exact (line 59) of your build file, and try to satisfy the java version that line requires. Java is generally backwords compatible -- something designed to run in J2SE5 should run in the latest JDK. Its not terribly difficult to update your JDK (just google for instructions on your OS).
The most common mistake I see is that people who have the java run time installed believe they also have the Java SDK as well.
Does this "install the library" means you want to look at the code and run them in your eclipse? If so I can share my experience with you.
First run the Eclipse.py script; this will add package info to the source code
Create a new Java project in Eclipse, and then just copy all the source code folders to the src source folder in eclipse, these folders will then be recognized as Java packages.
You should be able to run the classes with a main function.
You can also configure which java version to use for this project in Eclipse build path. 1.5 or higher will work.

Attempting to export/deploy an Eclipse plugin I created, Eclipse complains of bad ANT classpath

I've developed an Eclipse (3.5) plugin for my employer (a university) using Graphical Editing Framework (GEF).
Deploying the app should be as simple as pressing the "Export Wizard" link and entering an archive name and hitting "Finish" (shown in the images below).
But then I encounter the an error dialog protesting "Could not find one or more classes: "org.apache.tools.ant.launch.AntMain". Please check the Ant classpath."
But I've looked inside the Eclipse>Preferences>Ant>Runtime>ClassPath and found everything to be in order.
What's wrong? How do I set the class path so I can deploy my plugin.
UPDATE:
I'm using Mac OSX Leopard for development.
I also correct the ANT_HOME settings in preferences>Ant>Runtime>ClassPath to /Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145 as others have suggested
The Export Wizard Link http://img199.imageshack.us/img199/5766/picture4ro.png
The Export Wizard http://img134.imageshack.us/img134/9534/picture5gf.png
It does not seem to be related to eclipse 3.5 (it has been reported with eclipse3.2 or 3.1.2).
In one case, it was because the build was using:
-Djava.endorsed.dirs
which happened to point on an old Ant version.
Another said its Ant->Runtime / "Ant Home" was erroneously set to the current project dir.
setting it to /usr/share/ant makes ant work properly. (But you said that "eveything was in order" there).
A third had to manually add
/usr/lib/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-launcher.jar
to the Ant classpath in the preferences to make it work.
It all boils dow to an older version of Ant being somehow referenced.
I tried for far too long to solve this problem, so I resorted to the good ol` truism, "Java hates OSX" and decided to try the whole process on Vista... and BAM! worked first time, no issues.
So, the answer to my question is "Don't use OSX, use Windows or Linux".
I'm not a jerk so I posted this platform bug in Eclipse bugzilla.
VonC was indeed awesome enough to give me really good advise and point to other bugs I couldn't find.. he deserves more votes..

Categories