Michael MacEachran

Greenhorn
+ Follow
since Dec 15, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 Michael MacEachran

I agree. And after yesterdays attack, it has gone to the top of the list. So I have a budget. Im just wondering if someone out there has already done the research and can tell me who company X is.
13 years ago
Is there a virus scanner for Java? I am doing some file I/O and need to scan it. Ideally, a class that takes a ByteStream, InputStream, File, or whatever, and does the scan in my code before I write it to disk. (Actually store it in Alfresco)

Thank you,
Michael
13 years ago
I have given up. My solution:

I set environment variables for what I want and used System.getenv()

Works on all platforms and class loaders!

Thank you for the help. I think the problem is that this jar is being used in many ways by many apps with different ways of loading the classes, so nothing seemed to work in all situations.
13 years ago
Well, I cant get either of them to work. Now, because I have several classes that need a properties file I thought that I would move the my.properties to the root of the jar file and do this:



I open my jar file and at the root I have 2 directories com and META-INF and one file my.properties

that should work right? I am getting a NullPointerException
13 years ago
What am I doing wrong? I have tried every permutation of something like this:



I have tried all of these:
props.load(classLoader.getResourceAsStream("com.myapp.props.properties")); // with the file named "properties"
props.load(classLoader.getResourceAsStream("my.properties")); // with the file in the same directory as the class
props.load(classLoader.getResourceAsStream("my.properties")); // with the file in root directory of the jar

Any ideas?

13 years ago
All,

I have a standard dev/test/prod enviroment. I also have my core classes in myapp.jar. I have your basic db connect string for each environment. So I am trying to do this right and have a properties file instead for hard coding a different string for each DB (among other things)

The problem is that the jar file is being used by many applications. Stand alone executable jar, web services, web applications, Eclipse IDE, etc... so my relative file path is different every time and - fails - the path is different every time

I cold hard code it from the root, but that's wrong, and it's different on every box.

There has to be a way of doing it so the path is relative to the jar file. Something like a class.forName("com.myapp.properties") so that nomater where the jar is being used, it can find the properties file.

Also, it should be easy to deploy with ant, like I copy the correct properties file into the /bin directory and simply jar it up.

Any ideas?
13 years ago
I have searched through all the past post and have not found exactly what I need so here it goes:

I have working several webapps under the webapp directory such that :

localhost:8080/myapp
localhost:8080/yourapp
localhost:8080/everyonesapp

all works fine under the same tomcat instance.

Now management has spoken and it MUST be this way:

localhost:8080/ (is the home of myapp) aka /webapps/myapp/index.jsp
localhost:8081/ (is the home of yourapp) aka /webapps/yourapp/index.jsp
localhost:8082/ (is the home of everyonesapp) aka /webapps/everyonesapp/index.jsp

all under the same tomcat instance

I tried to just play with the connector such that:

<Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000"
redirectPort="8443"
appBase="/webapps/myapp" />
<Connector port="8081" protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000"
redirectPort="8444"
appBase="/webapps/yourapp" />

etc... but that did not work. I suspect that I must also change my myapp.xml in /conf/Catalina/localhost/myapp but I do not know where to begin.

thank you in advance for any help
13 years ago
Sorry, I was not clear... That was the line that I added in my ant build.xml to make the jar...
13 years ago
So I go ahead and try adding the classpath to the MANIFEST like this:
<attribute name="Class-Path" value="C:/AntStage/lib/quartz-1.7.3.jar"/>

and now it cant find the main-class !!! I tried adding "." to the classpath like this:
<attribute name="Class-Path" value=".;C:/AntStage/lib/quartz-1.7.3.jar"/>

But then it could not find the quartz classes!

it's like it will only take one classpath.

for now, This is working:

java -classpath C:\AntStage\lib\MyReports.jar;C:\AntStage\lib\quartz-1.7.3.jar;C:\AntStage\lib\commons-logging-1.1.jar com.x.scheduler.ReportScheduler

but that seems to defeat the point of an executable jar....
13 years ago
I have not done this in years so maybe I am missing something simple but.....

I have some classes that generate reports. I want to schedule these reports to run in the morning. I go and use Quartz scheduler. I run in Eclipse, everything is fine.

I of course do not want to keep an instance of Eclipse up on the production server just to run reports!

I jar everything up (Using ant if that matters, but the same jar file works on production) I explore the jar, and ant put the correct MANIFEST file in there. the main class is com.x.reports.ReportScheduler

I run this:

java -jar reports.jar

I get the NoClassDefFound error for the quartz jar file.

so I do this:

java -classpath C:\AntStage\lib\quartz-1.7.3.jar -jar reports.jar

Still NoClassDefFound !!!

I test to see if the .class files are messed up and run this:

java -classpath C:\AntStage\bin;C:\AntStage\lib\quartz-1.7.3.jar com.x.reports.ReportScheduler

Works fine!!!

Is there something about jaring everything up that messes with the -classpath?
because the .jar is just the /bin directory jared up, so I don't see what the difference is.


13 years ago
I wrote my first session EJB's from scratch yesterday and deployed them on glassfish. However, they act exactly opposite of what I thought would happen. Here is the scenario:

I have 2 beans StatefulCounter and StatelessCounter, they have the exact same code except for the name. Here are the relevant bits:

private int count = 0;
public void increment() {
count += 1;
}
public String getCount() {
return String.valueOf(count);
}

Verry simple.

I then have a JSP that increments then displays the count of each bean. Here are the relevant bits:

<% InitialContext ic = new InitialContext();

Object oRef = ic.lookup( "StatelessCounter" );
StatelessCounterHome statelessHome = (StatelessCounterHome)PortableRemoteObject.narrow( oRef, StatelessCounterHome.class);
less = statelessHome.create();

Object oRef2 = ic.lookup("StatefulCounter");
StatefulCounterHome statefulHome = (StatefulCounterHome)PortableRemoteObject.narrow(oRef2, StatefulCounterHome.class);
ful = statefulHome.create();

less.increment();
ful.increment();
%>
<table border=1>
<tr>
<td>
Stateless counter: <%=less.getCount()%>
</td>
<td>
Stateful counter: <%=ful.getCount()%>
</td>
</tr></table>

However, when I keep hitting the reload button on FF, the stateless counter goes up, and the stateful counter stays at 1. This is exactly the opposite of what I thought would happen.

Also, here is the relevant ejb-jar.xml:
<session>
<ejb-name>StatelessCounterEJB</ejb-name>
<mapped-name>StatelessCounter</mapped-name>
<description>Simple session bean example</description>
<home>com.pos.ejb.test.home.StatelessCounterHome</home>
<remote>com.pos.ejb.test.remote.StatelessCounterRemote</remote>
<ejb-class>com.pos.ejb.test.StatelessCounter</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
<session>
<ejb-name>StatefulCounterEJB</ejb-name>
<mapped-name>StatefulCounter</mapped-name>
<description>Simple session bean example</description>
<home>com.pos.ejb.test.home.StatefulCounterHome</home>
<remote>com.pos.ejb.test.remote.StatefulCounterRemote</remote>
<ejb-class>com.pos.ejb.test.StatefulCounter</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
</session>

What concept am I missing?