GWT 1.6 project war layout- mixing source code & compiler-generated artifacts? - java

Having just wrapped up a GWT-1.5 based project, I'm taking a look at what we'll have to do to migrate to 1.6. I'm very surprised to see that GWT seems to want to write its compiled output to the war directory, where you would normally have items under source control.
What's the reason behind this? Did Google really think this was a good idea? Is there a workaround to keep source code separate from compiler-generated artifacts? Is there some other reason for this that I'm missing?
EDIT:
It's been suggested that I use the -war option to specify an output directory. I wrote some ANT scripts, and have this mostly working. I've had to copy over my static resources such as HTML, JSPs, etc into this directory (I'm using target/war, maven-style). Is that what most people are doing? Or are you just letting GWT write its output into your source-code-controlled war dir, and telling your VCS to ignore the non-version-controlled files? It occurred to me that there might be some benefit to letting GWT write to this dir directly, since then Jetty could automatically notice changes to JSPs, HTML etc, and avoid having to do a copy to make these changes visible.

Use the "-war" option to control where the output goes.
FYI: The Wiki has the design doc which will, hopefully, give you a bit of insight as to what they were thinking.
See also the Release Notes which discuss the new project layout, as well as some things to watch out for with this change.

Salvador Diaz has provided an excellent solution to this.

Yep, look at the -war option which may help.
What I'm doing (which may not be as clean as maven, and I dont use the -war) is I'm putting my entire project dir on SVN, and then ignoring the subdir that holds the js and other compiled bs along with the classes dir. That way I have everything else on source control, including the libs which I wanted. So another team member can just check out the whole project from SVN, compile, and ready to go.

Related

spring-boot: configuring different versions of a property-file with hardcoded filename?

Building a spring-boot app, we are depending on a 3rd party jar-file,
that expects to find a properties-file with hardcoded filename (say xyz.properties) on the classpath,
and will read its properties from that.
We need, though, to "switch in" different version of this properties-file, depending on in which environment we deploy the jar-file.
So would need, preferably, to add to the classpath a directory external to the jar-file, where we can put the properties-file.
Googling this, I find other people having similar issue,
but not a simple, clean solution for it.
It seems to me, the spring properties-model assumes you only care abt the property-names and their values
(picking them up from System.getProperties())
and really dont care abt from which property-file each value comes.
This may be fine when building your own code along that model,
but may fit not so well when depending on 3rd party solutions, like our use-case.
The simplest workaround I found is to "explode" the spring jar file,
then copy desired property-files into WEB-INF/classes,
then start with the JarLauncher.
Just wondering if there is a better way, without need to "explode" it?
Is my understanding above correct, or have I just overlooked some spring-feature that already supports this use-case?
Hopefully it still works - but with some trick you can set your own classpath:
java -cp "./conf/:yourBoot.jar" org.springframework.boot.loader.JarLauncher
and then you can place your config in external dir (as you already suggested).
See original question: Add jar file to spring-boot classpath at runtime

Eclipse kepler - Disable javascript validation

I just installed the new eclipse kepler (eclipse 4.3). It shows me hundreds of errors and warnings from third party javascript libraries.
I tried to disable the javasscript validation completely by unchecking "Enable JavaScript semantic validation" in "Preferences/JavaScript/Validator", but with no effect - Errors and warnings are still shown.
Is there another option to disable them or is this just a bug?
Can other people confirm this issue or is it just me? :)
Edit 1: Lavie Tobey pointed out, i should set all validations to "ignore" -> did not help
Edit 2:
Jim Garrison pointed out, i should disable the builder for the projects -> Actually I don't have a javascript builder in there. Disabled for testing purposes all of them, but did not help:
You can go Project properties/Javascript/Include Path/source and exclude the third party components.
There are two places you have to look. You have found the first. The second is in each project's Properties dialog, accessed by right-clicking on the project in Package Explorer and selecting "Properties". There, under Builders you may find a "Javascript Validation" entry, which you must disable.
You have to do this for every project that contains a Javascript Validation builder.
Try this: Open the .project in notepad and remove the javascript validator
I've found that in previous versions of Eclipse, the only way to really get these to go away is to enable it and change every case to "Ignore".
You can switch off (and configure) validation in Preferences/Validation or (for each project) Properties/Validation. However, this doesn't seem to force a cleanup of the messages.
Like it was said : be sure to go to PROJECT properties (right click on project, properties), and not Workspace (Eclipse/preference).
I searched like 20 min before hitting myself ;)
I solved this by choosing a PHP profile for my javascript instead.
Maybe you don't get the same functionality but for me this profile is just fine. Crashes, hangings & frustration went away.
I had the same issue for XML Validation. I deactivated the validators globally and in the projects itself, nothing worked for me. There wasn't even the slightest hint that anything changed. I even uninstalled XML Editor and Validation Plugins without any effect.
In the end the problem was solved in copy-pasting the XML files with a validation error, deleting the old files and renaming the copies files to the original ones. Somehow Eclipse did not re-validate the old files, but the new ones were okay.

How to rename Java packages without breaking Subversion history?

The company I'm working for is starting up and they changed their name in the process. So we still use the package name com.oldname because we are afraid of breaking the file change history, or the ancestry links between versions, or whatever we could break (I don't think I use the right terms, but you get the concept).
We use: Eclipse, TortoiseSVN, Subversion
I found somewhere that I should do it in many steps to prevent incoherence between content of .svn folders and package names in java files:
First use TortoiseSVN to rename the directory, updating the .svn directories.
Then, manually rename the directory back to the original name.
To finally use Eclipse to rename the packages (refactor) back to the new name, updating the java files.
That seems good to me, but I need to know if the ancestry and history and everything else will still be coherent and working well.
I don't have the keys to that server, that's why I don't hastily backup things and try one or two things. I would like to come up with a good reason not to do it, or a way of doing it which works.
Thank you for your help,
M. Joanis
Package rename test
Procedure:
Create a new package com.oldname.test.renametest.subpackage.
Add a new class under renametest called RenameTest0.java and containing:
class RenameTest0 {
public RenameTest0() {
showMessage();
new RenameTest1();
}
public static void showMessage() {
System.out.println("RenameTest0!");
}
public static void main(String[] args) {
new RenameTest0();
}
}
Add a new class under renametest.subpackage containing:
class RenameTest1 {
public RenameTest1() {
showMessage();
RenameTest0.showMessage();
}
public static void showMessage() {
System.out.println("RenameTest1!");
}
}
Test that RenameTest0 runs fine.
Commit.
Change the messages of both of the classes.
Commit.
Again, change the message of one class and commit (just creating some history).
Apply procedure proposed above (the three steps in the original message) for renaming package renametest to testrename.
Commit.
Test run.
Modify the messages again and test.
Commit.
Try to roll back to the version when both messages have been changed simultaneously the first time.
If everything worked fine to this point, it looks good, no?
Result of test:
Note on step 9: Had to do it in reverse order (Eclipse rename THEN TortoiseSVN rename.), else it was getting complicated, as TSVN create a new folder/package and marks the old one for deletion... So you can't rename for Eclipse unless you put the old package somewhere else in the meantime to prevent losing .svn folders, etc. etc. Didn't look like a good idea to go further with this method. (Note to myself: don't forget to tick the checkbox for recursive package renaming!)
Note on step 14: Worked! We can see previous versions; all we have to do is tell not to break on copy/move and it's ok. Once reverted to a version before the rename, the package names are not back to the good name though, probably that refactoring it again would do it.
End note: I was surprised to have to do the critical steps in reverse order. To do that right in the middle of this first package rename try, I had to roll back some TSVN and manual modifications, casting a little doubt on the repeatable nature of the exact results of this procedure. I will have to do a second test to confirm it's validity. To sum up: it looks good, but needs further testing.
Perhaps it's not practical for your exact needs but TortoiseSVN has a handy feature regarding renames. You could do this:
Use your IDE's refactoring feature to rename stuff.
Launch the "Check for modifications" dialogue from TortoiseSVN.
For each renamed item, you'll see two entries: a missing "source.java" item and an unversioned "target.java" item. Highlight both and choose "Repair move" from the context menu.
Repair moves/renames
Have you considered using the Subclipse plugin? It may solve your problems, according to How do I use Eclipse Refactoring Tools and stay in sync with SVN through Subclipse?
Are you sure keeping history is NOT working if you are using the refactoring method included in eclipse?
With NetNeans I regularly change package names and the underlying 'svn plugin' will silently move the content (which saves history) into the new directory (after that the normal refactoring will happen).
so: Have you tried it from within eclipse if the history is kept with the subversion plugin? (e.g. in a fresh check-out copy to avoid failure)
At least you could use NetBeans to do this one-time task ...
Yes, it will work. You could install the command line version of svn and write a batch file that will do the svn stuff. Automating the eclipse stuff would be a bit more work, and probably not worth it unless you're already familiar with the eclipse API.
Test it with one package before you do everything just to make sure you're doing all the steps right.
You can do this, and it's not that hard - your best bet to get a clean SVN history is to do it in 2 steps (can become one commit) - though for good results I recommend using the CLI client.
Use svn mv to move the folders/packages
Go into Eclipse, or use grep from the CLI to fix the packages in the files to match the new name
Then you can commit as a change-set, and the history at the file level should match.
If you're using Maven or a packaging tool, recommend you run a release before doing something like this - also it's worth cutting a tag immediately before this in case you need to go back to the old structure
I discovered that the subclipse plugin gives the error message " is already under version control" when committing a class that has been moved to a new package (i.e. not under source control yet) and the parent of this package is also new.
When this happens, I can commit the changes using TortoiseSVN. After that I only need to refresh the project in Eclipse.
After moving a class to a new package whose parent is already under source control, subclipse can commit this change without problems.
Instead of renaming the packages you could do this:
create the new package structure in your project. Once done your project should look something like this:
com -
|- myOLDcompname -
| |- feature1 -
| |- classA.java
| |- classB.java
|- myNEWcompname -
|- feature1
add the new folders under version control so svn can track them
move your java classes from old packages to new ones. Eclipse should update all the classes imports and package declarations accordingly. Most importantly because old and new packages are under vcs this step should keep the history of the classes.
when done delete the old folders
commit!

m2eclipse marking 'target' directory as 'Derived'

I have a Maven Java project, imported using m2eclipse.
The target/ directory is not marked as 'Derived' by m2eclipse.
Problems:
It is validated, so any validation error appear twice. My example shows a JSP Problem, when I insert intentionally an error in a jsp.
When I want to open a resource with Ctrl-Shift-R, all files appear twice, and I run the risk of editing the copy instead of the original file.
Possibly see post eclipse-ignore-folder
Note: When I set manually the directory to derived, the validation problem doesn't disappear, so that would only be part of the solution...
Question:
Is there something I need to do, so that m2eclipse sets the target/ directory to 'Derived' ?
Yeah, that has been around for a while. I wrote a plug-in that allows you to mark directories as "derived" without having to find them all (http://eclipsefrills.sourceforge.net/). It's not great, and you still have to manually run the action to make it work, but it may help.
Odd, though, I have not noticed the problem lately, myself. I wonder if there is some setting in the preferences that takes care of this now.
Good luck.
I got rid of this problem by writing a custom plug-in KeepTargetDerivedPlugin. As its name suggests, it automatically keeps all target folders derived (unlike the other solutions, which require user action).
Still, e. g. the YA2O's plug-in can be used to mark derived folders of projects which already reside in the given Eclipse workspace.
Yes: open a bug report :)
I have been so annoyed by this problem that I wrote a plugin to solve it. You can get the source and jar from here.

Java Reflection not working on my system - working for team members

I am working on a team project in Java. One requirement is that we dynamically populate a drop-down menu of all classes that implement a certain interface. New classes can be added after compile time. To accomplish this we are using reflection.
Problem: All of the drop-down menus are blank on my system. I cannot for the life of me figure out why they are not populating. All other 5 team members have it working on their system.
Things I tired that didn't work:
1) Installing most recent eclipse (galileo) because rest team was using it
2) Re-install most recent java release (jdk1.6.0-17 and jre6)
3) Check PATH and JAVA_HOME variables
Any thoughts as to what else I can try or if something I did should have solved it and didn't? It is driving me crazy.
Edit:
I should have been clearer that we are developing in a team. We are using SVN for version control and we are all running the exact same source code. I even tried checking out a fresh copy of the entire tree from SVN, but I had the same issue with reflection on my system while it worked for teammates.
The team created an executable jar and that ran on everyone's system fine except for mine. Everything worked for me except the reflection bit.
You need to debug your application. This means you have to systematically explore possible causes of the problem. Here are some things that come to mind:
Could your GUI be failing rather than reflection? What if you output with System.out.println() rather than your menu?
Is your reflection code throwing an exception, and are you ignoring it?
Is your reflection code actually being called? Toss a println() in there to be sure!
Is the test for the interface suffering from a typo or similar error that's causing it to fail? Try finding classes that implement Serializable instead!
Is your reflection test running in the main thread and trying to update your GUI? You need to use SwingUtilities.invokeAndWait to get an update to the Swing worker thread.
You're working with Eclipse; Eclipse has a fantastic debugger. Set a breakpoint near where your main action is and then single step through the code.
PATH and JAVA_HOME won't help. PATH only affects dynamically-linked libraries ("native code"). JAVA_HOME is a scripting variable that happens to be used by some Java-based utilities like Ant and Tomcat; it means nothing to the Java runtime itself.
You need to be investigating the classpath, which should be specified by the -classpath option to the java command, in the Build Path in your Eclipse project properties, or in the Class-Path attribute of the main section of a JAR file if you're launching java with the -jar option.
From within your code, you should be able to list the contents of your classpath by examining the system property, "java.class.path"
System.out.println(System.getProperty("java.class.path"));
Problem solution:
Classpath leading to source code must have no spaces in it.
I am running windows XP and, for whatever reason, if the classpath that leads to the jar file or source code that is using reflection has any spaces in it, then the reflection fails.
I took the jar file that works for the rest of my team and ran it from C:\ on my system and the reflection worked perfectly fine.
I do not know why this is so please comment if you know what is happening.
Might be a long shot, but look for differences in security settings for you and your team mates. Article describing more details http://www.ibm.com/developerworks/library/j-dyn0603/ heading "Security and reflection"

Categories