How does Spring create the base URL for a Maven project - java

I'm using Eclipse and I'm learning Spring MVC/Rest/Security.
I created a Maven project from scratch but for some reason unknown to me, it refuses to connect to the database.
Then I used a sample project I have from somewhere, but replaced basically every file in it with the ones of the new project. For some miraculous reason this one DOES work even though it's comparably the same as the first one.
But I do have a problem with it: Whenever I try to run this project, under the "Run on server" window, Eclipse shows me the project as
Configured:
new-project-name(original-project-name)
When it manages to run (because it takes forever to load and it sometimes times out), the url given is:
localhost:8080/original-project-name/
instead of the new name I have given. I have replace the original project name in every file I could think of. In the folders that contain it, in "pom.xml" of course, "pom.properties", ".project", ".classpath" and even a eclipse config file called "org.eclipse.wst.common.component", to no avail.
I cannot find what file is it reading it from and I have checked every single one. I think.

Update properties file
/src/main/resources/application.properties
server.port=8080
server.contextPath=/original-project-name/
/src/main/resources/application.yml
server:
port: 8080
contextPath: /original-project-name/

Related

What is the meaning of the "Launch configuration Main (1) references non-existing project Server." error?

Every time I try to run chocolate(My New Game), I get a error saying
Launch configuration Main (1) references non-existing project Server.
I remember I deleted my old project Server, is it because of that?
IDE is Eclipse if needed
What does it mean?
It means that you have a Launch config whose name is "Main (1)", and that config refers to a project called "Server" that the IDE cannot find.
I remember I deleted my old project Server, is it because of that?
Well ... if you deleted it, that would explain why your IDE can't find it.
You probably just need to go to the panel where all of the Launch configs are listed and delete the one that your IDE is complaining about.

Eclipse asking for module named after the old project name

I'm trying to make my project modular on Eclipse, but I'm running into an issue. I have added the module-info.java file through right-clicking on the project > Configure > Create module-info.java. However, when I run, I get the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module serenitea-pot-manager not found
I believe this might be caused by having renamed the project to sereniteaPotManager at some point. Initially, the project name was serenitea-pot-manager, which is the name of the module being asked for. I did the renaming through right-clicking on the project > Refactor > Rename..., which should have updated all instances.
I have been searching for a while, but still haven't found a way to fix this. Is there anything else that I need to update on Eclipse for it to change to the correct module name?
Note: The module name included in module-info.java is indeed sereniteaPotManager.
I had the same problem. I will summarize my experience then my solution.
I did a rename of the module, and Eclipse kept wanting to use the old module name. Cleans, restarts, etc., did not help. A search of the project properties, the run configuration, and all files in the workspace, did not turn up an instance of the original module name. Editing the module name so that it matched the original one did work. It is as if Eclipse tucks away the initial module name in some hidden place and keeps wanting to use it.
I was able to solve the problem by deleting all Run configurations that existed and then creating a new project and new Run configuration.
I am using JavaFX, and a somewhat peculiar side-effect of this is that the normally-required run configuration argument (below) was not needed in this new run configuration. I wonder if Eclipse is tucking that away in some hidden place, also?
In Java, serenitea-pot-manager is an invalid module name since a module name must not contain hypens (-).
Therefore, In module-info.java, Eclipse shows Syntax error on token "-". So make sure, before running your application, no compile errors are shown in the Problems view.
Rename your module to serenitea_pot_manager, delete the existing launch configuration (in Run > Run Configurations...) and try again:
module serenitea_pot_manager {
// ...
}
https://stackoverflow.com/users/17416717/stevevzzz[Steves] solution worked for me while I got stuck with the same problem.
... but I did not create a new project. I only was able to solve the problem by deleting all Run Configurations that existed and then I created a new Run Configuration.
I noticed the same behaviour. After changing the module name of my project, I got the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module ... not found
It looks like eclipse holds on to the original module name that is used when first running the application using the Run Configuration. To work around this issue, I deleted and recreated the run configuration. Then it works again.

cassandra 3.5 fails to load trigger class

I am trying to get started with Cassandra triggers, but I cannot get Cassandra to load them. I have built jar files from here and here, and put them under C:\Program Files\DataStax-DDC\apache-cassandra\conf\triggers. I have restarted the DataStax_DDC_Server service (on Windows) and reopened the CQLSH command line, but trying to use the trigger class in a create trigger command gives me only:
ConfigurationException: <ErrorMessage code=2300 [Query invalid because of configuration issue] message="Trigger class 'org.apache.cassandra.triggers.InvertedIndex' doesn't exist">
I checked the jar files, and they include the class files.
The only thing I could find in the log files of cassandra is Trigger directory doesn't exist, please create it and try again. But I don't know if that is relevant.
EDIT: Following the last line shown here, I edited the cassandra.bat file. Now if I stop the DataStax_DDC_Server service and run the bat file directly, the create trigger command succeeds. Nevertheless, the service seems to be independent of this bat file. The question now is how to apply the same config to the service?
After googling creatively, I found a solution. As mentioned here you need to explicitly set the cassandra.triggers_dir variable, but for the service to pick it up, as explained here, you must configure it in the registry. So the answer is to update the registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\DataStax_CDC_Server\Parameters\Java\Options
and add the line
-Dcassandra.triggers_dir=C:\Program Files\DataStax-DDC\apache-cassandra\conf\triggers
Note that the path should not be enclosed in quotations, or it won't work.
Don't forget to restart the service.
Above solution is working for window. it's difficult in window to find registry option. so to find registry option go to start menu and type "regedit" it will open registry window then you can do above settings.

Spring Tool Suite: Copying and renaming a Maven Web App

I have a HelloWorld Java app called FitnessTracker that I want to clone as another name, FDE3, leaving the original website in tact. I performed the following steps an attempt to do this. Please tell me where I went wrong and/or what else I need to do.
Change Context Root
Confirm Change Context Root
Still the original "FitnessTracker" name persists and I'm not sure how to get rid of it.
If I was able to successfully clone the FitnessTracker webapp as FDE3, I should be able to access the new site as
http://localhost:8080/FDE3
But I get an invalid resource error. Instead, the site is still accessible as
http://localhost:8080/FitnessTracker
..because of reminants of the old name.
What do I need to change within Spring Tool Suite to get the web app to use only the new name? To minimize chance of corruptying the project, I'd rather do it via the STS GUI over manual modification of any system file.
I see that the following file contains the text "FitnessTracker" but I would rather not modify it manully for fear of breaking. What GUI option controls this?
Search "fitnesstracker" (2 hits in 1 file)
C:\Dev\Workspace\FDE3\.settings\org.eclipse.wst.common.component (2 hits)
Line 2: <wb-module deploy-name="FitnessTracker">
Line 7: <property name="java-output-path" value="/FitnessTracker/target/classes"/>
Sorry for being a noob.
Update:
I'm not sure what I did, maybe just clean, refresh, open/close a million time, dunno, but now when I run the web server from with the Spring IDE the site is coming up using the FDE3 path, however, I am wondering why I see a reference to Fitness in Parens in the project node.
Earlier, it just displayed "FitnessTracker" in parens, now I see a full path to a Test folder...
Update 2:
When I copied the FitnessTracker project as FDE3, I didn't expect that the new FDE3 project would have any ties to FitnessTracker project and I didn't think that the new FD3 project would be in SVN until I added it to SVN, but based on the icons I see below, it looks like it is, (I'm new to SVN, too)
It looks like my issues are related to SVN.
Why is there a tie to the original FT project and why? How should I have clone the FitnessTracker project?
Yes, your issue is indeed related to SVN. Copying an SVN working copy will copy .svn folders inside that and will be pointing to the same URL in the SVN repository. What you have to do is an SVN Export of your FitnessTracker project to FitnessTracke-Ex first in either Tortoise or Subclipse SVN client and then import that project into your STS Eclipse environment. Finally you can copy and rename the FitnessTracke-Ex project FDE2 or FDE3
See this
post on how to Export a working copy
See this post on how to Import an existing project into Eclipse

How to get jar class is coming from

I am currently working on an API for a server software so users can extend my software by programming plugins for it instead of modifying the software themselves, and allow other users without programming knowledge to easily change the software by adding these plugins. So far, everything is working fine. But, I am running into a problem with configuration.
You see, each plugin has a plugin.yml file stored with these 4 attributes:
Main: The main class is stored here
Name: This is where the plugin name is stored
Version: This is where the plugin version is stored
Author: This is where the plugin author is stored
Now, in order for the plugin to print something to the console, they use a function called: this.getServer().getLogger().info("MESSAGE); (They extend another class for plugins, thats why they use "this" instead of another class to log)
But, I do not have any idea on how to get which plugin is which when they are calling the function. I have a ArrayList of PluginSessions which event handlers use to cycle through to run Event Functions.
My solution is to get the jar from which a class is being called so I can then get the plugin.yml from there. But, I have NO idea on how to get that, I have tried using Class.forName(); and some other code. But because the class is non-existent within the jar/project running the code, It will throw a ClassNotFoundException.
Does anyone here know how to get the jar from which a class is coming from without using Class.forName()? Thanks! -Trent
Take a look at Class.getResource.
If you call MyClass.getResource("plugin.yml") (or "/plugin.yml" with leading slash, I forget) you get back a file URL pointing to the plugin.yml file in the same jar as MyClass. (Or null if the path is wrong or the jar doesn't contain a "plugin.yml" file.) You can then open an InputStream to that resource. In a plugin framework you may want to use myPluginInstance.getClass().getResource.
Assuming jar for 'PluginSessions' is already added in you classpath by eclipse then you can try the following trick -
Select/highlight PluginSessions by double clicking on it
Now press CTRL+SHIFT+T
A dialog named Open Type is appeared. Here you found from where the PluginSessions class is coming from. If you have more than one jar containing PluginSessions class than you have a list of them.
To benefited from this CTRL+SHIFT+T trick you need to add all of your jar need by the project to be added in your classpath.

Categories