Product Version: NetBeans IDE 6.8 (Build 200912041610)
Java: 1.6.0_17; Java HotSpot(TM) Client VM 14.3-b01
System: Windows 7 version 6.1 running on x86; Cp1252; en_GB (nb)
Hello, newbee java programmer here and wondering if someone can help, I have been having some problems updating a GUI for a desktop application in netbeans, here are the details:
my current application GUI works great, everything is appearing correctly.
when I update the GUI by adding a new label from the netbeans toolbox onto my form, and use the netbeans preview function, everything looks great
however when i run the application the new label has disappeared..
to try and understand the problem i ran the app in debug mode and stepped through the auto-generated initComponents() code
from debugging i believe the problem comes from this line of code:
TEST_lbl.setText(resourceMap.getString("TEST_lbl.text")); // NOI18N
after this line of code has executed TEST_lbl.setText is equal to null..
so the label is disappearing when i run the app because it has no text value to display...
i opened the resource map file in notepad (the .properties file) and it contains an entry "TEST_lbl.text=jLabel1" among the entries for all the other working controls...
so the properties file has the correct value, but resourceMap.getString is not retrieving it
i can work around this problem by changing the "Automatic Resource Management" option of the form from "All Resources" to "Off"
as a result this changes the auto-generated "setText" code line to:
TEST_lbl.setText("jLabel1");
and makes the label display correctly when the application runs
my first question would be, is this a known bug? or have i done something silly and accidently changed a setting someware?
if this is not a bug, how do i correct the problem without changing the resource management setting?
if this is a bug, what are the implications of turning off automatic resource management?
Thanks for the help, - Gaz
I assume you're running it under NB (Run > Run Main Project)?
Try a clean build (Run > Clean and Build Main Project). That will usually fix it.
It's an issue of how the build system is structured.
When you run the project in a clean repository (Run > Run Main Project):
the .class files are written to $project/build/classes
the non-class files are copied into the tree
the whole thing is run from there.
That works fine.
If you "build" the project (Run > Build Main Project):
1. the .class files are written to $project/build/classes
2. the non-class files are copied into the tree
3. the whole thing rolled up into a jar file.
That also works fine.
However, if you subsequently make changes and run the project, the class files and resources now appear in 2 places:
in build/classes
in the dist/project.jar
This works OK as far as finding class files. Resources, however, are found in the jar first. So, at runtime, you code finds the outdated copy of the properties file in the jar, not the new one in the filesystem.
Also: NB ignores case when finding a resource, but Sun's JVM does not (not sure about IcedTea). So, if the wrong case is used NB may insist the file is there, but the JVM will not be able to find it.
Related
The case:
I have created a complex java project (spring boot) with maven build in IntelliJ and I was able to run it, everything was working fine. Now, as IntelliJ hasn't a community edition with spring boot, I had to move to vs code. I didn't change anything in my project, I just opened the folder (which contains the pom.xml and the src folder) in vs code and let vs code load the java project (earlier I installed all the extensions like spring boot, java, etc. for vs code).
After vs code opened the project successfully, I wanted to run it in the main method by clicking the run text (I inserted the image, that you can see the folder structure):
But as stated above, I get the famous error. I reloaded the window, I cleared the workspace, I set the JAVA_HOME and CLASSPATH variables in the env variables and tried, tried, tried it again, but no success. What the hell can I do on top of that? It worked in IntelliJ, it should work in vs code too. I use java se17. Note, that if I start a new simple project, the program get's compiled and executed without any error.
Another curiosity is, if I try to load the maven dependencies, vs code says, that it can't create the dependency tree, but if I run the mvn dependency:tree command, I get all the dependencies and it says, that the build was successful.
What is going on here?
EDIT: my antivirus program blocked maven, so, the problem with the dependency tree is now gone, but the error with the classpath remains.
I'm building a simple calculator app from a tutorial/class on Pluralsight (Java Fundamentals class), which starts with a Main.java file, and adds a class file later, MathEquation.java.
I created a Git repo to track my progress, and uploaded to Github: JavaFundamentalsClass. I used GitIgnore.IO to find a Java IntelliJ .gitignore file, and everything seemed to be working fine on the original PC I was using.
However, after switching over to a different PC, with a fresh install of IDEA, I cloned down the repo from Github, and found that the project would not build and/or run. I get this error:
"C:\Program Files\RedHat\java-1.8.0-openjdk-1.8.0.191-1\bin\java.exe" -Dfile.encoding=windows-1252 -jar ""
Error: Unable to access jarfile
Process finished with exit code 1
I suspect that there is something in the .gitigore file that is keeping some of the project, dependency, or build information from being saved in the repo that keeps IDEA from having all the info it needs to build and run the Main.java correctly.
Can anyone help? You should be able to download the project from the repo linked above in it's currently broken state, including the .gitignore file.
Additional Info
I wiped my repo clean and recloned and I forgot, originally it doesn't even give me the run button (it is grayed out). I had to do a procedure with "Add Configuration" from a search I did for that to show up to get the error above.
Also, I did install java from the OpenJDK, rather than oracle. I figured with Oracle cutting off commercial development maybe start the switch now as I'm learning, but maybe that's the issue (normal Java on my other PC).
It's working, but...
First thing - Intellij needs to know where Java is. It appears that if the SDK/JDK is not installed prior to Intellij, you will need to tell it where Java is after installing. Or if you use OpenJDK instead of Oracle Java SDK. You can do that at View/Open Library Settings, under Platform Settings / SDKs (select the JDK home path).
Then, after setting up Java, I am able to get everything working in Intellij IDEA if I find the Main.java file, right-click, and choose "Run main.main()". This runs the program okay, and also creates a Main configuration in the Run/Debug configuration area, and finally the "Run" button becomes available.
So I can get it working, but if I wipe all the files and clone it fresh from the remote repo, I have to go through running the Main.java file directly again to recreate the configuration.
So, this still doesn't answer my original question. Why doesn't this configuration get saved in the repo? What file is this information saved in? Is there something in the .gitignore file that is keeping this information from being saved to the repo?
Look like you have a different java version on your second machine.
First of all, check your java version
Update the configuration of your project, right now it pointing to java 1.8
https://github.com/LightCC/JavaFundamentalsClass/blob/master/.idea/misc.xml
I think it might be because of java not installed on the other PC you were trying. If it is installed just check whether the path mentioned has java executable file.
The first part is ensuring Java is setup, and that Intellij IDEA knows where Java is, per the other answers, comments, and addendums to the question.
The second part is setting up the run/debug configuration, per the "It's working but.." section of the question. This can be created automatically by right-clicking the file that has the main class to be run (usually Main()...), and selecting the "Run Main.main()" option (replacing Main and main() with the file and function which needs to be run)
The final piece is that to get the run/debug configurations to save to the repo, you either need to:
Share the workspace.xml file (i.e. make sure this is not in the .gitignore file). However, there is a lot of user-specific stuff in that file, so it should normally be excluded from the repo.
Or, edit the configuration and checkmark the "Share" box in the upper right-hand corner (just right of the "Name" field). This will put the configuration into a separate folder inside the .idea folder, which should not be excluded from the repo by .gitignore.
When I run an Ant build, MyEclipse (happens for v6.0 and 7.5) formats my code. When I open the file it says it was modified on the file system and when I reload it it is formatted.
The thing that is even stranger is that it is not formatted as specified in the Code Style in my Preferences (seems like Java Sun codding rules).
As far as I could determine, there is nothing called by the Ant build to do the formatting so it MyEclipse doing it? Could it be a plugin or something?
Part of the build also includes Maven tasks so could there be a Maven plugin doing this?
I mention that I searched and deactivated all possible options in the preferences of the IDE trying to find some setting but nothing.
It is very annoying so far and could cause problems since I am working on some older projects with minimal modifications in the code and don't want to have a complete messed up version of a class just because I modified a word or something.
Has someone else encountered this?
P.S. It happens only on my PC. My colleagues don't encounter this issue.
Thank you!
EDIT: I have executed some tests:
I executed the Ant script outside of
eclipse (in command prompt) then
opened the files with notepad. The
files are untouched, no formatting
occurred. If I open eclipse nothing
happens to the files.
I opened eclipse and changed the files on the disk using notepad (added some spaces and saved them). Eclipse says the files are changed on the file system and asks to reload them. I say Yes he opens the files. The files are unchanged. No formatting occurs.
I run Ant from eclipse. Eclipse says files have changed and asks to reload them. I say Yes and when the files are opened they are formatted. WTF??!?!!
Is there a config that says to run some tasks after ant builds or something? I could not find anything.
Did you check the "Save actions"?
Preferences" menu, Java > Editor > Save actions.
One of the possible actions is to format your code when you save. You can have these preferences on a global or per project context.
Although it's strange that the code gets changed when you run your Ant script.
Eclipse can format on save if you choose, and you can elect to have it save automatically any modified files before a build. There is nothing in myeclipse that would cause the code to be formatted on load. I would look through your plugins.
Jalopy has an ANT plugin that will format code
Everything was going well. Nightly builds ran for more than a month with no problems. However, suddenly when invoking the feature builder from Eclipse the execution ends right away with the message.
ERRORLEVEL 13
As far as I know I haven't changed anything, as this computer is normally not touched. (It is only used for the nightly builds).
I've googled around to see what this error means but to no avail. I found a link from IBM that shows a custom bat file that catches this error, but the explanation given is not very useful.
My guess is that this is related to the workspace, somehow, or that the whole eclipse installation is corrupted.
Do you have any idea what this error means and how can it be corrected?
After reading what the error code means thanks to the answer from VonC I understood where to look. The problem was a lot more obscure that it seems.
I looked into the configuration folder for Eclipse (logs are either written there or in the .metadata folder when something goes wrong), and I found a huge log file. Inside the file I found the following error:
application org.eclipse.sdk not found
and the following exception, followed by a plugin name, several times:
java.util.zip.ZipException: Too many open files
Several plugins could not be loaded, causing a cascade of missing dependencies that prevented Eclipse from launching. I searched the web for this exception and found the following bug description from SUN, which says that Java 1.5.0 can not open more than 2,100 zip files.
The problem started a while after I installed the BABEL project translations for Eclipse into the build computer. These are more than 900 fragments, containing translations for many plugins, one for each language. As I installed it on top of an existing eclipse installation, it seemed that it was not a problem to open them.... until I cleared the workspace for the builds. Then Eclipse wouldn't launch anymore. I went over the limit. It didn't help that the first thing I tried to fix the build was, again.... clearing everything.
Because I only use this computer for headless builds, I didn't realize that the problem was in Eclipse itself and I was looking inside the build process. I only realized when I looked into the log file.
After installing Java 1.6.0_11 I was able to launch Eclipse and go on with my build.
It should mean "ant build failed", meaning the headless ant script fails at some point.
You should check if you can catch the log/output generated by this script to analyze this ant session and see at what point the ant script fails.
If it fails right away, it usually is because of:
a change in rights (writing access), or
in environment variable modifications, or
in resource access (path non accessible).
You also have to check if the computer is still in its original windows domain, and if the rights (admin ?) associated with the account running the ant script are still the same.
OMG - what is going on with Eclipse (3.3 Europa) - has anyone come accross this problem (bearing in mind I have been messing about with uninstalling different Tomat containers and installing others - but anyway thats another story)
When I change a line of code or remove a class within my project - when I come to debug - it actually goes to a line that is commented out and runs that line regardless!!!! e.g.
//System.out.println("you should not be able to read this!");
UPDATE: This can be solved by setting Project -> Build Automatically (see answer below).
REMAINING PROBLEM:
Eclipse is not keeping my hot deploy folder current with the latest changes to my project:
I found out to my horror that some old remenants of my project are 'hanging around' in the folder that I think Eclipse uses for hot deploys or something
C:\myJavaCode.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myWebApp
basically it is not actually copying accross any changes made in the classes of my working dir!?!??
...anyway - in order to keep my project up to date - I have to modify this folder too - TOTALLY UNACCEPTABLE - as you can't develop in this way - it would take you eons! Anyway, if anyone can help explain to me what stupid thing I have done to get me in this mess and how I can get out of this mess - I would really appreciate it.
Have a look at:
Windows>Preferences>Server>Launching...
and:
Project>Build Automatically
maybe you accidentally disabled the auto-deploy features.
I had a similar problem, only without the added complexities of a web app. I'm just running a JUnit test and it's running the old code. I went into Configure Build Path, on the bottom of the Source tab, and looked at Default Output Folder, which said myproject/bin. The Package Explorer doesn't even show a bin folder, but when looking at the file system there's a bin folder there. I deleted the bin folder, refreshed the package explorer tree, and it worked. This behavior was in Helios and occurred with AND without Build Automatically selected...looks like a bug to me.
Dave
A super-silly question: Does all your webproject and related projects compile correctly?
Also check your output folder for classes (Project Properties -> Java Build Path -> Source Tab) then go to your filesystem and check permissions and modification dates.
Hope this will help you.
Probably the easiest way to get past this is to define a new server.
Right-click in the Servers window and select New, or when you do 'Run On Server' select Manually define a new server. You can have multiple servers defined using the same Tomcat runtime (they'll all have separate configs and deployment directories defined by -Dcatalina.base=...), but don't run them at the same time unless you change the ports they're listening on.
The new server will use a path like
<<yourEclipseWorkspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
for the Tomcat conf and webapps directory.
Try running on this server. If it works, you can compare settings with the old one,
maybe try deleting the app from it and re-deploying, and figure out what you might have done to cause the problem. Or just delete the original server config.
As far as your second problem, I'm not sure. I'd try a new server config first, get it working, stop the server, do a 'Clean' on your project, delete anything in the tmp1\work\Catalina directory, and restart the server (you could remove and add your project to the server again too to be really clean).
Check the console messages too to make sure there were no errors related to this.