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 56444 - Cannot exclude classes from final JAR file
Summary: Cannot exclude classes from final JAR file
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 8.1
Hardware: All All
: P2 blocker with 1 vote (vote)
Assignee: Tomas Zezula
URL:
Keywords:
: 65958 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-15 13:24 UTC by Milan Kubec
Modified: 2016-04-18 17:18 UTC (History)
3 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Milan Kubec 2005-03-15 13:24:58 UTC
[dev-200503141900, JDK 1.5.0_02]

There is no way how user could exclude classes from final jar built by building
the project. 'Exclude From JAR File' property in project properties doesn't
exclude classes only things that are copied from src/ to dist/ folders.
Comment 1 Tomas Zezula 2005-03-21 13:34:42 UTC
Is there an use case for it? In my opinion there is no relevant one.
If you need something so obscure you should rewrite the jar target in way you
like. Sorry, but until someone else will complain about it I am not going to
change it for the reasons David has described in the issue #51953.
I don't want to create new additional exlude for jar target. But the fix of
issue #49371 may help you in future.

Comment 2 Milan Kubec 2005-03-21 14:40:25 UTC
OK, but I don't think that jarring part of my source tree is obscure use case,
changing to ENHANCEMENT.
Comment 3 Tomas Zezula 2005-11-16 09:02:25 UTC
*** Issue 65958 has been marked as a duplicate of this issue. ***
Comment 4 Milan Kubec 2005-11-16 09:06:40 UTC
Increasing prio.
Comment 5 t_gergely 2014-04-11 14:42:50 UTC
(In reply to Tomas Zezula from comment #1)
> Is there an use case for it?

Here's mine. For Vaadin projects, it's normal to build your own widgetsets (js files generated from java files by GWT). When you have client classes, you don't need those packed into a WAR as class files, only as js.
Comment 6 Tomas Zezula 2014-04-11 14:52:32 UTC
Is it possible to attach such a sample project?
Does the Vadim project use gwt compiler instead of java compiler to generate both js and class files into build/classes?
Comment 7 t_gergely 2014-04-11 16:35:44 UTC
(In reply to Tomas Zezula from comment #6)
> Is it possible to attach such a sample project?

It's not that trivial, that needs a bunch of jars.

> Does the Vadim project use gwt compiler instead of java compiler to generate
> both js and class files into build/classes?

It's spelled VAADIN. They seem to be Eclipse guys, but NetBeans is partially supported, too. Here's the relevant doc: https://vaadin.com/directory/help/using-vaadin-add-ons/netbeans
The build file build-widgetset.xml (that works with vaadin version 6) is linked on that page.
All the classes in the project are compiled to build/WEB-INF/classes because of the "compile" dependency. But I don't think that dependency is strictly necessary. I guess it's just for validating the sources.
The js files are generated into web/VAADIN/widgetsets/*/.

Here's my workaround:
    <target name="-do-dist-without-manifest" depends="init,compile,compile-jsps,-pre-dist" if="do.war.package.without.custom.manifest">
      <dirname file="${dist.war}" property="dist.jar.dir"/>
      <mkdir dir="${dist.jar.dir}"/>
      <jar jarfile="${dist.war}" compress="${jar.compress}">
        <fileset dir="${build.web.dir}" excludes="WEB-INF/classes/com/vaadin/client/**,WEB-INF/classes/.netbeans_*,${dist.archive.excludes}"/>
      </jar>
    </target>

That leaves an empty com/vaadin directory in the WAR, so probably excluding from compilation would be better:

    <target depends="init, deps-jar, -pre-pre-compile, -pre-compile, -copy-manifest, -copy-persistence-xml, -copy-webdir, library-inclusion-in-archive,library-inclusion-in-manifest" if="have.sources" name="-do-compile">
        <webproject2:javac excludes="**/com/vaadin/client/**" destdir="${build.classes.dir}" gensrcdir="${build.generated.sources.dir}"/>
        <copy todir="${build.classes.dir}" includeEmptyDirs="false">
            <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
        </copy>
    </target>
Comment 8 jayxac 2016-04-18 17:18:31 UTC
Here is a use case that we have and would love to have a solution for.

we have certain classes - let's say Dev License Mock objects that are part of our project. In the development version we would like our factory to return this class and in production a real License Object. 
We also dont want to be shipping our Dev License file in the jar. This exposes a security loophole.