This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 254411 - Running a program includes unnecessary jar files
Summary: Running a program includes unnecessary jar files
Status: NEW
Alias: None
Product: javaee
Classification: Unclassified
Component: Web Project (show other bugs)
Version: 8.0.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Petr Hejl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-16 23:22 UTC by blake1024
Modified: 2015-08-21 21:52 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description blake1024 2015-08-16 23:22:27 UTC
I have a large Java/SOAP/Tomcat app that works fine.  However, if I try to run a single file by itself as sort of a command line program via right-click / Run File, the system unnecessarily provides a classpath with all of the Web stuff that isn't needed.  In fact the added jar files prevents the program from running because of some sort of conflict.  The libraries I specify are fine.  The ones being erroneously included by NetBeans at runtime are:

/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/asm-all-repackaged-2.2.0-b21.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/cglib-2.2.0-b21.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/guava-14.0.1.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/hk2-api-2.2.0-b21.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/hk2-locator-2.2.0-b21.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/hk2-utils-2.2.0-b21.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/javax.annotation-api-1.2.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/javax.inject-2.2.0-b21.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/javax.servlet-api-3.0.1.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/jaxb-api-2.2.7.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/jersey-entity-filtering-2.5.1.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/jersey-media-moxy-2.5.1.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/org.osgi.core-4.2.0.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/osgi-resource-locator-1.0.1.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/persistence-api-1.0.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/ext/validation-api-1.1.0.Final.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/jersey-client.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/jersey-common.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/jersey-container-servlet.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/jersey-container-servlet-core.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jersey2/jersey-server.jar
/opt/netbeans-8.0.1/java/modules/ext/eclipselink/eclipselink.jar
/opt/netbeans-8.0.1/enterprise/modules/ext/jaxrs-2.0/javax.ws.rs-api-2.0.jar
/opt/tomcat-8.0.9/lib/annotations-api.jar
/opt/tomcat-8.0.9/lib/catalina-ant.jar
/opt/tomcat-8.0.9/lib/catalina-ha.jar
/opt/tomcat-8.0.9/lib/catalina-storeconfig.jar
/opt/tomcat-8.0.9/lib/catalina-tribes.jar
/opt/tomcat-8.0.9/lib/catalina.jar
/opt/tomcat-8.0.9/lib/ecj-4.4RC4.jar
/opt/tomcat-8.0.9/lib/el-api.jar
/opt/tomcat-8.0.9/lib/jasper-el.jar
/opt/tomcat-8.0.9/lib/jasper.jar
/opt/tomcat-8.0.9/lib/jsp-api.jar
/opt/tomcat-8.0.9/lib/servlet-api.jar
/opt/tomcat-8.0.9/lib/tomcat-api.jar
/opt/tomcat-8.0.9/lib/tomcat-coyote.jar
/opt/tomcat-8.0.9/lib/tomcat-dbcp.jar
/opt/tomcat-8.0.9/lib/tomcat-i18n-es.jar
/opt/tomcat-8.0.9/lib/tomcat-i18n-fr.jar
/opt/tomcat-8.0.9/lib/tomcat-i18n-ja.jar
/opt/tomcat-8.0.9/lib/tomcat-jdbc.jar
/opt/tomcat-8.0.9/lib/tomcat-jni.jar
/opt/tomcat-8.0.9/lib/tomcat-spdy.jar
/opt/tomcat-8.0.9/lib/tomcat-util-scan.jar
/opt/tomcat-8.0.9/lib/tomcat-util.jar
/opt/tomcat-8.0.9/lib/tomcat-websocket.jar
/opt/tomcat-8.0.9/lib/websocket-api.jar


I want to be able to right-click on a file and select "Run File" to run it with the jar files I specify only.

I have been using NetBeans for years and it always ran the way I am requesting.  Something changed in the last 6 months or so.

Thanks.

Blake McBride
Comment 1 Jiri Kovalsky 2015-08-17 09:23:06 UTC
This might be similar to issue #247702. Reassigning for further evaluation.
Comment 2 blake1024 2015-08-17 12:15:10 UTC
While it is true that the jersey libraries are always included, perhaps errantly, as the other bug describes, this bug report refers to something different.  Those libraries, whether or not they are included when the Web app is run, clearly shouldn't, in this case, be included when a single module is run as a command line utility (without the server).
Comment 3 Petr Hejl 2015-08-17 13:05:25 UTC
That's how the project is designed if it is a Java EE project.
Comment 4 blake1024 2015-08-17 13:37:02 UTC
I have been using NetBeans for about 8 years with this project.  Never had this problem before.  Something changed in the last 6-12 months.

Saying "this is the way it is designed" is like trying to sell a car model without a starting motor.  You know, the model that doesn't run.
Comment 5 blake1024 2015-08-20 14:47:50 UTC
1.  Create a new project

    a.  File / New Project / Java Web / Web Application / Next
    b.  (name it) / Next
    c.  Server: tomcat / Java EE 7 Web / Next
    d.  Finish

2.  Create a Java class

    a.  Expand "Source Packages"
    b.  Right-click <default package> and select add Java Class
    c.  (name it) / Finish
    d.  add the following code to the new java class

	public static void main(String [] argv) {
		System.out.println("Hello");
	}

3.  Set ant verbosity level to see arguments

    a.  Tools / Options / Java / Ant / Verbosity Level:  Verbose

4.  Run new class

    a.  Right-click on new class and select Run File

You will notice in the Output window that, when running the class, it is including all of the tomcat JAR's.  This is wrong because I am not kicking off the server.  I am merely running a class locally as a command line utility.  Tomcat JAR's should not be included when running a class as a command line program.

In my real app, when I run a command line utility like this, in addition to the unwanted tomcat JAR's, I get the following unrequested JAR's:
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/asm-all-repackaged-2.2.0-b21.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/cglib-2.2.0-b21.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/guava-14.0.1.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/hk2-api-2.2.0-b21.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/hk2-locator-2.2.0-b21.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/hk2-utils-2.2.0-b21.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/javax.annotation-api-1.2.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/javax.inject-2.2.0-b21.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/javax.servlet-api-3.0.1.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/jaxb-api-2.2.7.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/jersey-entity-filtering-2.5.1.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/jersey-media-moxy-2.5.1.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/org.osgi.core-4.2.0.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/osgi-resource-locator-1.0.1.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/persistence-api-1.0.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/ext/validation-api-1.1.0.Final.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/jersey-client.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/jersey-common.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/jersey-container-servlet.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/jersey-container-servlet-core.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jersey2/jersey-server.jar
 
and:

    /opt/netbeans-8.0.2/java/modules/ext/eclipselink/eclipselink.jar
    /opt/netbeans-8.0.2/enterprise/modules/ext/jaxrs-2.0/javax.ws.rs-api-2.0.jar


The only libraries that should be included are those specified in my Libraries configuration.  How to I make it stop including tomcat, jersey2, and those other random JAR's?

Thanks!
Comment 6 Petr Hejl 2015-08-20 19:58:09 UTC
Not a P2.

The comment about "as designed" was about tomcat jars. I've just checked 7.4 and it works the same way. Tomcat jars are on the classpath when running sample described in comment #5.

I'm not sure about the Jersey part. The classpath is statically stored in the project not figured out before the run. Perhaps you used some IDE wizard which has added Jersey to CP (maybe wrongly)? We need some more details about it. Please also specify the exact versions of server and IDE.
Comment 7 blake1024 2015-08-20 20:51:53 UTC
Although I think including the tomcat JAR's is wrong, my problem is with the jersey2 JAR's.  Interestingly:

~/NetBeansProjects-8.0.2/MyProj/nbproject $ find . -type f -exec grep -iH jersey {} \;
~/NetBeansProjects-8.0.2/MyProj/nbproject $ cd ..
~/NetBeansProjects-8.0.2/MyProj $ find . -name '*.xml' -exec grep -iH jersey {} \;
~/NetBeansProjects-8.0.2/MyProj $ 


Where are the jersey2 JAR's being specified?

Thanks.

Blake
Comment 8 Petr Hejl 2015-08-20 21:13:01 UTC
I tried to create the simple JAX-RS web service through wizard and JAX-RS libraries appears on classpath. Those are referenced as IDE libraries through ${libs.restlib.classpath} and ${libs.restapi.classpath} I guess.

Check project properties -> Libraries. Haven't you used the wizard? In my usecase described above in this comment I would assume it is correct to add Jersey for plain old Tomcat.
Comment 9 blake1024 2015-08-21 21:52:36 UTC
Two problem with what you said.

I am right-clicking on a class to run it as a command line utility.  There is no tomcat, and there is no ant script.

So, I don't need jersey or tomcat jars, and I can't control how it is executed.

Unless, when I right-click a class and select run, does it use something in my build script?

Thanks.

Blake