I'm a long time reader, first time poster.
I use Netbeans to develop a Java application to run some simulations in regard to Project Management. Now the program is finished, I want to make a JAR file of it so other team members can use it without installing Netbeans. Normally I just press "build and clean" to make a JAR file but this trick ain't working this time. When I run the JAR file everything works fine until I press the button to start the simulations. Next error is given on the command line in cmd:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: optimizat
ion/Lmder_fcn
at umontreal.iro.lecuyer.randvar.BetaGen.nextDouble(BetaGen.java:109)
at Scheduling.SimulationEngine.randomizeDurations(SimulationEngine.java:
122)
at Scheduling.SimulationEngine.simulateNew(SimulationEngine.java:73)
at IO.FileReader_GUI$GUIEventHandler.actionPerformed(FileReader_GUI.java
... blablabla
Point given is that the umontreal.iro.lecuyer.randvar.BetaGen.nextDouble() method is a static method used from a JAR file I added to my project. In Netbeans it doesn't bring any problems but it does when I use run it 'stand-alone' without Netbeans.
Can somebody please give me a quick solution? Please keep in mind that I'm not a professional programmer. Do not hesitate to ask questions if you need more information!
It seems pretty clear that your JAR is not in the class path. Please read this tutorial, it should help you figure out your problem in your environment.
PATH and CLASSPATH (The Java™ Tutorials > Essential Classes > The Platform Environment)
Also, in the comments #Perception included a great link that might also help you, I want to make sure you see it.
Related
I am quite new to programming, so I have a lot of difficulties with things that may seem simple.
I work on an app that reads an Access database and lets the user search trough it. I am programming it with eclipse and javaFX.
When I run it with Eclipse it works fine, however I have tried to export it in a runnable JAR file to be able to run it on any computer, and when I try to run the JAR, nothing seems to happen.
I have added an argument :
--module-path "C:\Users\calon\OneDrive\Documents\Code\JavaFX\openjfx-17.0.2_windows-x64_bin-sdk\javafx-sdk-17.0.2\lib" --add-modules=javafx.controls,javafx.fxml, which from what I understood is not added to the JAR, so I have to add it when I want to run it. However this argument is relative to my file system and wont work on another computer. I don't know how I can change it to make it work for everyone.
Also, I have tried to convert it to Maven, and when I run it, it sends this message : Error occurred during initialization of boot layer java.lang.module.FindException: Module henriGaussenDataBase not found.
The project can is at https://github.com/Anthony-Calonne/HenriGaussen.git .
I don't know what to do to make it work, I have searched different ways to do it but did not understand everything I have read on this subject.
I installed Java & Eclipse and wanted to run the tutorial of the Hello World project.
As soon as I start with the first real step, creating a Java Project, I do everything alike the Tutorial, write the name "HelloWorld", finish.
Then a Window pops up, that wants me to create a new module-info.java. That is pretty strange, I have not seen anything like this in a Tutorial anywhere, but either way, if I create it or not, I get an error:
Errors occurred during the build.
Errors running builder 'Java Builder' on project 'HiWorld'.
java.lang.NullPointerException
Does anyone know something about this issue?
I have already tried to look in the Properties - Building Path, but when I add, remove, change something I do not get anywhere.
I had the idea that it could be a problem with my eclipse, but I reinstalled it twice already (Java as well) and I have not made any progress.
My code is just:
module helloworld {
}
I want to eliminate the error, so that later on my HelloWorld program is running.
Thank you for taking some time!
You don't mention the tutorial, but I imagine it's for below Java 9, of which module-info is part.
Go into Eclipse project settings and set language level to 8 (there's plenty of guides online) and you should be good.
Edit: If, however, the tutorial is for Java 9, I'd really recommend finding another tutorial as the module stuff is a whole set of extra complication which you don't need right away (I've yet to see Java 9 used in the real world)
I am very experienced in Java, but not in Netbeans. I have a project that I've been working on, a little test program for a particular issue, so I have been making changes to it and running it and debugging it many times a day, every day, for several weeks. Yesterday Netbeans quit running it the way I had been running it, and I can't seem to get it started again.
The entire output when I run the project is:
run: Error: Could not find or load main class
C:\Users\rcook\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
I note for whatever it's worth that the classname does not appear on the first line, as it seems to with others who have had the "could not find" error.
This happens whether I run the project (select the project and press F6) or the file (select the file and press control-F6). I have cleaned and rebuilt the project (which I didn't do often before, I've wondered if it caused the problem). I have restarted Netbeans. I have restarted the (Win7) computer. I am not running any memory-hogging programs except for Outlook, which I have been running the entire time it was working.
I can run the program from the command line by setting my default directory down to the 'classes' directory under the project and entering java stsclientexample3.STSClientExample3.
I have checked the "Run" configuration many times -- there are no program or VM options entered, it has the correct classname. Oddly enough, if I change the classname to something that isn't there, Netbeans displays a popup that says the invalid name class wasn't found in the project, and listing the main classes available. But when I do that and select the one to run, it gives the same "could not find" error. There's one other main class in the project, if I select THAT it gives the same "could not find" error.
I have looked at the XML file referenced in the message, but it is full of ${parameter} references that I don't know the resolution of. It would likely be helpful to know how Netbeans resolves "${classname}", for instance, or even to dump the value Netbeans has at runtime somehow.
I have commented out code and re-run. Same result.
I have deleted that class from the run configuration, restarted Netbeans, and added the class back. Same result.
By now I've read more than a dozen other queries for a similar error, on SO and other places; I've tried all the things that looked at all possible (skipping things like configuring for special-purpose libraries, etc.).
Anyone know how to fix this?
EDIT: before someone asks, another project with a main() runs using the 'run project' option.
EDIT2: I forgot to mention, also, that another post recommended that one delete the Netbeans cache (c:\Users\\AppData\Local\NetBeans\Cache), so I shut down NetBeans, deleted everything in that directory, and restarted NetBeans. Same result.
I've encountered this problem a few times and it is very frustrating. If you delete the cache it should fix it after you rebuild the project
Close netbeans
Delete the Cache folder User\AppData\Local\NetBeans\Cache\ (Windows 7 and above)
Open Netbeans
Rebuild and run
Edit - you can find the cache directory also by going in netbeans to Help - About then it shows your cache directory.
Try creating new class with main method and copy your code into this class.
Just close the Netbeans. Go to C:\Users\YOUR_PC_NAME\AppData\Local\Netbeans and delete the Cache folder. The open the Netbeans again and run the project. It works like magic for me.
(AppData folder might be hidden probably, if so, you need to make it appear in Folder Options).
I'm working in the Netbeans IDE 8,2. I had the same problem and in my manifest.mf, the field classpath: was empty(I noticed that because I got the message:
java returned 1 could not load main class ExerciseFinal
I looked at the classpath nb where searching and I simply changed one folder's name and then after restarting netbeans everything worked.
My file name was "teo_1=1;" and I changed it to "teo" simply because I thought that maybe 1=1 (always true) was messing the nb.
I had the same problem and i think the problem was in the file path, either it was too long or it had some forbidden characters(now i have seen that it was a letter from my language), when i copied a project to a different folder it worked...
After an eternity of trying to figure it out myself, looking through every menu, submenu, tab, and option, I was still stuck. Nothing anybody suggested worked for me.
How many hours did I spend flailing about in the name of pride and self-education? Several. How long did what I'm about to suggest take? Maybe 10 minutes; 15 tops.
Was my journey a waste? No. I learned a lot. But since I hadn't set out to learn what I did and was prevented from work I needed to do, I was pissed long before giving that up and copping out.
So... Long story short, do this:
(Step 1 has been deleted; renumbering steps might be bad idea. So start with 2!)
Step 2: Open the problem project.
Step 3: Create a new Netbeans project, get into Project view, and expand both projects to show their packages.
Step 4: Thoughtfully copy all packages from problem project to new.
(This means to hold off on the "main" package until last to avoid a chuteload of red-marked errors. If you see a bunch anyway, don't look at them. Further copying will fix many.)
NOTE: Having to choose a different project name for the new project will likely lead to a new name for your new "main" java class file. No problem. Just note this.
Step 5: Once you've copied all but the "main" package from problem project to new, open the "main" package to see your files. Then open the new "main" package, which will have ONE tiny file in it.
Step 6: Thoughtfully copy one file at a time (holding off on the "main" class file until last) from problem project to new.
(If you see errors, let 'em go. Not finished yet.)
Step 7: Once you have only the "main" class file left to copy from the problem project, open it. Also open the new "main" class file in the new project.
Step 8: Copy all the code from problem project "main" java class file and paste it into the new project's "main" file.
Step 9. There will be errors at the end. After all, at least one package and one file name changed. So open each source file with an error, put the cursor on each line with error, and press Alt-Enter to get a hint. Renaming the new main file or changing some old package names to new will fix a few, especially in some imports; this might just get rid of the rest.
I hope this helps someone. I should look for a more recent post and put this Answer there, if it gets enough upvotes.
I have been working on trying to use the openLogger tool which uses the OpenLog Database also available at openNTF, and I have hit a bit of a snag. My question is not about those databases explicitly, they are just a good example of what is going wrong!
My issue is that I wanted to rebuild the OpenLogger Demo/test database after making a few changes to the xsp.properties file, and I suddenly was presented the wonderful gift of 12 or more errors, all of which were that the com.ibm.xsp.extlib.util.ExtLibUtil class could not be resolved.
After a bit of googling, I found out that it sometimes helps to re-install Designer - done (three times)or to re-install the ExtLibs (done a few times and then upgraded to the 900_201305* version)
nothing.
I have really tried everything I can think of, and everything that I could find via google, but I cannot figure out how to get this thing to resolve. I remember once upon a time having to copy specific jar files into the designer install directory, but I cannot remember the details, nor can I find anything about that, nor do I know if this is my issue. I also thought about a specific designer variable not being set that would tell designer where to find the jar files, but I would not know where to begin searching for that.
Any help getting this thing to resolve would be a HUGE! help. It could also be that I wish to use this awesome looking class in my own applications. Thanks!
To make sure that the jar files is found and able to be used, try these things:
Use the package explorer to make sure the jar is in the "Referenced Libraries" folder
Check the build path, and add the jar to the build path if necessary
Examine the XSP properties file and make sure it looks correct, and then change something and resave it
Use Project | Clean which sometimes fixes issues like this
I've been searching the web for a long time, and it seams that this VerifyError isn't that uncommon and can have multiple reasons for tripping. I have created a project, that I've exported as a jar file. It is built with android 2.2 (API 8). This part works fine. But I have a separate project that when I try to import it, I start having problems.
The only way I've been able to get it to work, is to import the jar into a libs folder I created. It then get's automatically added as an Android Dependency and I can use it fine, however I can't attach my javadoc file to it, and in my build configuration it says I can't modify the dependency. (Can't link to a javadoc).
What I thought I should be able to do is simply add it as an external jar, then link the javadoc and source. If I do this, the code that uses the jar shows no errors, and the javadoc comments work. However I keep getting a VerifyError when I run it. I've attached a stack trace that shows the errors. I'm completely out of ideas, does anyone have any suggestions? Am I building the jar file wrong? Am I importing it wrong?
If anyone can help point me in a constructive direction, it would be really appreciated.
Thanks
Stack trace:
Ok, so this was frustrating to solve. The solution took about 20 seconds when I spent over an hour researching the problem.
What I had to do was go to:
Properties -> Java Build Path -> Order and Export
But rather than just clicking the external jar, I had to move it up to the top of the list for the build path order.
Credit definitely goes to yorkw for pointing me in the right direction.
I believe that Android jar files are a little different.
You could try putting the JAR files into the Android "dx" tool
It's in the ~/android-sdk/platform-tools