John McParland

Ranch Hand
+ Follow
since May 11, 2009
John likes ...
Eclipse IDE Spring Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John McParland

I finally figured this out. Peter was right that I needed a copy. I put this in.



As part of the the copy task and it worked! That said, I did have to simplify the structure, to do away with different mode-controlled directories for the properties files. I'll look to add this back in later.

After this I looked at why the application would not launch. As it turned out, when I looked at the Tomcat logs, I found that because I had already deployed an application with the same name Tomcat wouldn't allow it. The lesson is to clean-up your applications...

More checking of the logs led to uncovering problems with file locations etc but in the end it now works!

Thanks!
7 years ago

Balkishore pandey wrote:Hi John McParland,
When i directly specify the path in java.io.file, the source code works perfectly.
And by the way, it is fine if i have t write a new property file for a new machine.
Any help would be very much appreciated.

Regards.



As I said earlier, you'd be better to read the tutorial on Resource Bundles to find out how to do this.

7 years ago

Balkishore pandey wrote:Hi John McParland,
I tried debugging, i use netbeans by the way, by placing the end point. But still i dont get any thing. And yes it is a web application. I don't use and kind of logging mechanism.
Is it possible to use properties or configuration files? If so how can I use them?
Any help would be very much appreciated.

And Thank a ton for replying.
Regards.



Well if you've put a break point on the code, at the point of calling exec, and it doesn't reach it then you've got far bigger problems. Work backwards from that point, placing break points earlier in the code until you can figure out why it is not executing the "exec" part.

Using properties or configuration files is rather moot until you can get it working as is. Besides, these mean that for every new machine you deploy to, you'll need a new properties file. I'm not sure this is exactly what you are looking for.

7 years ago

Balkishore pandey wrote:Hi John McParland,
I have a small doubt,
How should i print System.getProperty(PYTHON_PATH)?
I used System.out.println(System.getProperty(PYTHON_PATH)); and stopped debugging a line after this.
But not getting any thing.

What i am getting is



This appears to be the output of building the project rather than debugging it. I was thinking about using, for example, the Eclipse debugger with a breakpoint set at the place you are calling exec.

You can print the system property like this;



Of course I don't know exactly where System.out is going in your application. Is it a web application? Does it using logback or another logging mechanism? If so it would be better to log the value of PYTHON_PATH to there instead.


Are you sure i have to use java.io.file in this line



Yes I'm sure it is java.io.File. After all, the value in pythonPath should now be the location of python.


7 years ago

Peter Johnson wrote:Where are your config files located in your project? If they are in the same location as the .java source files, you will need to copy then over to the classes directory (the <javac> task doesn't copy properties file)



Hi Peter.

The config files are within the packages. E.g.

main/packages is the main SOURCE root.

All packages start with name com.mcpaland.john.footballmanagerroles

Under the directory main/packages/com/mcparlan/john/footballmanagerroles there is the "config" directory, and many other directories. The config directory contains the Spring XML file, while other directories contain Java source code.

I understand what you say about copying the files over - but where exactly should this be? I've tried messing around with it myself, but while that allows the War to contain the Spring XML file, it does not let Tomcat launch it!

John
7 years ago

Balkishore pandey wrote:Hi John McParland,
Thank you very much for replying.
But when I run this script, i get an HTTP 500 error.
Edited: I use to get this kinds of error before, when my python file is not read.
Any help would be very much appreciated.

Regards.
Balkishore



Have you tried debugging the process? What about printing out the value obtained from System.getProperty(PYTHON_PATH)?

Where are you getting the 500 error exactly?
7 years ago
Hi Maulin,

If you look at the getTimeZone() method of the Calendar class clearly you can see there is a way to get a TimeZone from a given Calendar.

The trick is to get an appropriate calendar instance using the getInstance() method of Calendar, passing in a Locale.

Unfortunately that'll not help down to the city level. The above will only work for countries. SO why not try the likes of Joda Time as suggested here?

I hope this helps,

John
7 years ago
Hi Balkishore,

so from what I understand is that you would prefer the path in this segment of code to be more generic, or platform-independent (i.e. doesn't matter whose computer it runs on).



You have multiple options, two of which you have suggested.

  • Use properties files
  • Use system properties


  • My own preference, since this is a plain Java application, is to use system properties. This means that an Environment Variable, called PYTHON_PATH (or something similar) is set. The value of this variable is the path to Python on the users computer (in your case C:\\Users\\Balkishore\\Documents\\NetBeansProjects\\Testinstrument_Rest\\build\\web).

    In your code, to get this path, you only require;



    If you would prefer to use a configuration file, again you're almost on the right path, but spend a few hours reading the tutorial on Resource Bundles to better understand the approach (I myself am starting to forget it)

    I hope this helps.

    John
    7 years ago
    Hi all,

    I'm creating my first web project, and having completed the coding using Java, Spring and Apache Commons , I'm trying to use Ant to build the project.

    You can browse the project source tree here.

    Simply put, the Spring Beans File (footballamangerroles.xml) resides within a package (com.mcparland.john.footballmanagerroles.config). There are config files one level down from there too ([dev|prod]/footballamangerroles_log4j.properties).

    However when I build the project, using Ant, the config directory is completely missing! See the image below.



    I would have expected a config dir with all the config files (and subdirectories) in there. I note also that the war itself does not include the config dir.

    Here is my build file (also here);



    Additionally, when I try to launch my web application, I see the following;



    Please let me know if there is a way I can ensure the Spring Beans File is included in the War and the application can launch.

    Thanks,

    John
    7 years ago

    Manish Sridharan wrote:Just had a glance on the stack trace. it seems either jndi is not initialized properly or it has not retrieved properly in the application. You can try following things to check that.

    1. Try changing to
    I think forward slash might not be required.

    2. Create simple main class and try to get datasource object directly from jndi. Try with runtime debugging, it will give lot more information on the jndi.

    Another important thing, please initialize log4j properties file and set it to debug level for spring classes. this will give you more logging information where in spring it has failed.
    I generally attached the spring source code while debugging to see where the application is failing.


    Thanks



    Thanks Manish. I tried suggestion one and put trace logging on for all. I'm not sure exactly where I could put a breakpoint on since it fails early on.

    7 years ago
    Hi again.

    I tried the example based on Tomcat JNDI Datasource Examples - HOWTO for MySQL and also section 5.2.1 of Spring In Action (2nd Edition) but I haven't had any luck.

    Here's what I've got now.

    In XAMPP (the web server I'm using for testing just now); I've got a Context.xml file in this location C:\xampp\tomcat\conf\Catalina\localhost
    It looks as follows;



    Then in my Spring Beans property file I have



    And finally some noddy Java code



    Unfortunately when I run this I get an exception;



    I'm not sure exactly where it's gone wrong. Any ideas anyone?

    Thanks,

    John
    7 years ago

    Manish Sridharan wrote:Quite agree JNDI would be a better way to go for it. Perhaps you can have a look on this link :Configure JNDI with Spring

    Thanks,



    Thanks - I'll certainly use it!
    7 years ago
    Thanks Bill. The idea of using JNDI and the username/password being configured separately on the server sounds about right. I like how it means the code can be entirely separated from the authentication.

    I've got the Spring In Action book but haven't come across that example yet. I'll give it a go.

    Thanks
    7 years ago
    I agree with Bill's approach here. This was the class is annotated with the configuration files to load and the bean to test is autowired. You could also have a method for setting the object to test and annotate that instead.

    It cuts down the amount of code in the test case, making it much clearer.
    8 years ago
    I am writing a web application using Java/Spring and MySQL.

    At the moment I have a datasource configured as follows;



    But the "password" property concerns me. It seems wrong to pass the data source the password explicitly.

    I have taken some measures to improve the security of my app including;

  • chaning the root password
  • giving my application a userid/password for it alone
  • ensuring my apps user id can only access the database it needs (and only do what it needs)


  • But I'm not sure how to configure the data source in a more secure manner. I'd imagine anything which requires a password property at all is off the table.

    How do others securely configure their data sources?

    Thanks,

    John
    8 years ago